elasticsearch查询将所有时间都花在create_weight上

时间:2019-01-19 10:19:02

标签: elasticsearch

我有两个Elasticsearch集群,每个集群上的索引和数据都相同。 相同的简单查询在群集A上需要毫秒,但是在群集B上则需要10秒钟以上。

我使用了_profileAPI,在集群B上,我可以看到elasticsearch在create_weight操作上花费了大量时间。

  {
    "id" : "[dj3LJZL1RNuPEP7S0ZXFVQ][index_2018_12][3]",
    "searches" : [
      {
        "query" : [
          {
            "type" : "TermQuery",
            "description" : "n:8096344531",
            "time" : "441.2ms",
            "time_in_nanos" : 441271696,
            "breakdown" : {
              "score" : 0,
              "build_scorer_count" : 20,
              "match_count" : 0,
              "create_weight" : 441255457,
              "next_doc" : 0,
              "match" : 0,
              "create_weight_count" : 1,
              "next_doc_count" : 0,
              "score_count" : 0,
              "build_scorer" : 16218,
              "advance" : 0,
              "advance_count" : 0
            }
          }
        ],
        "rewrite_time" : 3967,
        "collector" : [
          {
            "name" : "CancellableCollector",
            "reason" : "search_cancelled",
            "time" : "79.4micros",
            "time_in_nanos" : 79420,
            "children" : [
              {
                "name" : "SimpleTopScoreDocCollector",
                "reason" : "search_top_hits",
                "time" : "42.1micros",
                "time_in_nanos" : 42166
              }
            ]
          }
        ]
      }
    ],
    "aggregations" : [ ]
  },
  {
    "id" : "[dj3LJZL1RNuPEP7S0ZXFVQ][index_2018_12][4]",
    "searches" : [
      {
        "query" : [
          {
            "type" : "TermQuery",
            "description" : "n:8096344531",
            "time" : "296.7ms",
            "time_in_nanos" : 296795143,
            "breakdown" : {
              "score" : 0,
              "build_scorer_count" : 15,
              "match_count" : 0,
              "create_weight" : 296779276,
              "next_doc" : 0,
              "match" : 0,
              "create_weight_count" : 1,
              "next_doc_count" : 0,
              "score_count" : 0,
              "build_scorer" : 15851,
              "advance" : 0,
              "advance_count" : 0
            }
          }
        ],
        "rewrite_time" : 2947,
        "collector" : [
          {
            "name" : "CancellableCollector",
            "reason" : "search_cancelled",
            "time" : "54.7micros",
            "time_in_nanos" : 54776,
            "children" : [
              {
                "name" : "SimpleTopScoreDocCollector",
                "reason" : "search_top_hits",
                "time" : "18.6micros",
                "time_in_nanos" : 18642
              }
            ]
          }
        ]
      }
    ],
    "aggregations" : [ ]
  },
  {
    "id" : "[dj3LJZL1RNuPEP7S0ZXFVQ][index_2019_01][3]",
    "searches" : [
      {
        "query" : [
          {
            "type" : "TermQuery",
            "description" : "n:8096344531",
            "time" : "173.2ms",
            "time_in_nanos" : 173260750,
            "breakdown" : {
              "score" : 0,
              "build_scorer_count" : 17,
              "match_count" : 0,
              "create_weight" : 173247380,
              "next_doc" : 0,
              "match" : 0,
              "create_weight_count" : 1,
              "next_doc_count" : 0,
              "score_count" : 0,
              "build_scorer" : 13352,
              "advance" : 0,
              "advance_count" : 0
            }
          }
        ],
        "rewrite_time" : 4606,
        "collector" : [
          {
            "name" : "CancellableCollector",
            "reason" : "search_cancelled",
            "time" : "47.5micros",
            "time_in_nanos" : 47584,
            "children" : [
              {
                "name" : "SimpleTopScoreDocCollector",
                "reason" : "search_top_hits",
                "time" : "15.8micros",
                "time_in_nanos" : 15809
              }
            ]
          }
        ]
      }
    ],
    "aggregations" : [ ]
  },
  ...

在集群B上,TermQuery在每个分片上花费100毫秒至500毫秒,而在集群A上仅花费几微秒。

该如何解决?

1 个答案:

答案 0 :(得分:0)

我解决了自己的问题,所以我将其发布在这里!

实际上,群集B索引是通过群集A索引的快照还原创建的(这就是为什么我在每个群集中添加完全相同的数据)。我认为这就是将索引分段的原因。

要解决速度慢的问题,我必须对每个索引进行强制合并:

POST /index_*/_forcemerge?max_num_segments=1