gpt4 book ai didi

elasticsearch - Elasticsearch完全匹配某些字段,但不完全匹配

转载 作者:行者123 更新时间:2023-12-03 01:43:34 25 4
gpt4 key购买 nike

我需要ElasticSearch精确匹配某些字段,当前正在使用multi_match。

例如,用户键入long beach chiropractor

我希望long beach与城市字段完全匹配,而不返回seal beachglass beach的结果。

同时chiropractor也应该匹配chiropractic

这是我正在使用的当前查询:

"query": {
"bool": {
"should": [
{
"multi_match": {
"fields": [
"title",
"location_address_address_1.value",
"location_address_city.value^2",
"location_address_state.value",
"specialty" // e.g. chiropractor
],
"query": "chiropractor long beach",
"boost": 6,
"type": "cross_fields"
}
}
]
}
},

最佳答案

正确的方法是将搜索到的术语与位置分开,并将位置存储为关键字类型。如果无法做到这一点,则可以使用同义词标记生成器将位置存储为单个标记,但这需要具有所有可能位置的列表。例如

{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"long beach=>long-beach"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}

现在,如果你打电话
POST /my_index/_analyze?analyzer=my_synonyms    
{
"text": ["chiropractor long beach"]
}

响应是
{
"tokens": [
{
"token": "chiropractor",
"start_offset": 0,
"end_offset": 12,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "long-beach",
"start_offset": 13,
"end_offset": 23,
"type": "SYNONYM",
"position": 1
}
]
}

关于elasticsearch - Elasticsearch完全匹配某些字段,但不完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45741294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com