Hi all,
I am using the Java client. I am using QueryBuilders.boolQuery() to dynamically construct a DSL bool query for a nested object field. Example query looks this and it part of a query. This query could grow given the number of clauses. The idea is that the user can search for other standard fields AND the nested object fields. The standard fields are in a separate boolQuery and the nested object field in this one. What I want to do is to express the following example query using the boolQuery: cats AND (dog OR horse OR pig)
.
Question: how can I dynamically add new clauses if the QueryBuilder is already nested with multiple boolQueries in it?
{
"bool" : {
"must" : {
"bool" : {
"should" : [ {
"nested" : {
"query" : {
"bool" : {
"must" : {
"query_string" : {
"query" : "raw:(dog)",
"default_operator" : "and"
}
}
}
},
"path" : "path"
}
}, {
"nested" : {
"query" : {
"bool" : {
"must" : {
"query_string" : {
"query" : "raw:(horse)",
"default_operator" : "and"
}
}
}
},
"path" : "path"
}
}, {
"nested" : {
"query" : {
"bool" : {
"must" : {
"query_string" : {
"query" : "raw:(pig)",
"default_operator" : "and"
}
}
}
},
"path" : "path"
}
} ]
}
}
}
}