我正在弹性搜索中尝试基本命令,但我坚持使用基本搜索。
我的脚本:
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
都有效。Docs 并不是很有帮助。
编辑:
在 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 的。