# Parsing date in a field query against a date field

**URL:** <https://discuss.elastic.co/t/parsing-date-in-a-field-query-against-a-date-field/8495>\
**Category:** Elasticsearch\
**Created:** [July 23, 2012, 8:58pm UTC](https://discuss.elastic.co/t/parsing-date-in-a-field-query-against-a-date-field/8495 "2012-07-23T20:58:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Smolyak](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Michael\_Smolyak](https://discuss.elastic.co/u/Michael_Smolyak)\
**Post date:** [July 23, 2012, 8:58pm UTC](https://discuss.elastic.co/t/parsing-date-in-a-field-query-against-a-date-field/8495/1 "2012-07-23T20:58:29Z")

</div>

Hello,

In my ES index I have a field defined as

releaseDate: {

- include\_in\_all: true
- format: dateOptionalTime
- type: date

}

The way I understand dateOptionalTime format is that I should be able to  
query the records using '2012' or '2012-02-16' or '2012-02-16T05:00:00.000Z'  
(the actual value).

When I am querying the index (I am using elasticsearch-head) I get correct  
results with the query

{

- query: {
  - bool: {
    - must: [
      - {
        - term: {
          - releaseDate: 2012-02-16T05:00:00.000Z  
}  
}  
]  
}  
}

}

If I use strings '2012' or '2012-02-16', I get no results. I would like to  
be able to search against this field without using the time component. The  
only way I found to do it is by using a range query:

{

- query: {
  - bool: {
    - must: [
      - {
        - range: {
          - releaseDate: {
            - from: 2012-02-16
            - to: 2012-02-16  
}  
}  
}  
]

    - 

}  
}

- 

}  
Is there a way to use a term query and not have to specify the time  
component?

Thank you,

Michael

---

<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 6, 2017, 3:19am UTC](https://discuss.elastic.co/t/parsing-date-in-a-field-query-against-a-date-field/8495/2 "2017-07-06T03:19:23Z")

</div>


