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.

Nested Sub-query does not generate correct elastic search syntax.

See original GitHub issue
bodybuilder()
	.query('term', 'field', 'something')
       .andQuery('bool', (q) => {
     	return q.query('term', 'obj1.color', 'blue')
  	})
        .build()

generates bool.query which is not valid as per ES [bool] query does not support [query]

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "field": "something"
          }
        },
        {
          "bool": {
            "query": {
              "term": {
                "obj1.color": "blue"
              }
            }
          }
        }
      ]
    }
  }
}

This is just simplistic scneario, I genuinely have some subqueries wiith nested path’s as well which does not work. I can come up with better example if this does not make sense.

Please advise if there is a workaround I can apply ?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ferronrsmithcommented, May 3, 2020

That’s a known-issue. You can’t have a single level nesting. If you think about it, it’s redundant. It can be brought up a level.

0reactions
qdelettrecommented, Mar 4, 2021

@johannes-scharlach Using filter instead of query will work, but filter and query have a different behavior regarding scoring (https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-filter-context.html).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested query | Elasticsearch Guide [8.5] | Elastic
Wraps another query to search nested fields. The nested query searches nested field objects as if they were indexed as separate documents.
Read more >
What is the ElasticSearch equivalent for an SQL subquery?
Elasticsearch doesn't support subqueries; you would need to perform your first query, then construct a second query using the results of the first...
Read more >
ElasticSearch Nested Queries: How to Search for Embedded ...
This can happen when, for example, you have a nested JSON document, i.e., one JSON document inside another. This is because Lucene (i.e., ......
Read more >
KNQL Plugin - The Daily Grok
In general you will never notice that nested queries are being generated, as this is done for you in the query parser. There...
Read more >
Kibana Discover | KQL Nested Query | Examples - eduCBA
Kibana query helps us to explore our big data to convert useful information. The elastic search does an index of our data, but...
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