# Convert mongo "OR" query to equivalent ES DSL

**URL:** <https://discuss.elastic.co/t/convert-mongo-or-query-to-equivalent-es-dsl/120496>\
**Category:** Elasticsearch\
**Created:** [February 19, 2018, 4:59pm UTC](https://discuss.elastic.co/t/convert-mongo-or-query-to-equivalent-es-dsl/120496 "2018-02-19T16:59:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [February 19, 2018, 4:59pm UTC](https://discuss.elastic.co/t/convert-mongo-or-query-to-equivalent-es-dsl/120496/1 "2018-02-19T16:59:15Z")

</div>

This mongo OR statement is a bit confusing translating to an ES DSL. Below is my attempt. Appears to be working, but would like someone more seasoned to stamp it correct or provide insight into how to do it the ES DSL way.

Notice the mongo $ne =\> 0.00 only exists in the second mongo OR block. How do I apply this condition to only tags match block of my ES DSL?

```auto
$filter = [
    '$or' => [
        [
            'created_at' => ['$gt' => $startDate, '$lte' => $endDate],
            'transaction_data.transactions.gateway' => 'authorize_net'
        ],
        [
            'created_at' => ['$gt' => $startDate, '$lte' => $endDate],
            'tags' => ['$regex' => "Option A", '$options' => "i"],
            'total_price' => [
                '$ne' => '0.00'
            ]
        ]
    ]
];

```

**Mongo equivalent ES DSL?**

```auto
GET orders/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "total_price": {
              "value": "0.00"
            }
          }
        }
      ],
      "should": [
        {
          "term": {
            "transaction_data.transactions.gateway": {
              "value": "authorize_net"
            }
          }
        },
        {
          "match": {
            "tags": "Option A"
          }
        }
      ],
      "filter": [
        {
          "range": {
            "created_at": {
              "gt": "2018-02-16",
              "lte": "2018-02-28"
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

---

<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:** [March 19, 2018, 4:59pm UTC](https://discuss.elastic.co/t/convert-mongo-or-query-to-equivalent-es-dsl/120496/2 "2018-03-19T16:59:48Z")

</div>

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