如何显着减少使用脚本聚合的查询的elasticsearch查询执行时间

问题描述

我在弹性搜索索引中有大约 1700 万个文档(它逐渐增加), 用于聚合的属性标签之一的映射是

{
   "mappings":{
      "labels":{
         "properties":{
            "label":{
               "type":"text","fields":{
                  "raw":{
                     "type":"keyword"
                  }
               }
            },"count":{
               "type":"float"
            }
         }
      }
   }
}

每个文档在 labels 属性中都有超过 500 个项目

现在用查询聚合文档

{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "type": "XYZ"
          }
        }
      ]
    }
  },"aggs": {
    "date": {
      "range": {
        "field": "date","ranges": [
          {
            "from": 1577816100000,"to": 1609438500000
          },{
            "from": 1546280100000,"to": 1577816100000
          }
        ]
      },"aggs": {
        "field1": {
          "terms": {
            "field": "field1","size": 100
          },"aggs": {
            "agg_label": {
              "terms": {
                "field": "labels.label.raw","size": 250,"min_doc_count": 5
              },"aggs": {
                "sum1": {
                  "sum": {
                    "script": "_score"
                  }
                },"sum2": {
                  "sum": {
                    "field": "labels.count"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

大约需要 20 秒,该字段标签中的值越多,执行时间越长。

我知道脚本查询很昂贵,那么有什么方法可以显着缩短执行时间?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)