Cannot build valid 'nested' queries in filter context
See original GitHub issueFrom what I can tell, it’s not possible to perform a nested query inside of a filter context with BodyBuilder:
bodybuilder().orFilter('nested', 'path', 'my_path', b =>
b.query('term', 'my_path.my_field', 'my_value')
)
This doesn’t work because b.query
does not exist, and instead only various filter functions are available. I believe this has to do with being in the “filter context” because of the outer orFilter()
.
If I try to use filter
, however:
bodybuilder().orFilter('nested', 'path', 'my_path', b =>
b.filter('term', 'my_path.my_field', 'my_value')
)
This results in a 400 Bad Request
from Elasticsearch because filters inside of a nested field is not supported. I am running against Elasticsearch v6.2.
If I use an orQuery
at the top-level this works fine:
bodybuilder().orQuery('nested', 'path', 'my_path', b =>
b.query('term', 'my_path.my_field', 'my_value')
)
However this doesn’t work for me because I want my boolean condition to live in the filter context with my other conditions and it’s cheaper to perform.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Combine nested query with filter - elasticsearch - Stack Overflow
The following query should work. You cannot nest the range query inside the nested one, you need to keep it outside but at...
Read more >Invalid sub-query filter. Either data cannot be retrieved (null) or ...
Either data cannot be retrieved (null) or no result objects are defined. (IES 00023) The query contains an invalid sub-query.
Read more >Use Context Filters - Tableau Help
To create a context filter, select Add to Context from the context menu of an existing categorical filter. The context is computed once...
Read more >Perform simple and compound queries in Cloud Firestore
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group.
Read more >ElasticSearch Nested Queries: How to Search for Embedded ...
Doing nested queries with ElasticSearch can be complicated. Get all the answers on how to search for embedded documents here.
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
I solved the problem using:
@johannes-scharlach’s solve worked for me. If there’s no plans on adding nested filter functionality in the near future, this should probably be documented as a workaround :~)