should nested within must
See original GitHub issueI am curious if it is possible with this module to set up a complex elastic query that has should queries nested within a must.
Simply, I am trying to recreate this SQL query:
SELECT * FROM test where status = 'active' and (city = 'New York' or city = 'Toronto')
I would like to get back something similar to the below, but I have only been able to have the MUST and the SHOULD on the same level. Is this functionality possible? It seems like a simple query case, but maybe I am wrong.
{
"query": {
"bool": {
"must": {
"bool": {
"must": [
{
"match": {
"status": {
"query": "active"
}
}
},
{
"bool": {
"should": [
{
"match": {
"city": {
"query": "New York"
}
}
},
{
"match": {
"city": {
"query": "Toronto"
}
}
}
]
}
}
]
}
}
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:24 (2 by maintainers)
Top Results From Across the Web
javascript - Nested Should query(OR) inside a Must ...
I need to query elastic search to get all the profiles with is_cricketer = 1 and an OR query over the field for...
Read more >Nested query with should clauses and filter - Elasticsearch
I am using nested query with should clauses in elasticsearch 2.3.2 GET shop/customer/_search { "from": 0, "size": 25, "query": { "bool": ...
Read more >The existing input element should be nested within a form ...
An element is nested within another element, if it is between the other element's opening and closing tags. i dont get how to...
Read more >what are the two tags that should always be nested within ...
The <body> element contains the entire content of a webpage. It must be the second element inside of the parent <html> element, following...
Read more >The Difference Between Crossed and Nested Factors
When there is only one factor in a design, you don't have to worry about crossing and nesting. But once you have at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gitemconte I made a approach similar to @diegoprd one, I needed something like this in my filters:
To get this result dinamically with bodybuilder I did:
Obviously this is not a good solution but it works, and I hope it helps someone, if you have any question just ask.
I started using bodybuilder and my project needs many nested queries, @danpaz we can create a PR for this? How can we help?
@KillerAyce no worries, well I overlooked too. Glad we figured out, all the best !