【问题标题】:Elastic search not get the all of documents in python code弹性搜索无法获取 python 代码中的所有文档
【发布时间】:2019-06-10 03:25:01
【问题描述】:

我有弹性搜索单节点集群,它有一些索引。索引包含 6000 个或更多文档。文档映射有很多字段,例如(30 个或更多)。我可以在(Kibana 开发工具)中查询所有重复记录但是我用 python 结果查询,比如 10 条记录或 20 条记录。这是什么原因?

我的索引和文档计数

yellow open   test_index kjioInpQRAqT3o1LZHI92g   1   2       7652         1267      20.7mb          20.7mb

我的地图

{
 "settings": {
  "number_of_shards": 1,
  "number_of_replicas": 2 
 },

 "mappings": {
  "test_index" : {
    "properties": {
        "name": {
            "type": "keyword"
        },
        "address": {
            "type": "keyword"
        },
        # MORE 35 FIELDS ....
        }
      }
   }
}

【问题讨论】:

    标签: python python-3.x python-2.7 elasticsearch


    【解决方案1】:

    我找到了原因。文档有很多字段。它有35个字段。我可以在(kibana dev)工具中查询。查询一次返回1000个文档。Python弹性搜索库无法获取此文档数原因是单个文档太大(文档有 35 个字段)。然后我更改查询并将有用的字段放入查询结果。现在它是工作文件。

    像这样更改您的查询(普通查询)

    `{
       "_source": ["_id","_index", "quote_date", "asset"],
       "query": {
           "match_all": {
           }
       }
    }`
    

    像这样更改您的查询(聚合查询)

    ` "aggs": {        
      "duplicateDocuments": {        
         "top_hits": {
            "_source": ["_id","_index", "name", "address"],
                        "sort": [{"create_at": { "order": "desc"} } ]                                                                                                                                
                    }
                }
       }`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      相关资源
      最近更新 更多