elasticsearch查詢時設置最大返回數 max_result_window | 限制字段總數超1000


es默認最大返回數是10000,支持的最大返回數是2^31-1,也就是2147483647,不建議設置太大,query數據時size不要太大,總得考慮內存消耗的,設置了返回max后可以用分頁獲取, from:num_a, size:num_b,獲取的就是num_a+1到num_a+num_b的數據。

1.kibana

下面是在kibana中設置最大返回數,需要針對具體某個index做設置,試過模糊設置,發現失敗,dsl如下:

PUT log-2021-04-13/_settings
{
  "index": {
    "max_result_window": 2000000000
  }
}

如果返回確認-true,說明設置成功,當然也可以通過get請求查看:

GET log-*/_settings

下面是返回結果:

# 設置最大返回數
{
  "acknowledged" : true
}

# 查詢index的設置
{
  "log-2021-04-12" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "provided_name" : "log-2021-04-12",
        "max_result_window" : "2000000000",
        "creation_date" : "1618219829836",
        "number_of_replicas" : "0",
        "uuid" : "jfHvq7vaTiqoUreOYGrSWA",
        "version" : {
          "created" : "6070299"
        }
      }
    }
  },
  "log-2021-04-13" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "provided_name" : "log-2021-04-13",
        "max_result_window" : "2000000000",
        "creation_date" : "1618282080819",
        "number_of_replicas" : "0",
        "uuid" : "zt-kx98HSRy3_ZU-0Ye0iQ",
        "version" : {
          "created" : "6070299"
        }
      }
    }
  }
}

設置字段數

PUT _all/_settings # 所有索引,也可以指定具體index
{
  "index.mapping.total_fields.limit": 2000
}

2.python

python代碼實現:

es = ElasticSearchClient.get_as_server() # 創建es連接
max_result_body = {'index':{
                      'max_result_window':500000}}
es.indices.put_settings(index='index_name', body=max_result_body)

設置索引字段數
類似返回最大一樣,body內:

{
  "index.mapping.total_fields.limit": 2000
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM