Is there a processor that can group my data correctly?

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:

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

Into the following:

"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:

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

Found a painless script to help.

      {
        "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
        }
      },

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

Thanks for checking in, but I should be good.

1 Like

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

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