elasticsearch term suggest不返回正确的结果

cyvaqqii  于 2023-11-17  发布在  ElasticSearch
关注(0)|答案(1)|浏览(172)

我正在学习elasticsearch term suggestion。以下是我的数据:

PUT test/_bulk?refresh
{"index": {"_id": "1"}}
{"text": ["elastic"]}
{"index": {"_id": "2"}}
{"text": ["elastic", "elastica"]}
{"index": {"_id": "3"}}
{"text": ["elastic", "elastica", "elasticb"]}
{"index": {"_id": "4"}}
{"text": ["elastic", "elastica", "elasticb", "elasticc"]}

字符串
以下是我的搜索:

GET /test/_search
{
  "suggest": {
    "my_suggestion": {
      "text": "elastic",
      "term": {
        "field": "text"
      }
    }
  }
}


结果是:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "my_suggestion": [
      {
        "text": "elastic",
        "offset": 0,
        "length": 7,
        "options": []
      }
    ]
  }
}


我知道默认的suggest_mode是missing,所以结果中不包含“elastic”。但是为什么“elastica”,“elasticb”和“elasticc”也不被建议呢?
Elasticsearch版本:8.10

3pmvbmvn

3pmvbmvn1#

当您搜索“elastic”时,不建议"elastica""elasticb""elasticc"的原因是编辑距离可能对于Elasticsearch的默认参数来说太大。默认情况下,术语搜索器使用的最大编辑距离为2。此外,Elasticsearch还使用索引中术语的频率来排名建议。如果术语"elastica""elasticb",和"elasticc"并不常见,它们可能不会被认为是“好”的建议。
您可以将suggest_mode设置为“always”,以始终获得建议,而不管原始文本如何。

GET /test/_search
{
  "suggest": {
    "my_suggestion": {
      "text": "elastic",
      "term": {
        "field": "text",
        "suggest_mode": "always",
        "max_edits": 2,
        "prefix_length": 6
      }
    }
  }
}

字符串

相关问题