gpt4 book ai didi

elasticsearch - ElasticSearch查询忽略其他搜索词

转载 作者:行者123 更新时间:2023-12-02 23:59:45 26 4
gpt4 key购买 nike

我正在使用ElasticSearch在多个结构化字段上构建自由形式的按需输入搜索功能。人们搜索的主要字段是first_namelast_namecity

问题:以下两个搜索David SalazarDavid Salazar Denver返回的结果相同,其中“Denver”似乎被忽略。

我假设这是我的查询的问题,但是我仍然坚持如何更改它以获取所需的内容。

这是查询:

GET index_name/_search
{
"query": {
"multi_match": {
"fields": [
"first_name","middle_name", "last_name", "city", "county", "street"],
"query": "David Salazar Denver",
"type": "cross_fields",
"use_dis_max": false
}
},
"size": 10
}

这是索引设置和字段映射的相关部分
{
"index": {
"aliases": {},
"mappings": {
"type": {
"properties": {
"city": {
"type": "keyword"
},
"county": {
"type": "keyword"
},
"first_name": {
"type": "text",
"analyzer": "synonym_autocomplete",
"search_analyzer": "standard"
},
"last_name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"middle_name": {
"type": "text",
"analyzer": "synonym_autocomplete",
"search_analyzer": "standard"
},
"street": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
}
}
},
"settings": {
"index": {
[...]
"analysis": {
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [Long list of nicknames]
},
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "2",
"max_gram": "15"
}
},
"analyzer": {
"synonym_autocomplete": {
"filter": [
"standard", "lowercase", "synonym", "autocomplete_filter"],
"type": "custom",
"tokenizer": "standard"
},
"autocomplete": {
"filter": ["standard","lowercase","autocomplete_filter"],
"type": "custom",
"tokenizer": "standard"
}
}
},
[...]
}
}
}
}
}

最佳答案

请查看 cross_fields 查询文档。那里有一个operator参数,如果不存在,则将其设置为OR。这意味着您当前的查询正在从字段列表"David Salazar Denver"中的["first_name","middle_name", "last_name", "city", "county", "street"]搜索任何术语。这基本上意味着,只要在您的任何字段中找到来自搜索查询的一个单词,就会从搜索中返回文档。

关于elasticsearch - ElasticSearch查询忽略其他搜索词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50113806/

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