# How to make a full text-query on date attribute in Elastic Search

**URL:** https://discuss.elastic.co/t/how-to-make-a-full-text-query-on-date-attribute-in-elastic-search/133278
**Category:** Elasticsearch
**Created:** [May 25, 2018, 8:03am UTC](https://discuss.elastic.co/t/how-to-make-a-full-text-query-on-date-attribute-in-elastic-search/133278 "2018-05-25T08:03:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![simonepontz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonepontz/32/71670_2.png) [@simonepontz](https://discuss.elastic.co/u/simonepontz)
#### Post date: [May 25, 2018, 8:03am UTC](https://discuss.elastic.co/t/how-to-make-a-full-text-query-on-date-attribute-in-elastic-search/133278/1 "2018-05-25T08:03:38Z")

</div>

I have a document with a date type attribute (like the following)

```
{
  "releaseDate": {
   "time": "1990-02-01T00:00:00+0000",
  }
}

```

I'm confident in doing some range query (date-math etc) so that if I'm looking for all the event in 1990, I can do the following range query

```
{
  "query": {
    "range": {
      "releaseDate.time": {
        "gte": "1990",
        "lte": "1991"
      }
    }
  }
}

```

I've noticed that Elasticsearch allow making a full-text search (match) on dates

> match queries accept text/numerics/dates, analyzes them, and constructs a query. For example:  
> [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html](http://query-dsl-match-query)

But I've trouble understanding how to make the right query.

for example, if I search for the following match query

```
{
  "query": {
    "match": {
      "attribute.releaseDate.time": "1990"
    }
  }
}

```

Zero results are returned from ES even if the date 1990-02-01T00:00:00 exists

But if I make the following

```
{
  "query": {
    "match": {
      "attribute.releaseDate.time": "1990-02"
    }
  }
}

```

I've found my event.

My understanding is that with the search query, ES will expand my search as 1990-01-01T00:00:00+0000 that won't match the indexed value of 1990-02-01T00:00:00+0000 while in the second query the token is the same.

This will observation will lead to my questions:

There is any way to use the following query? - events occurred in 1990, dates that contain the year 1990 (without a range) - events occurred in February of any year - events occurred in February the 5th of any year

But I haven't found any working example (the only things I've seen is here [https://discuss.elastic.co/t/mapping-date-field-as-multifiled-to-provide-date-query-and-full-text-search/80691](http://mapping-date-field-as-multifiled-to-provide-date-query-and-full-text-search))

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [June 1, 2018, 9:29am UTC](https://discuss.elastic.co/t/how-to-make-a-full-text-query-on-date-attribute-in-elastic-search/133278/2 "2018-06-01T09:29:09Z")

</div>

Hi @simonepontz,

dates are stored as long values internally, so using full text queries with them is not the standard and most useful way of working with them. The Range-Query should be your first stop when working with dates. For queries like "all events in February of each year" it is best to also index e.g. the month-of-year into a separate field and then do the search on that. Hope this helps.

---

<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: [June 29, 2018, 9:29am UTC](https://discuss.elastic.co/t/how-to-make-a-full-text-query-on-date-attribute-in-elastic-search/133278/3 "2018-06-29T09:29:10Z")

</div>

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