- download latest Wikidata file in the data folder.
- download the elasticsearch software and install it.
- install the python package elasticsearch
(make sure the version is suitable for the elasticsearch software installed in step 2)
pip install elasticsearch
- run insert.py
python insert.py
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