Nested queries that refer to an expression on the parent

Hi All,

I wish to write a query on nested data where there are expressions on the parent data as wells as expressions on the nested data all mixed together.

For example, get me all the records that have id = 1 and exists lineId 11

GET myIndex/_search
{
  "query": {
    "nested": {
      "path": "lines",
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "lines.lineId": {
                  "gte": 11,
                  "lte": 11
                }
              }
            },
            {
              "range": {
                "id": {
                  "gte": 1,
                  "lte": 1
                }
              }
            }
          ]
        }
      }
    }
  }
}

This does not work as it does not recognize the root level id field in the nested query. I realize in this simple example I can re-write this as a bool query of the root id=1 and nested lineId=11, but how would I compose more complex cases:

example:
give me record where exists a line with id=1 and line.lineid = 11 or someOtherParentField = 'x' and line.someLineField = 'y' and ...

all thoughts appreciated.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.