我正在嘗試使用 Python 從 Jupyter 查詢 Elasticsearch 索引。這是我的代碼:
from elasticsearch import Elasticsearch
esHost="http://myhost.com:9600"
esUser="myuser"
esPass="mypass"
es = Elasticsearch(hosts=esHost, http_auth=(esUser, esPass))
query = {
"query": {
"bool": {
"must": {
"exists": {
"field": "pkey"
}
}
}
}
}
res = es.search(index="myindex", doc_type="articles", body=query)
res
我得到的結果是:
{'took': 1,
'timed_out': False,
'_shards': {'total': 6, 'successful': 6, 'skipped': 0, 'failed': 0},
'hits': {'total': 0, 'max_score': None, 'hits': []}}
但是,當我在 Kibana 中運行相同的查詢時:
GET /myindex/_search?
{
"query": {
"bool": {
"must": {
"exists": {
"field": "pkey"
}
}
}
}
}
我得到了數千個結果:
{
"took" : 67,
"timed_out" : false,
"_shards" : {
"total" : 6,
"successful" : 6,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 12605121,
"max_score" : 1.0,
"hits" : [
{
...
我錯過了什么?
uj5u.com熱心網友回復:
只需在您的 python 代碼中洗掉doc_type,因為這似乎是唯一的區別
res = es.search(index="myindex", doc_type="articles", body=query)
^
|
remove this parameter
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/423050.html
標籤:
