# How to merge Array while reindexing data?

**URL:** <https://discuss.elastic.co/t/how-to-merge-array-while-reindexing-data/244388>\
**Category:** Elasticsearch\
**Created:** [August 10, 2020, 11:10am UTC](https://discuss.elastic.co/t/how-to-merge-array-while-reindexing-data/244388 "2020-08-10T11:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darshan\_ambre](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@darshan\_ambre](https://discuss.elastic.co/u/darshan_ambre)\
**Post date:** [August 10, 2020, 11:10am UTC](https://discuss.elastic.co/t/how-to-merge-array-while-reindexing-data/244388/1 "2020-08-10T11:10:23Z")

</div>

I have an index in which i have duplication document information which i wish to transform and to create one document with array of information.

I've the following data in the index:

\</\>

```auto
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "reservation",
            "_type" : "_doc",
            "_id" : "26_87",
            "_score" : 1.0,
            "_source" : {
              "Reservations" : [
                {
                  "ItemStatus" : "In Progress",
                  "displayName" : null,
                  "DocumentId" : 87,
                  "ModifiedBy" : "479044",
                  "RequestedQty" : 925428.0,
                  "entityDescription" : null,              
                  "ReservationId" : 67,
                  "ItemName" : "TestName",
                  "DocumentStatusId" : 1,
                  "DocumentType" : null,
                  "OnHandQty" : 0.0,
                  "DocumentNumber" : null,
                  "DocTypeCode" : 26,
                  "DocumentStatus" : "In Progress",
                  "DocumentSeqNo" : "PL#0000059",
                  "ItemNo" : "1014060",
                  "StatusId" : 1,
                  "DocumentCode" : "87",
                  "ReservationNo" : "0055674568"
                }
              ],
              "DocumentNo" : "0000059",
              "IsDeleted" : false
            }
          },
          {
            "_index" : "reservation",
            "_type" : "_doc",
            "_id" : "26_86",
            "_score" : 1.0,
            "_source" : {
              "Reservations" : [
                {
                  "ItemStatus" : "In Progress",
                  "displayName" : null,
                  "DocumentId" : 86,
                  "ModifiedBy" : "479044",
                  "RequestedQty" : 925428.0,          
                  "ReservationId" : 67,
                  "ItemName" : "TestName1",
                  "DocumentStatusId" : 1,
                  "DocumentType" : null,
                  "OnHandQty" : 0.0,
                  "LastAccessedOn" : null,
                  "DocumentNumber" : null,
                  "DocTypeCode" : 26,
                  "DocumentStatus" : "In Progress",
                  "DocumentSeqNo" : "PL#0000059",
                  "ItemNo" : "1013960",
                  "StatusId" : 1,
                  "DocumentCode" : "86",
                  "ReservationNo" : "0055674568"
                }
              ],
              "DocumentNo" : "0000059",
              "IsDeleted" : false
            }
          }
        ]
      }
    }

```

\</\>

I want to reindex the data in the following format:

\</\>

```auto
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "reservation",
            "_type" : "_doc",
            "_id" : "0000059",
            "_score" : 1.0,
            "_source" : {
              "Reservations" : [
                {
                  "ItemStatus" : "In Progress",
                  "displayName" : null,
                  "DocumentId" : 87,
                  "ModifiedBy" : "479044",
                  "RequestedQty" : 925428.0,
                  "entityDescription" : null,              
                  "ReservationId" : 67,
                  "ItemName" : "TestName",
                  "DocumentStatusId" : 1,
                  "DocumentType" : null,
                  "OnHandQty" : 0.0,
                  "DocumentNumber" : null,
                  "DocTypeCode" : 26,
                  "DocumentStatus" : "In Progress",
                  "DocumentSeqNo" : "PL#0000059",
                  "ItemNo" : "1014060",
                  "StatusId" : 1,
                  "DocumentCode" : "87",
                  "ReservationNo" : "0055674568"
                },
    			{
                  "ItemStatus" : "In Progress",
                  "displayName" : null,
                  "DocumentId" : 86,
                  "ModifiedBy" : "479044",
                  "RequestedQty" : 925428.0,          
                  "ReservationId" : 67,
                  "ItemName" : "TestName1",
                  "DocumentStatusId" : 1,
                  "DocumentType" : null,
                  "OnHandQty" : 0.0,
                  "LastAccessedOn" : null,
                  "DocumentNumber" : null,
                  "DocTypeCode" : 26,
                  "DocumentStatus" : "In Progress",
                  "DocumentSeqNo" : "PL#0000059",
                  "ItemNo" : "1013960",
                  "StatusId" : 1,
                  "DocumentCode" : "86",
                  "ReservationNo" : "0055674568"
                }
              ],
              "DocumentNo" : "0000059",
              "IsDeleted" : false
            }
          }
        ]
      }
    }

```

\</\>

Please any suggestion on having a custom processor is possible in this scenario..

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 12, 2020, 9:47am UTC](https://discuss.elastic.co/t/how-to-merge-array-while-reindexing-data/244388/2 "2020-08-12T09:47:07Z")

</div>

One thing to try out would be [transforms](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-overview.html), allowing you to group several documents together to create a so called entity centric index.

If the above does not help you this is something that you have to implement on the client side likely. Even though Elasticsearch has the ability to reindex a whole index, everything happens on a per document base so there is no ability to merge documents.

---

<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:** [September 9, 2020, 9:47am UTC](https://discuss.elastic.co/t/how-to-merge-array-while-reindexing-data/244388/3 "2020-09-09T09:47:21Z")

</div>

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