Advanced scripts on nested entities

Hi,
Regarding some mapping like this one :

{"root_entity": {"properties": {
  "root_long": {"type": "long"},
  "root_int": {"type": "integer"},
 "nested_entity":    {
    "type": "nested",
    "properties":       {
      "nested_long": {"type": "long"},
      "nested_int": {"type": "integer"},
      "nested_date": {"type": "date"}
}}}

What we need is to do scripting on the nested entities.
The scripts need to select several entities and do cross-computation on this selection.
I managed to write search, fields and aggregation scripts, using the document source

For example, I need to select 2 nested_entities, based on some criterias, then compute the duration between the "nested_date", so I can write some script fields like this one :

"script_fields" : {
  "test" : {
     "script" : "
        long d1=0;
        long d2=0;
        for(e in params._source['nested_entity']) {
           if (e['nested_int'] == 1 } d1 = e['nested_date'];
           if (e['nested_int'] == 2 } d2 = e['nested_date'];
        }
        return d2-d1"
    }
 }

I can search and aggregate with the same method.
The problem with my approach is I use the document source, so the performance is poor.

I tried to write equivalent scripts using the doc values but I didn't succeed.
Are there any other, and better, ways to fit my need ?

Franck

Doc values are not exposed for the nested docs in the parent (the parent is a distinct doc, inside lucene, from the nested children). Source is the only way to access them.

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