# How do I conditionally reindex values (structured arrays) as nested types?

**URL:** <https://discuss.elastic.co/t/how-do-i-conditionally-reindex-values-structured-arrays-as-nested-types/135823>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 3:20am UTC](https://discuss.elastic.co/t/how-do-i-conditionally-reindex-values-structured-arrays-as-nested-types/135823 "2018-06-14T03:20:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanT](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@RyanT](https://discuss.elastic.co/u/RyanT)\
**Post date:** [June 14, 2018, 3:20am UTC](https://discuss.elastic.co/t/how-do-i-conditionally-reindex-values-structured-arrays-as-nested-types/135823/1 "2018-06-14T03:20:09Z")

</div>

Hello, I'm hoping to run Elasticsearch aggregation functions however my dataset no longer fits the index/mapping I originally implemented. I originally only had a single data dimension, however now need to handle 2D data points (Well, 3D if including time). Now I'm shoving an **array of data pairs(2 element array)** into a field that is of type **float** which is working, but I can't seem to run any Elasticsearch aggregation functions with the array data. I know I can achieve this with a structured, nested type and would like to reindex to this.

The current definition for the field (Called Value) is: "Value": { "type": "float" }

I have created a new index with the following mappings that I would like to re-index to. The Value field is defined as the following in the mappings:

> ```
> mapping_1d - "Value": { "type": "float" }
> 
> mapping_2d - "Value": {
> "type": "nested",
> "properties": {
> "A": {
> "type": "integer"
> },
> "B": {
> "type": "float"
> }
> }
> }
> 
> ```

What I'm struggling with is the inline script to map the data correctly in the \_reindex POST call. The pseudo code would be something along the lines of:

> ```
> IF (Name contains "2D Data") THEN
> FOR EACH element IN OldValue
> mapping_2d
> Value.A = element[0]
> Value.B = element[1]
> ELSE
> mapping_1d
> Value = OldValue
> 
> ```

Basically I want to map the old values based on whether they are an array or not. If it's an array, I want to put it in a mapping called "mapping\_2d" and store in the appropriate fields. If it is a single value I just want to simply pipe it to "mapping\_1d". Is this possible to achieve using 'painless'? How would I go about constructing the script?

---

<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:** [July 12, 2018, 3:20am UTC](https://discuss.elastic.co/t/how-do-i-conditionally-reindex-values-structured-arrays-as-nested-types/135823/2 "2018-07-12T03:20:17Z")

</div>

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