How to add leading zeros to a numeric field using the ingest pipeline?

I have a field that needs to be a 3 digit field always. so if the field value is 1 it should be coming in as 001 and if its 11 then it should be coming in as 011. I am parsing this field from a different field using the grok processor and when I simulate the document its showing me 3 digit field but in discover its removing the leading zeros from the field.
I am also not seeing the mutate and replace processor in ingest pipeline using which I know can be useful to my case as shown in the below link:

Hey,

just to be sure. if your field should have leading zeros, it must be a string value and cannot be a number. Is this OK for you?

See this example

POST _ingest/pipeline/_simulate
{
  "docs": [
    {
      "_source": {
        "value": 1
      }
    },
    {
      "_source": {
        "value": 99
      }
    }
  ],
  "pipeline": {
    "processors": [
      {
        "script": {
          "source": """
          ctx.x = String.format("%03d", new def[] { ctx.value });
          """
        }
      }
    ]
  }
}

Hello Spinscale,

Yes, I changed the mapping from numbers to text and the values are coming in as needed.

Thank you.

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