繁体   English   中英

从 Python 查询 Elasticsearch 索引从 Kibana 返回 0 次命中但数千次

[英]Querying Elasticsearch Index from Python returns 0 hits but thousands from Kibana

我正在尝试使用 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" : [
      { 
     ...

我错过了什么?

只需删除doc_type代码中的 doc_type ,因为这似乎是唯一的区别

res = es.search(index="myindex", doc_type="articles", body=query)
                                       ^
                                       |
                              remove this parameter

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM