我有以下查詢,它作業正常。但是我的要求表明我可以有多個短語,我需要在OR條件中匹配,有什么方法可以縮短查詢。
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"primaryTags": {
"query": "Audience1",
"boost": 2
}
}
},
{
"match_phrase": {
"secondaryTags": {
"query": "Audience1",
"boost": 3
}
}
},
{
"match_phrase": {
"primaryTags": {
"query": "Audience2",
"boost": 2
}
}
},
{
"match_phrase": {
"secondaryTags": {
"query": "Audience2",
"boost": 3
}
}
}
],
"minimum_should_match": "1",
"boost": 1
}
}
}
隨著每個新短語的出現,我將不得不不斷添加兩個匹配短語主要和次要。有沒有辦法讓主要和次要的所有短語分別在一個條件下?
uj5u.com熱心網友回復:
您可以使用型別為 phrase 的 multi_match 查詢。試試下面的搜索查詢:
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "Audience1",
"fields": [
"primaryTags^2",
"secondaryTags^3"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "Audience2",
"fields": [
"primaryTags^2",
"secondaryTags^3"
],
"type": "phrase"
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481760.html
標籤:弹性搜索 弹性堆栈 单机版 弹性搜索-5 弹性搜索-dsl
下一篇:更新多欄位完成建議權重
