# Cant get the date range to work Elastic search 2.0

**URL:** <https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490>\
**Category:** Elasticsearch\
**Created:** [November 13, 2015, 6:41am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490 "2015-11-13T06:41:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janaka\_Bandara](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Janaka\_Bandara](https://discuss.elastic.co/u/Janaka_Bandara)\
**Post date:** [November 13, 2015, 6:41am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/1 "2015-11-13T06:41:04Z")

</div>

Hi, I have following mapping inserted,

```
'searchable_tags' => array(
    'type' => 'string',

),
    'listing_type' => array(
        'type' => 'string'
    ),
    'listing_id' => array(
        'type' => 'integer'
    ),
    'from_date' => array(
        'type' => 'date',
        'format' => 'yyyy-MM-dd HH:mm:ss'
    ),
    'to_date' => array(
        'type' => 'date',
        'format' => 'yyyy-MM-dd HH:mm:ss'
    ),

```

And I'm trying to filter the result by date by running following query

```
'query' => [
    'bool' => [
        'must' => [
            'common' => [
                "searchable_tags" => [
                    "query" => $searchString,
                    "cutoff_frequency" => 0.001
                ]
            ]
        ],
        'filter' => [
            'range' => [
                'from_date' => [
                    [
                        'lte' => '2015-01-01',
                        "format" => "yyyy-MM-dd"
                    ]
                ]
            ]
        ],
        'must' => [
            'term' => [
                'listing_type' => $listingType
            ]
        ]

    ],
],

```

But it returns all the result despite the date range filter. Date range filter was working fine with ES 1.7 but I cant get it to work with 2.0

Could someone help me with this? whats am I doing wrong here

thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 13, 2015, 7:09am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/2 "2015-11-13T07:09:23Z")

</div>

Pretty unsure but it sounds like you added two must parts instead of two must clauses in a must part.

Not sure if it's your issue but it looks incorrect to me.

---

<div class="post-metadata">

**Author:** ![Janaka\_Bandara](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Janaka\_Bandara](https://discuss.elastic.co/u/Janaka_Bandara)\
**Post date:** [November 13, 2015, 7:41am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/3 "2015-11-13T07:41:14Z")

</div>

Thanks for the reply, This may be a stupid question but I'm new to elastic search and 2.0 changes not helping me at all. So whats the difference between must parts and must clauses?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 13, 2015, 8:47am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/4 "2015-11-13T08:47:15Z")

</div>

I meant that all inner must clauses must be wrapped under a must array.  
Have a look at the should part in the doc example. This form applies to must as well: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html?q=Bool](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html?q=Bool)

---

<div class="post-metadata">

**Author:** ![Janaka\_Bandara](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Janaka\_Bandara](https://discuss.elastic.co/u/Janaka_Bandara)\
**Post date:** [November 13, 2015, 8:58am UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/5 "2015-11-13T08:58:12Z")

</div>

Ah got it. Anyway the problem was with mapping it seems. Had to delete the index and re map, to get it working. Odd issue. anyway thanks a lot for the help and for the tip about clauses.

---

<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:** [July 5, 2017, 11:38pm UTC](https://discuss.elastic.co/t/cant-get-the-date-range-to-work-elastic-search-2-0/34490/6 "2017-07-05T23:38:42Z")

</div>


