# Is there a processor that can group my data correctly?

**URL:** <https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [March 26, 2024, 6:04pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200 "2024-03-26T18:04:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nama\_Chintamani\_Illo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nama_chintamani_illo/32/123100_2.png) [@Nama\_Chintamani\_Illo](https://discuss.elastic.co/u/Nama_Chintamani_Illo)\
**Post date:** [March 26, 2024, 6:04pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/1 "2024-03-26T18:04:20Z")

</div>

I have tried multiple methods and they all seem to keep the data in an array of the same field instead of the grouping to match.

I am attempting to turn this type of grouping:

```auto
"service": {
   "name": [
          "value1",
          "value2",
         ]

```

Into the following:

```auto
"service": [
  {
  "name": value1
  },
  {
  "name": value2
  }
]

```

A little more to the story:  
I am attempting to index these as nested field types. I have the mapping setup like the following:

```auto
        "service": {
          "type": "nested",
          "properties": {
            "name": {
              "type": "keyword"
            }
          }

```

---

<div class="post-metadata">

**Author:** ![Nama\_Chintamani\_Illo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nama_chintamani_illo/32/123100_2.png) [@Nama\_Chintamani\_Illo](https://discuss.elastic.co/u/Nama_Chintamani_Illo)\
**Post date:** [March 27, 2024, 8:15pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/2 "2024-03-27T20:15:35Z")

</div>

Found a painless script to help.

```auto
      {
        "script": {
          "source": """ArrayList input = new ArrayList(ctx['services']);
long c = 0;
String output = '';
for (item in input) {
  if (c == input.length - 1) {
    output += String.valueOf('{"name":"'+item+'"}');
  } else {
    output += String.valueOf('{"name":"'+item+'"},');
  }
  c++
}
ctx['services'] = String.valueOf([output])""",
          "if": "ctx?.services != null",
          "ignore_failure": true
        }
      },

```

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [April 1, 2024, 10:15pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/3 "2024-04-01T22:15:58Z")

</div>

Thanks for following up, @Nama_Chintamani_Illo. How did it work out with the painless script? Do you need any support here?

---

<div class="post-metadata">

**Author:** ![Nama\_Chintamani\_Illo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nama_chintamani_illo/32/123100_2.png) [@Nama\_Chintamani\_Illo](https://discuss.elastic.co/u/Nama_Chintamani_Illo)\
**Post date:** [April 2, 2024, 2:49pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/4 "2024-04-02T14:49:50Z")

</div>

Thanks for checking in, but I should be good.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [April 2, 2024, 2:53pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/5 "2024-04-02T14:53:31Z")

</div>

Thanks for following up @Nama_Chintamani_Illo. Glad you found a solution.

---

<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:** [April 30, 2024, 2:53pm UTC](https://discuss.elastic.co/t/is-there-a-processor-that-can-group-my-data-correctly/356200/6 "2024-04-30T14:53:39Z")

</div>

Closed on April 30, 2024, 2:53pm UTC

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