# How to add new fields in ingest pipeline based on conditons?

**URL:** <https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640>\
**Category:** Beats\
**Tags:** filebeat, ingest-pipeline\
**Created:** [November 8, 2021, 2:34pm UTC](https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640 "2021-11-08T14:34:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sidharth\_vijayakumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sidharth_vijayakumar/32/97257_2.png) [@sidharth\_vijayakumar](https://discuss.elastic.co/u/sidharth_vijayakumar)\
**Post date:** [November 8, 2021, 2:34pm UTC](https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640/1 "2021-11-08T14:34:58Z")

</div>

Need to add a new field called app\_statuscode for in filebeat. The condition is that if message field contains 404 or 502 the value of app\_statuscode must be set to failed.  
If the Message field contains 200 OK then the value must be set to successful.  
Can someone help me out ?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 8, 2021, 3:21pm UTC](https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640/2 "2021-11-08T15:21:39Z")

</div>

Here is one way to do it.

If `status == 200` then create a new field called `app_status` with value of `successful`.

If `status == 404 or 502` then create a new field called `app_status` with value of `failed`.

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "set": {
          "if": "ctx.app_statuscode == '200'",
          "field": "app_status",
          "value": "successful"
        }
      },
      {
        "set": {
          "if": "ctx.app_statuscode == '404' || ctx.app_statuscode == '502'",
          "field": "app_status",
          "value": "failed"
        }
      }      
    ]
  },
  "docs": [
    {
      "_source": {
        "app_statuscode": "404"
      }
    },
    {
      "_source": {
        "app_statuscode": "502"
      }
    },
    {
      "_source": {
        "app_statuscode": "200"
      }
    }
  ]
}

```

**Output**

```auto
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "app_status" : "failed",
          "app_statuscode" : "404"
        },
        "_ingest" : {
          "timestamp" : "2021-11-08T15:20:13.04282Z"
        }
      }
    },
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "app_status" : "failed",
          "app_statuscode" : "502"
        },
        "_ingest" : {
          "timestamp" : "2021-11-08T15:20:13.042826Z"
        }
      }
    },
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "app_status" : "successful",
          "app_statuscode" : "200"
        },
        "_ingest" : {
          "timestamp" : "2021-11-08T15:20:13.042829Z"
        }
      }
    }
  ]

```

---

<div class="post-metadata">

**Author:** ![sidharth\_vijayakumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sidharth_vijayakumar/32/97257_2.png) [@sidharth\_vijayakumar](https://discuss.elastic.co/u/sidharth_vijayakumar)\
**Post date:** [November 10, 2021, 2:05pm UTC](https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640/5 "2021-11-10T14:05:45Z")

</div>

Hi,  
Actually, the scenario is a bit more complicated. there is a field called message and it has value called status. Need to check if there is a status inside message if it has any of these status codes then set the value or if it does not have status then nothing to be done. Should i use grok here ??

Sample value of message field :  
{action:show,count:208,duration:6.38ms,status:200}

---

<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:** [December 8, 2021, 4:06pm UTC](https://discuss.elastic.co/t/how-to-add-new-fields-in-ingest-pipeline-based-on-conditons/288640/6 "2021-12-08T16:06:32Z")

</div>

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