# Renaming nested fields based on some condition

**URL:** <https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801>\
**Category:** Logstash\
**Created:** [October 30, 2019, 7:25am UTC](https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801 "2019-10-30T07:25:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thilak](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@Thilak](https://discuss.elastic.co/u/Thilak)\
**Post date:** [October 30, 2019, 7:25am UTC](https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801/1 "2019-10-30T07:25:12Z")

</div>

In the document, I want to change the fieldName based on conditions below

1.If the **value** field has JSON type. Change the **value** field to **value-keyword** and remove **"value-whitespace"** and \*\*"value-standard" \*\* if present

2.If the value field has a size of more than 15. Change the **value** field to **value-standard**

this is the original document

```auto
"_source": {
          "applicationid" : "appid",
          "interactionId": "716bf006-7280-44ea-a52f-c79da36af1c5",
          "interactionInfo": [
            {
              "value": """{"edited":false}""",
              "value-standard": """{"edited":false}""",
              "value-whitespace" : """{"edited":false}"""
              "title": "msgMeta"
            },
            {
              "title": "msg",
              "value": "hello testing",
            },
            {
              "title": "testing",
              "value": "I have a text that can be done and changed only the size exist more than 20 so we applied value-standard ",
            }
          ],
          "uniqueIdentifier": "a21ed89c-b634-4c7f-ca2c-8be6f31ae7b3",
        }
      }

```

the end result should be

```auto
"_source": {
          "applicationid" : "appid",
          "interactionId": "716bf006-7280-44ea-a52f-c79da36af1c5",
          "interactionInfo": [
            {
              "value-keyword": """{"edited":false}""",
              "title": "msgMeta"
            },
            {
              "title": "msg",
              "value": "hello testing",
            },
            {
              "title": "testing",
              "value-standard": "I have a text that can be done and changed only the size exist more than 20 and so we applied value-standard ",
            }
          ],
          "uniqueIdentifier": "a21ed89c-b634-4c7f-ca2c-8be6f31ae7b3",
        }
      }

```

Here we may have from 1 nested document to 10 nested document - is there a way to interate the nested document and rename the field name based on the condition i mention above

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 30, 2019, 2:24pm UTC](https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801/2 "2019-10-30T14:24:33Z")

</div>

You could write code to do that in a ruby filter.

---

<div class="post-metadata">

**Author:** ![Thilak](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@Thilak](https://discuss.elastic.co/u/Thilak)\
**Post date:** [October 31, 2019, 6:14am UTC](https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801/3 "2019-10-31T06:14:29Z")

</div>

Yeah i am also working on the ruby filter.It would be better if you give any suggestion on looping and check whether the value is JSON or not in ruby

---

<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:** [November 28, 2019, 6:14am UTC](https://discuss.elastic.co/t/renaming-nested-fields-based-on-some-condition/205801/4 "2019-11-28T06:14:30Z")

</div>

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