gpt4 book ai didi

elasticsearch - 如何增强ES中应子句的某些单词/短语?

转载 作者:行者123 更新时间:2023-12-03 01:17:07 24 4
gpt4 key购买 nike

我正在使用以下查询:

{
"_source": [
"title",
"bench",
"id_",
"court",
"date",
"content"
],
"size": 15,
"from": 0,
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "london",
"fields": [
"title",
"content"
]
}
}
],
"should": [
{
"multi_match": {
"query": "London is a beautiful city and has a lot of amazing landmarks. I love the Thames!",
"fields": [
"title",
"content^2"
],
"operator": "or"
}
}
]
}
},
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"content": {}
},
"number_of_fragments": 5,
"fragment_size": 300
}
}

该查询的合理性是,必须显示伦敦一词,而应查询中的那些词应仅提高得分。我想做的是,在“应该”查询中,我想增加短语“美丽的城市”和“泰晤士河”一词。我该怎么做?

PS:“内容”和“标题”是标准文本字段,没有在其上应用分析器。

问候

最佳答案

您可以在应查询中添加多个子句

{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "london",
"fields": [
"title",
"content"
]
}
}
],
"should": [
{
"multi_match": {
"query": "beautiful city",
"fields": [
"title",
"content^2"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "Thames",
"fields": [
"title",
"content^2"
]
}
}
]
}
}
}

关于elasticsearch - 如何增强ES中应子句的某些单词/短语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61982895/

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