私はelasticsearchで基本的なコマンドを試していますが、基本的な検索に固執しています。
私のスクリプト:
from elasticsearch import Elasticsearch
INDEX_NAME = 'person'
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
data = {
'name': 'John'
}
response = es.index(index=INDEX_NAME, body=data)
print(response['result']) #=> created
id = response['_id']
response = es.get(index=INDEX_NAME, id=id)
print(response['_source']) #=> {'name': 'John'}
query = {
'query': {
'match_all': {}
}
}
response = es.search(index=INDEX_NAME, body=query)
print(response) #=> {'took': 0, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}
print(response['hits']['hits']) #=> []
デバッグ ログによると、ドキュメントが作成さes.get
れ、インデックスでそれを見つけることができますが、es.search
できません。問題がどこにあるか誰か知っていますか?
私も試しupdate
てみましたがdelete
、両方ともうまくいきました。ドキュメントはあまり役に立ちませんでした。
編集:
検索は Kibana で機能します。
GET person/_search
{
"query": {
"match_all": {}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "person",
"_type" : "_doc",
"_id" : "3EZ1s3gBsIJkcgJzc150",
"_score" : 1.0,
"_source" : {
"name" : "John"
}
}
]
}
}
したがって、Python 固有のものでなければなりません。