[英]Filtering Elastic search result with must and match giving unexpected result
{
"body": {
"query": {
"bool": {
"must": {
"match": {
"_id": "24"
}
},
"should": [
{
"term": {
"draft_id": "draft_11"
}
},
{
"term": {
"draft_id": "non_draft"
}
}
]
}
}
}
}
結果包含以下信息
{
"_id": "24",
"name": "xyz",
"draft_id": "draft_312"
}
要求
我想根據以下條件過濾記錄:
non_draft
或draft_11
或者用簡單的話
id = 24 AND (draft_id = "non_draft" OR draft_id = "draft_11")
如果你看到結果,它只匹配 id,而不匹配 draft_id 字段。
您需要將您的 should 子句移到 must_clause 中。 只有子句在它們之間必須得到“AND”
{
"query": {
"bool": {
"must": [
{
"match": {
"_id": "24"
}
},
{
"bool": {
"should": [
{
"term": {
"draft_id": "draft_11"
}
},
{
"term": {
"draft_id": "draft_11"
}
}
]
}
},
{
"query_string": {
"default_field": "FIELD",
"query": "this AND that OR thus"
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.