How to mix nested object with script in aggregation?

I want to concatenate 2 document fields, one of which is a nested object. If it were not nested, it wouldn't be a problem, but with script you can't mix nested. A sample mapping is:

{
       "_doc": {
       "properties": {
       "upper_level": {
        "type":"nested",
        "properties": {
          "my_field": {"type": "keyword"},
          "new_one": {"type": "keyword"},
          "name": {"type": "keyword"}
        }
      },
      "single_level" : {"type": "keyword" }
    }
  }
}

If it was not nested, I could do the following;

{
  "aggregations": {
      "single_level.upper_level" : {
          "terms": {
             "script": {
                   "source": "doc['single_level'].value + ' ' + doc['upper_level.name'].value",
                   "lang": "painless"
             },
         "size": 10,
        "min_doc_count": 1
      }
  }
}

But with a nested object, I can't mix that with script. Is there another way to do this?

Thanks.

Les

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