# Range search - adding month and day make query results wrong

**URL:** <https://discuss.elastic.co/t/range-search-adding-month-and-day-make-query-results-wrong/123354>\
**Category:** Elasticsearch\
**Created:** [March 9, 2018, 10:15pm UTC](https://discuss.elastic.co/t/range-search-adding-month-and-day-make-query-results-wrong/123354 "2018-03-09T22:15:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjo](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@bjo](https://discuss.elastic.co/u/bjo)\
**Post date:** [March 9, 2018, 10:15pm UTC](https://discuss.elastic.co/t/range-search-adding-month-and-day-make-query-results-wrong/123354/1 "2018-03-09T22:15:03Z")

</div>

this query works and shows results from 1771-01-07:

```auto
 curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' 
"query": {
        "range" : {
            "time_from" : {
                "gte" : "1771",
                "lt" : "1772",
                "format" : "yyyy"
            }
        }
    }'

```

but when I add MM-dd to the format, I get no results:

```auto
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' "query": {
        "range" : {
            "time_from" : {
                "gte" : "1771-01-01",
                "lt" : "1772-12-10",
                "format" : "yyyy-MM-dd"
            }
        }
   }'

```

same (no results) when I try this:

```auto
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
 "query": {
        "range" : {
            "time_from" : {
                "gte" : "1771-01",
                "lt" : "1772-12",
                "format" : "yyyy-MM"
            }
        }
    }'

```

This one however shows the 1771-01-07 result as expected (and it shows the date format seems to work but does not explain why searching from 1771-01-01 shows nothing):

```auto
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
 "query": {
        "range" : {
            "time_from" : {
                "gte" : "1770-01",
                "lt" : "1772-12",
                "format" : "yyyy-MM"
            }
        }
    }'

```

Edited question, added the following:

Model in Django:

```auto
class Text(models.Model):
    time_from = models.DateField(null=True, blank=True)

    def indexing(self):
        obj = TextIndexingNew(
            meta={'id': self.id},
            time_from=self.time_from,
        )
        obj.save(index='text-index')
        return obj.to_dict(include_meta=True)

```

DocType:

```auto
class TextIndexingNew(DocType):
    time_from = Text(fielddata=True)

```

Indexing method:

```auto
def bulk_indexing():
    TextIndexingNew.init(index='text-index')
        es = Elasticsearch()
        bulk(client=es, actions=(b.indexing()
        for b in models.Text.objects.all().iterator()))

```

Any idea what is going on?

---

<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:** [March 9, 2018, 10:30pm UTC](https://discuss.elastic.co/t/range-search-adding-month-and-day-make-query-results-wrong/123354/2 "2018-03-09T22:30:56Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). Specifically index creation, mapping and data indexed.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [April 6, 2018, 10:30pm UTC](https://discuss.elastic.co/t/range-search-adding-month-and-day-make-query-results-wrong/123354/3 "2018-04-06T22:30:59Z")

</div>

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