【问题标题】:elasticsearch query spend all time in create_weightelasticsearch 查询花费所有时间在 create_weight
【发布时间】:2019-01-19 10:19:01
【问题描述】:

我有两个弹性搜索集群,每个集群具有相同的索引和数据。 同样的简单查询在集群 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 上只需要几微秒

我能做些什么来解决这个问题?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

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

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

    为了解决缓慢的问题,我必须对每个索引进行强制合并:

    POST /index_*/_forcemerge?max_num_segments=1
    

    【讨论】:

    • 从远程集群重新索引后也发生在我身上。感谢您的解决方案。
    猜你喜欢
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 2019-11-14
    • 2012-09-03
    • 2013-07-11
    • 2017-09-24
    相关资源
    最近更新 更多