Querying a nested document value AND root document value


(Kehphin) #1

Suppose I have a simplified Organization document like so (ES 2.4):

{ 
  "organization" : { 
      "dateUpdated" : 1395211600000,

      "publications" : [ 
         { 
            "dateCreated" : 1393801200000
         },
         { 
           "dateCreated" : 1401055200000
         }
       ]
    }
}

I want to find all Organizations that have a publication dateCreated < the organization's dateUpdated:

{
  "query": {
    "nested": {
      "path": "publications",
      "query": {
        "bool": {
          "filter": [
            {
              "script": {
                "script": "doc['publications.dateCreated'].value < doc['dateUpdated'].value"
              }
            }
          ]
        }
      }
    }
  }
}

My problem is that when I perform a nested query, the nested query does not have access to the root document values, so doc['dateUpdated'].value is invalid and I get 0 hits.

Any help would be appreciated!


(system) #2