# Index Mappings over nested fields

**URL:** <https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326>\
**Category:** Elasticsearch\
**Created:** [May 2, 2019, 9:25am UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326 "2019-05-02T09:25:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [May 2, 2019, 9:25am UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/1 "2019-05-02T09:25:32Z")

</div>

Hi there!

I'd like to know whether it is possible to apply an index mapping so to manipulate some nested fields as soon as they arrive.

To make it more understandable, let's say I have some in-coming documents structured as follows:

```
field1: ...
field2: ...
field3: 
[
    {
        nestedfield1: ...
        nestedfield2: float
        nestedfield3: ...
    },
    {
        nestedfield1: ...
        nestedfield2: float
        nestedfield3: ...
    },
    .
    .
    .
    {
        nestedfield1: ...
        nestedfield2: float
        nestedfield3: ...
    }
]

```

I'd like to add to such documents a further NON nested field (i.e. sibling of field1, field2, field3) which is the sum of the nestedfield2s (e.g. total\_nestedfield2: float).

Docs are ingested from a third party platform so I cannot modify the way they are generated but only manipulate them at load time.

Ideas?  
Thank you!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 2, 2019, 9:28am UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/2 "2019-05-02T09:28:57Z")

</div>

Mappings do not alter the document in any way. If you want to change the structure you will need to use an ingest pipeline that you link to the index.

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [May 2, 2019, 9:41am UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/3 "2019-05-02T09:41:34Z")

</div>

First of all thank you for the fast reply.

Anyway, I've used ingest pipelines with \_update\_by\_query in the past to modify some historical data but as far as I know they cannot access nested fields (in fact I had to use Logstash with a ruby script to fulfill the task eventually).

Do you know any other way to achieve such a goal?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 2, 2019, 10:10am UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/4 "2019-05-02T10:10:36Z")

</div>

I suspect you would need to use a script process or with Painless in the pipeline. Otherwise you may need to find a way to get the data through Logstash, e.g. by using a http input and bulk codec.

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [May 2, 2019, 12:08pm UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/5 "2019-05-02T12:08:51Z")

</div>

Mhmh don't know if I can redirect the output of the third party app to logstash, I'll check that out.

As for now, I'll try with a painless script even though I'm not sure it'll let me access nested fields and make computation over them.

I'll let you know (and ask for help) asap!

Thank you for now

---

<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:** [May 30, 2019, 12:08pm UTC](https://discuss.elastic.co/t/index-mappings-over-nested-fields/179326/6 "2019-05-30T12:08:58Z")

</div>

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