[英]match query on elastic search with multiple or conditions
我有三個字段status
, type
和search
。 我想要的是搜索包含status
等於NEW
或status
等於IN PROGRESS
且type
等於abc
或type
等於xyz
並search
contains(partial match)。
我的電話如下所示-
{
"query": {
"bool" : {
"must" : [{
"match": {
"status": {
"query": "abc",
}
}
}, {
"match": {
"type": {
"query": "NEW",
}
}
},{
"query_string": {
"query": "*abc*", /* for partial search */
"fields": ["title", "name"]
}
}]
}
}
}
嵌套您的boolqueries。 我認為您缺少的是:
"bool": { "should": [
{ "match": { "status": "abc" } },
{ "match": { "status": "xyz" } }
]}
這是一個查詢,該查詢必須與應子句之一匹配,因為僅應給出應子句。
編輯來解釋差異:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"status": "abc"
}
},
{
"match": {
"status": "xyz"
}
}
]
}
},
{
"terms": {
"type": [
"NEW",
"IN_PROGRESS"
]
}
},
{
"query_string": {
"query": "*abc*",
"fields": [
"title",
"name"
]
}
}
]
}
}
}
因此,您在頂部有一個boolquery。 3個內部查詢中的每個查詢都必須為真。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.