Querying a nested object
See original GitHub issueWhat is the proper way to query a nested object? Example:
s = Search(using=es).index("my_index").query("nested", path="features", query=Q("term", features__name="foo"))
The code expects keyword parameters, but specifying a nested field like ‘features.name’ as keyword parameter is not possible and ‘features__name’ is not converted into ‘features.name’.
If it’s not supported, I could add some code that will properly replace double underscores with periods.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:27 (12 by maintainers)
Top Results From Across the Web
Nested query | Elasticsearch Guide [8.5] | Elastic
The nested query searches nested field objects as if they were indexed as separate documents. If an object matches the search, the nested...
Read more >Query on Embedded/Nested Documents — MongoDB Manual
This page provides examples of query operations on embedded/nested documents using the db.collection.find() method in mongosh . The examples on this page ...
Read more >Nested object queries - AWS IoT Core
You can use nested SELECT clauses to query for attributes within arrays and inner JSON objects. Supported by SQL version 2016-03-23 and later....
Read more >Elasticsearch query nested object - Stack Overflow
The nested type is a specialized version of the object data type that allows arrays of objects to be indexed in a way...
Read more >How to Do Elasticsearch Nested Query - Linux Hint
You can perform a nested query in Elasticsearch by using the nested parameter. A nested query will search the nested field objects and...
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 Free
Top 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
Thanks for the feedback, in abd0075bba01f58dd3294528c264d0beee5e136d I added an option to override this behavior by sending
_expand__to_dot=False
:Q('match', field__with__underscores='value', _expand__to_dot=False)
Hope this helps
Hi Adriaan, converting
a__b
toa.b
is indeed not supported. Currently you can achieve the code you want by specifying:s = Search(using=es).index("my_index").query("nested", path="features", query=Q("term", **{'features.name': "foo"}))
…which is obviously far from ideal.Transforming
__
to the dots sounds definitely like a good idea - something theQ
andF
shortcuts could do. I will look into it.Thanks!