gpt4 book ai didi

elasticsearch - 使用Elasticsearch进行 bool 查询

转载 作者:行者123 更新时间:2023-12-03 00:46:26 24 4
gpt4 key购买 nike

我目前正在使用以下查询-

{
"_source": [
"title",
"bench",
"id_",
"court",
"date",
"content"
],
"size": 15,
"from": 0,
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "the",
"fields": [

"content"
], "operator": "and"
}
},

],
"should": {
"multi_match": {
"query": "the",
"fields": [
"content.standard^2"
], "operator": "and"
}
}
}
}
,
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"content": {}
},
"fragment_size": 100
}
}

使用以下映射
{
"courts_2": {
"mappings": {
"properties": {
"author": {
"type": "text",
"analyzer": "my_analyzer"
},
"bench": {
"type": "text",
"analyzer": "my_analyzer"
},
"citation": {
"type": "text"
},
"content": {
"type": "text",
"fields": {
"standard": {
"type": "text"
}
},
"analyzer": "my_analyzer"
},
"court": {
"type": "text"
},
"date": {
"type": "text"
},
"id_": {
"type": "text"
},
"title": {
"type": "text",
"fields": {
"standard": {
"type": "text"
}
},
"analyzer": "my_analyzer"
},
"verdict": {
"type": "text"
}
}
}
}
}

我的分析器是 Metaphone分析器。
这是我的目标。我希望完全匹配(标准)首先出现,然后是语音匹配。我能够用代码实现。我很确定其中有一些不需要的逻辑,如果有人可以指出它,我将深表感谢。

另外,我想加入的是搜索逻辑,用户可以在其中输入搜索内容,例如

皇家马德里和巴塞罗那或曼联。
在这里,我想要所有包含皇家马德里和巴塞罗纳/曼联/的文档,如何使用已有的当前查询(进行修改)来实现?

最佳答案

我在您的查询中看不到任何副作用。关于您的搜索逻辑,最简单的方法可能是使用query string query代替。默认情况下,它支持 bool(boolean) 运算符,因此您的查询可能如下所示:

{
"_source": [
"title",
"bench",
"id_",
"court",
"date",
"content"
],
"size": 15,
"from": 0,
"query": {
"bool": {
"must": [
{
"query_string" : {
"query" : "Real Madrid AND Barcelona OR Manchester United",
"fields" : ["content", "title"],
"operator": "and"
}
}
],
"should": {
"query_string" : {
"query" : "Real Madrid AND Barcelona OR Manchester United",
"fields" : ["content.standard", "title.standard"],
"boost": 2,
"operator": "and"
}
}
}
},
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"content": {}
},
"fragment_size": 100
}
}

否则,您将不得不解析您的查询,并使用多个 bool(boolean) 查询对运算符建模。

关于elasticsearch - 使用Elasticsearch进行 bool 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60376466/

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