# How to mix nested object with script in aggregation?

**URL:** <https://discuss.elastic.co/t/how-to-mix-nested-object-with-script-in-aggregation/204741>\
**Category:** Elasticsearch\
**Created:** [October 22, 2019, 11:50pm UTC](https://discuss.elastic.co/t/how-to-mix-nested-object-with-script-in-aggregation/204741 "2019-10-22T23:50:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhartzman](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@lhartzman](https://discuss.elastic.co/u/lhartzman)\
**Post date:** [October 22, 2019, 11:50pm UTC](https://discuss.elastic.co/t/how-to-mix-nested-object-with-script-in-aggregation/204741/1 "2019-10-22T23:50:19Z")

</div>

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:

```javascript
{
       "_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;

```javascript
{
  "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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 19, 2019, 11:50pm UTC](https://discuss.elastic.co/t/how-to-mix-nested-object-with-script-in-aggregation/204741/2 "2019-11-19T23:50:25Z")

</div>

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