我有一個彈性查詢,它在函式內部有一個過濾器。我需要添加一個條件,例如它應該與部門過濾器匹配,或者它應該與任何 product_ids 匹配,以便召回必須包含傳遞的 product_ids。下面是我想在彈性召回中看到的 product_ids,它需要在 ES 查詢的函式中添加。
{
"terms": {
"product_ids": [
"166168",
"753547",
"156835",
"90112"
]
}
}
下面是實際的 ES 查詢
"track_total_hits": true,
"_source": {},
"query": {
"boosting": {
"positive": {
"function_score": {
"query": {},
"boost_mode": "avg",
"score_mode": "sum",
"functions": [
{
"filter": {
"match": {
"Departments": {
"query": "1/lipstick",
"operator": "OR",
"fuzzy_transpositions": true,
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
},
"weight": 99
}
//I need to add the product_ids terms here
]
}
},
"negative": {},
"negative_boost": "1.0E-4"
}
},
uj5u.com熱心網友回復:
您可以在子句內創建bool查詢。filter
{
"query": {
"boosting": {
"positive": {
"function_score": {
"query": {
"match_all": {}
},
"boost_mode": "avg",
"score_mode": "sum",
"functions": [
{
"filter": {
"bool": {
"should": [
{
"match": {
"Departments": {
"query": "1/lipstick",
"operator": "OR",
"fuzzy_transpositions": true,
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
},
{
"terms": {
"product_ids": [
"166168",
"753547",
"156835",
"90112"
]
}
}
]
}
},
"weight": 99
}
]
}
},
"negative": {},
"negative_boost": "1.0E-4"
}
}
}
您還可以添加 multipul 函式,只有當檔案與此處提到的給定過濾查詢匹配時,才可以選擇應用該函式。
GET /_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"filter": {
"match": {
"Departments": {
"query": "1/lipstick",
"operator": "OR",
"fuzzy_transpositions": true,
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
},
"weight": 99
},
{
"filter": {
"terms": {
"product_ids": [
"166168",
"753547",
"156835",
"90112"
]
}
},
"weight": 42
}
],
"boost_mode": "avg",
"score_mode": "sum"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/468541.html
