【问题标题】:elasticsearch ngram slow when large numbers of documents match当大量文档匹配时,elasticsearch ngram 很慢
【发布时间】:2017-11-22 03:31:29
【问题描述】:

我正在按照以下示例在您键入功能时执行搜索: Edge NGram with phrase matching.

我觉得查询时间与匹配文档的数量有关,即使我只请求前 5 个文档。

我的索引有 3.2 亿份文档。当我的查询是“l”时,600 万个文档与查询匹配,运行查询需要 22 毫秒。但是,当我的查询是“a”时,有 1.33 亿个文档与查询匹配,并且需要 400 毫秒。同样,我只要求前 5 个文件。

请参阅下面的索引定义和查询。

我试图让我的所有查询都少于 100 毫秒。我如何实现这一目标?我错过了什么?

这是我的索引定义:

`

PUT /ss
{
    "settings": {
        "analysis": {
            "filter": {
                "english_poss_stemmer": {
                    "type": "stemmer",
                    "name": "possessive_english"
                },
                "edge_ngram": {
                    "type": "edgeNGram",
                    "min_gram": "1",
                    "max_gram": "25",
                    "token_chars": [
                        "letter",
                        "digit"
                    ]
                }
            },
            "analyzer": {
                "edge_ngram_analyzer": {
                    "filter": [
                        "lowercase",
                        "english_poss_stemmer",
                        "edge_ngram"
                    ],
                    "tokenizer": "standard"
                },
                "my_standard": {
                    "filter": [
                        "lowercase",
                        "english_poss_stemmer"
                    ],
                    "tokenizer": "standard"
                }
            }
        }
    },
    "mappings": {
        "ss": {
            "_all": {
                "enabled": false
            },
            "properties": {
                "name": {
                    "search_analyzer": "my_standard",
                    "analyzer": "edge_ngram_analyzer",
                    "type": "text"
                },
                "type": {
                    "search_analyzer": "keyword",
                    "analyzer": "keyword",
                    "type": "text"
                },
                "tax_id": {
                    "search_analyzer": "keyword",
                    "analyzer": "keyword",
                    "type": "text"
                }
            }
        }
    }
}

`

这是我的查询:

GET /ss/_search
    {
            "from": 0,
            "size": 5,
            "query": {
                "bool": {
                    "must": {
                        "match_all": {}
                    },
                    "filter": {
                        "match_phrase": {
                            "name": "a"
                        }
                    }
                }
            }
        }

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    我在 1 克中看不到任何点,我认为将克数限制在 6 是有意义的。

    你有:

    "min_gram": "1"
    "max_gram": "25"
    

    最好有:

    "min_gram": "2"
    "max_gram": "6"
    

    【讨论】:

      猜你喜欢
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2017-12-21
      • 2014-07-04
      • 1970-01-01
      • 2021-08-24
      • 2013-07-22
      相关资源
      最近更新 更多