首页 > 解决方案 > 为什么elasticsearch中的TermQuery这么慢?

问题描述

我一直在使用 es 5.4.3 进行多索引搜索。我使用配置文件 API 跟踪搜索过程,发现其中一个“TermQuery”耗时超过 160 毫秒!我是 es 和 lucene 的新手,但我听说 lucene 中的 termquery 非常快。即使在我将'fielddata'放入内存之后也会发生这种情况(我将在下面展示我的索引是如何设置的),我对我的映射不太自信,我希望有高手能找出我的错误并解决问题。有什么指示让我找出问题所在吗?这个映射是从 es 2.x 派生的,但是官方文档说它会自动进行转换。

new_mappings = {
        "properties": {
            "did": {"type": "long", "index": "not_analyzed"},
            "title": {"type": "string", "index": "analyzed", "fielddata": {"loading": "eager"}},
            "title_embed": {"type": "double", "index": "no"},
            "entity": {"type": "string", "index": "not_analyzed", "fielddata": {"loading": "eager"}},
            "tag": {"type": "string", "index": "not_analyzed"},
            "aliases": {"type": "string", "index": "not_analyzed"},
            "entity_with_field": {"type": "string", "index": "not_analyzed", "fielddata": {"loading": "eager"}},
            "original_title": {"type": "string", "index": "analyzed", "analyzer": "standard", "fielddata": {"loading": "eager"}},
            "did3": {"type": "string", "index": "not_analyzed"},
            "title_entity": {"type": "string", "index": "not_analyzed", "fielddata": {"loading": "eager"}},
        }
    }
              {
                "type" : "TermQuery",
                "description" : "title:cure",
                "time" : "163.5755780ms",
                "time_in_nanos" : 163575578,
                "breakdown" : {
                  "score" : 72259602,
                  "build_scorer_count" : 19,
                  "match_count" : 0,
                  "create_weight" : 35370852,
                  "next_doc" : 55374841,
                  "match" : 0,
                  "create_weight_count" : 1,
                  "next_doc_count" : 71435,
                  "score_count" : 71416,
                  "build_scorer" : 427412,
                  "advance" : 0,
                  "advance_count" : 0
                }
              },
              {
                "type" : "TermQuery",
                "description" : "title:fever",
                "time" : "0.2344140000ms",
                "time_in_nanos" : 234414,
                "breakdown" : {
                  "score" : 0,
                  "build_scorer_count" : 19,
                  "match_count" : 0,
                  "create_weight" : 230746,
                  "next_doc" : 0,
                  "match" : 0,
                  "create_weight_count" : 1,
                  "next_doc_count" : 0,
                  "score_count" : 0,
                  "build_scorer" : 3648,
                  "advance" : 0,
                  "advance_count" : 0
                }

标签: elasticsearch

解决方案


推荐阅读