# Adding new field based on AND Condition

**URL:** <https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010>\
**Category:** Logstash\
**Created:** [December 17, 2020, 3:57pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010 "2020-12-17T15:57:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![errupeshmca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/errupeshmca/32/78285_2.png) [@errupeshmca](https://discuss.elastic.co/u/errupeshmca)\
**Post date:** [December 17, 2020, 3:57pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010/1 "2020-12-17T15:57:56Z")

</div>

Hi have below coloumns

```auto
columns => ["Order Key","Cust #","Doc Type","Doc #","Order #","Order Type","Order Complete?","Order Date","Total Order Value","Total Dollar Value","TotalOrderReceivedToday","Inv #","Inv Date","Expected Ship Date","Shipment Date","TotalShipped","ThisWeekShipped","Salesperson","Salesperson name","Loc","ThisWeekOrders"]

```

I want to add new field based on below condition, but it's not adding a new field.

```auto
if [Order Complete?] == "False" and [Doc Type] == "O" {
    mutate { add_field => { "Order Complete?" => "Open Unfilled Orders" } }
} else if [Order Complete?] == "True" and [Doc Type] == "I" {
    mutate { add_field => { "Order Complete?" => "Filled Orders" } }
}

```

Please help !

---

<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:** [December 17, 2020, 4:54pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010/2 "2020-12-17T16:54:22Z")

</div>

Can you show an example event using

```
output { stdout { codec => rubydebug } }
```

---

<div class="post-metadata">

**Author:** ![errupeshmca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/errupeshmca/32/78285_2.png) [@errupeshmca](https://discuss.elastic.co/u/errupeshmca)\
**Post date:** [December 17, 2020, 6:04pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010/3 "2020-12-17T18:04:45Z")

</div>

Thanks Badger looking into this, Below is the output

```auto
{
            "ThisWeekShipped" => 0,
                        "Loc" => " GS",
                   "@version" => "1",
             "ThisWeekOrders" => 0,
                       "path" => "D:/ELK/logstash-7.9.3/config/TotatOrderOfDay.csv",
                "Salesperson" => " SPZ",
    "TotalOrderReceivedToday" => 0,
         "Expected Ship Date" => 2020-07-28T04:00:00.000Z,
                       "host" => "server",
                  "Order Key" => "I 462123",
                   "Doc Type" => "I",
               "TotalShipped" => 0,
                      "Doc #" => 462123,
                    "Order #" => 416622,
                     "Cust #" => 780,
            "Order Complete?" => true,
              "Shipment Date" => 2020-08-11T04:00:00.000Z,
                    "message" => "\"I 462123\",\" 780\",\"I\",\" 462123\",\" 416622\",\"O\",\"True\",28-Jul-20,420.2,474.83,0,\" 462123\",11-Aug-20,28-Jul-20,11-Aug-20,0,0,\" SPZ\",\"Sheri Peet\",\" GS\",0\r",
                 "@timestamp" => 2020-12-17T18:03:33.478Z,
               "Order Status" => "AlreadyInvoiced",
         "Total Dollar Value" => 474.83,
                      "Inv #" => " 462123",
                 "Order Type" => "O",
           "Salesperson name" => "Sheren",
          "Total Order Value" => 420.2,
                   "Inv Date" => 2020-08-11T04:00:00.000Z,
                 "Order Date" => 2020-07-28T04:00:00.000Z
}

```

---

<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:** [December 17, 2020, 6:19pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010/4 "2020-12-17T18:19:19Z")

</div>

> [@errupeshmca](#):
>
> ` "Order Complete?" => true,`

There are no quotes around the value true, so this is a boolean, not a string. Try

```
if ! [Order Complete?] and [Doc Type] == "O" {

```

---

<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:** [January 14, 2021, 6:19pm UTC](https://discuss.elastic.co/t/adding-new-field-based-on-and-condition/259010/5 "2021-01-14T18:19:27Z")

</div>

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