Skip to content

Zinc-30/wikidata_es_index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wikidata_es_index

Insert the wikidata KB into elasticsearch

  1. download latest Wikidata file in the data folder.
  2. download the elasticsearch software and install it.
  3. install the python package elasticsearch (make sure the version is suitable for the elasticsearch software installed in step 2)
    pip install elasticsearch
    
  4. run insert.py
    python insert.py
    

Search in the wikidata

you can direct search with search.py

    from search import *
    ws = wikidataSearch(100)
    for x in ws.get_entity_by_id('P31'):
        print(x)

or

write your own query

from elasticsearch import Elasticsearch
es = Elasticsearch(['localhost'], port=9201)
query = {"match": {"label": {"query": name}}}
response = es.search(index='wikidata_entity_linking', query=query)
try:
    entities = [x['_source'] for x in response['hits']['hits']]
    return entities
except:
    return []

please check the API doc and query doc for how to write the query

About

build a elasticsearch index for wikidata

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages