Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

elasticsearch - Fast return when search common prefix keyword

There is a company index

health status index               uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   company             KTngnM6ASD-_KdU0FFAWRA   1   0   88243299     29462913     24.7gb         24.7gb

because many company name has same prefix, e.g. Shanghai. So if you only search Shanghai it is very slow

Query from slowlog:

{
  "size": 1,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "name": {
                  "query": "Shanghai",
                  "operator": "AND",
                  "prefix_length": 0,
                  "max_expansions": 50,
                  "fuzzy_transpositions": true,
                  "lenient": false,
                  "zero_terms_query": "NONE",
                  "auto_generate_synonyms_phrase_query": true,
                  "boost": 1.0
                }
              }
            },
            {
              "match": {
                "shortName": {
                  "query": "Shanghai",
                  "operator": "OR",
                  "prefix_length": 0,
                  "max_expansions": 50,
                  "fuzzy_transpositions": true,
                  "lenient": false,
                  "zero_terms_query": "NONE",
                  "auto_generate_synonyms_phrase_query": true,
                  "boost": 2.9
                }
              }
            },
            { "term": { "name.keyword": { "value": "Shanghai", "boost": 2.0 } } },
            { "match_phrase": { "name": { "query": "Shanghai", "slop": 0, "zero_terms_query": "NONE", "boost": 1.0 } } }
          ],
          "adjust_pure_negative": true,
          "minimum_should_match": "1",
          "boost": 1.0
        }
      },
      "functions": [
        {
          "filter": { "match_all": { "boost": 1.0 } },
          "field_value_factor": { "field": "weight", "factor": 1.0, "missing": 0.0, "modifier": "none" }
        },
        {
          "filter": { "match_all": { "boost": 1.0 } },
          "field_value_factor": { "field": "viewCount", "factor": 1.0, "missing": 0.0, "modifier": "log1p" }
        }
      ],
      "score_mode": "sum",
      "boost_mode": "sum",
      "max_boost": 3.4028235e38,
      "boost": 1.0
    }
  },
  "profile": true
}

In normal situation user will search specific name, e.g. Alibaba , in this case the response time is not slow, but if user search common prefix e.g. Beijing Shanghai it will be slow.

Does exist some manner could implement this purpose that is if user search some common prefix, just return the requested size docs which just contains the common prefix do not need score or something else work

question from:https://stackoverflow.com/questions/65561013/fast-return-when-search-common-prefix-keyword

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...