[英]How to filter with multiple fields and values in elasticsearch?
我一直在閱讀文檔並試圖實現通過多個字段和列過濾結果的解決方案,但是我不斷收到錯誤; 格式錯誤的查詢。
我想用完全相等的值過濾結果,例如:
is_active: true
category_id: [1,2,3,4]
brand: "addidas"
gender: "male"
為了更清楚地說明我打算做什么,如果它用 SQL 編寫,這就是我希望它運行的方式:
SELECT .... WHERE
is_active= 1 AND category_id IN(1,2,3,4)
AND brand='addidas' AND gender='male'
我在 DSL 中的查詢如下:
{
"body": {
"query": {
"nested": {
"query": {
"bool": {
"must": {
"terms": {
"category_id": [
1,
2,
3
]
},
"term": {
"is_active": true
},
"term": {
"brand": "addidas"
}
}
}
}
}
}
}
}
如何在 elasticsearch 中按照所述過濾多個字段和值?
如果您需要我提供回答問題所需的額外信息,請發表評論。 如果您添加指向文檔的鏈接,還請提供一個示例(帶有查詢 dsl),說明應如何解決我的當前或類似情況。
使用以下代碼:
子句(查詢)必須出現在匹配的文檔中,並將有助於得分。
"query": {
"bool": {
"must" : [
{"term" : { "is_active" : true}},
{"term" : { "gender" : "female"}},
{"term" : { "brand" : "addidas"}},
{"terms": { "categoryId": [1,2,3,4]}}
]
}
}
在過濾器元素下指定的查詢對評分沒有影響
"query": {
"bool": {
"filter" : [
{"term" : { "is_active" : true}},
{"term" : { "gender" : "female"}},
{"term" : { "brand" : "addidas"}},
{"terms": { "categoryId": [1,2,3,4]}}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.