# How to logstash if field equals value assign other field value?

**URL:** <https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857>\
**Category:** Logstash\
**Created:** [September 22, 2021, 11:28am UTC](https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857 "2021-09-22T11:28:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/max_wang/32/79213_2.png) [@Max\_Wang](https://discuss.elastic.co/u/Max_Wang)\
**Post date:** [September 22, 2021, 11:28am UTC](https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857/1 "2021-09-22T11:28:35Z")

</div>

I have a logstash conf  
field A : Value A  
field B : Value B

———————————————————————————

I would like to become

The value of field A is equal to N/A, i will use the value of field B, as follows:  
field A : N/A -\> field A : Value B

Can someone provide an approach?

---

<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:** [September 22, 2021, 11:42am UTC](https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857/2 "2021-09-22T11:42:56Z")

</div>

Does this look like what you need?

**Test Conf**

```auto
input { generator { lines => ['[{"fielda": "N/A", "fieldb": "valueb"},{"fielda": "valuea", "fieldb": "valueb"}]'] count => 1 codec => "json" } }
filter {
  if [fielda] == "N/A" {
    mutate {
      update => { "fielda" => "%{fieldb}" }
    }
  }
}
output { stdout { codec => json } }

```

---

<div class="post-metadata">

**Author:** ![Max\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/max_wang/32/79213_2.png) [@Max\_Wang](https://discuss.elastic.co/u/Max_Wang)\
**Post date:** [September 22, 2021, 12:05pm UTC](https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857/3 "2021-09-22T12:05:07Z")

</div>

Thanks a lot! it work

---

<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:** [October 20, 2021, 12:06pm UTC](https://discuss.elastic.co/t/how-to-logstash-if-field-equals-value-assign-other-field-value/284857/4 "2021-10-20T12:06:06Z")

</div>

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