# How to set a condition in set processor (ingest node pipeline) to check if log.level= error

**URL:** <https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [November 16, 2021, 4:20pm UTC](https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347 "2021-11-16T16:20:37Z")\
**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 16, 2021, 4:20pm UTC](https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347/1 "2021-11-16T16:20:37Z")

</div>

Hi, my doc looks like this and I need to access log.level which is a nested field. can someone help me as I need a condition to set a new field called statuscode if log.level=error.

![image](https://us1.discourse-cdn.com/elastic/original/3X/9/b/9bcb3aa7d6c2903faaeb2cb574f1b7468c6f7166.png)

tried ctx.messageinfo.log.level=="error" and ctx?.messageinfo?.log.level=="error"  
both did not work

---

<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 16, 2021, 5:55pm UTC](https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347/2 "2021-11-16T17:55:21Z")

</div>

Think you are looking for this.

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "set": {
          "field": "field-name",
          "value": "value",
          "if": "ctx.messageinfo['log.level'] == 'error'"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "messageinfo": {
          "log.level": "error"
        }
      }
    }
  ]
}

```

---

<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 17, 2021, 4:28am UTC](https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347/4 "2021-11-17T04:28:20Z")

</div>

Thanks a ton Aaron . This works as expected. Much appreciated!

---

<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 15, 2021, 4:28am UTC](https://discuss.elastic.co/t/how-to-set-a-condition-in-set-processor-ingest-node-pipeline-to-check-if-log-level-error/289347/5 "2021-12-15T04:28:27Z")

</div>

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