我有一个索引,是2-4个字符,没有空格,但用户经常搜索“完整的术语”,我没有索引,但有3个额外的字符后,空白。我索引"A1“或"A1B”或"A1B2“,而”完整术语“类似于"A1 11A”或"A1B ABA“或"A1B2 2C8”。
这是当前的映射:
"code": {
"type": "text"
},如果他搜索"A1“,它会带来所有这些内容--这也是正确的,如果他键入"A1B”,我只想带最后两个,如果他搜索"A1B2 2C8“,我只想带最后一个。
这有可能吗?如果是的话,最好的搜索/索引策略是什么?
发布于 2020-11-30 02:12:50
索引映射:
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 10
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"code": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}索引数据:
{
"code": "A1"
}
{
"code": "A1B"
}
{
"code": "A1B2"
}搜索查询:
{
"query": {
"match": {
"code": {
"query": "A1B2 2C8"
}
}
}
}搜索结果:
"hits": [
{
"_index": "65067196",
"_type": "_doc",
"_id": "3",
"_score": 1.3486402,
"_source": {
"code": "A1B2"
}
}
]https://stackoverflow.com/questions/65067196
复制相似问题