这个问题可能是由于输入的数据集非常小而引起的,因此Elasticsearch会自动禁用autosuggest功能。要解决这个问题,可以通过在索引的映射中设置“min_gram”和“max_gram”参数来调整Elasticsearch的一些配置,或者在查询中添加“_ignore_unmapped”选项。下面是一个示例代码:
PUT my_index { "mappings": { "properties": { "title": { "type": "text", "analyzer": "standard", "fields": { "autocomplete": { "type": "text", "analyzer": "autocomplete", "search_analyzer": "standard" } } } } }, "settings": { "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": 2, "max_gram": 10 } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "autocomplete_filter" ] } } } } }
GET my_index/_search { "query": { "multi_match": { "query": "Teas", "fields": [ "title", "title.autocomplete" ], "_ignore_unmapped": true } } }