question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Querying a nested object

See original GitHub issue

What 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:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

11reactions
honzakralcommented, Jun 10, 2016

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

8reactions
honzakralcommented, Oct 10, 2014

Hi Adriaan, converting a__b to a.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 the Q and F shortcuts could do. I will look into it.

Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found