Elasticsearch和Python:GetTotal变量
我使用ES的PythonAPI来发送请求,我试图得到我的答案,但这是错误的。 我使用以下代码:Elasticsearch和Python:GetTotal变量,python,
elasticsearch,Python,
elasticsearch,我使用ES的PythonAPI来发送请求,我试图得到我的答案,但这是错误的。 我使用以下代码: import elasticsearch es = elasticsearch.Elasticsearch(["127.0.0.1:9200"]) results = es.search(index="bhinneka", body={"query": {"match": {"name": '"'+reference+'"'}}}) if results['hits']:
import elasticsearch
es = elasticsearch.Elasticsearch(["127.0.0.1:9200"])
results = es.search(index="bhinneka", body={"query": {"match": {"name": '"'+reference+'"'}}})
if results['hits']:
print('-' * 80)
print results['hits']['total']
for hit in results['hits']['hits']:
print hit['_source']['name']
事实上,当我从我的web浏览器验证结果时,我得到了-例如-总变量为5,而我的代码得到了总变量为42-例如-
如果有人能解答这个谜,我很感兴趣:)
提前感谢我使用此查询:
127.0.0.1:9200/bhinneka/bhinneka/_search?q=name:%22reference%22&pretty=true
我得到了这个结果:
{
...
"hits": {
"total": 5,
"max_score": 9.990799,
"hits": [
{
"_index": "bhinneka",
"_type": "bhinneka",
"_id": "ySosUTHKSESxo7ScOOhUZw",
"_score": 9.990799,
"_source": {
...
}
}
]
}
}
在web查询中,您可以指定类型和索引
bhinneka
,而在Python中,您只能设置索引。这可能是个问题吗?尝试在不指定类型的情况下执行web查询。如何从web浏览器验证结果?也许你使用的插件一次可以返回5个结果?