# Problem while searching for date range or date

**URL:** <https://discuss.elastic.co/t/problem-while-searching-for-date-range-or-date/17317>\
**Category:** Elasticsearch\
**Created:** [May 2, 2014, 9:43am UTC](https://discuss.elastic.co/t/problem-while-searching-for-date-range-or-date/17317 "2014-05-02T09:43:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hemant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemant/32/1337_2.png) [@Hemant](https://discuss.elastic.co/u/Hemant)\
**Post date:** [May 2, 2014, 9:43am UTC](https://discuss.elastic.co/t/problem-while-searching-for-date-range-or-date/17317/1 "2014-05-02T09:43:30Z")

</div>

Hello,

I have indexed some data, with default mapping -

1. {
2. "inventory": {
3. "products": {
4. "properties": {
5. "exp\_date": {
6. "type": "date",
7. "format": "dateOptionalTime"
8. },
9. "man\_date": {
10. "type": "date",
11. "format": "dateOptionalTime"
12. },
13. "price": {
14. "type": "long"
15. },
16. "product\_description": {
17. "type": "string"
18. },
19. "product\_name": {
20. "type": "string"
21. },
22. "quan\_available": {
23. "type": "long"
24. }
25. }
26. }
27. }
28. }

Now when I perform a search to match some date, I am not getting the  
expected result.  
Consider query like this  
{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "exp\_date:[2013-03-1 TO 2013-03-5]"  
}  
}  
}  
},  
"fields": [  
"price",  
"quan\_available",  
"product\_name",  
"product\_description",  
"exp\_date",  
"man\_date"  
],  
"from": 0,  
"size": 50,  
"sort": {  
"\_score": {  
"order": "asc"  
}  
},  
"explain": true  
}

Gives me expected result, that is all the documents which matches this date  
range, but when I remove the field Name exp\_date from the query string, I  
am getting no result at all.  
The following query results zero result.  
{ "query": { "filtered": { "query": { "query\_string": { "query":  
"[2013-03-1 TO 2013-03-5]" } } } }, "fields": [ "price", "quan\_available",  
"product\_name", "product\_description", "exp\_date", "man\_date" ], "from": 0,  
"size": 50, "sort": { "\_score": { "order": "asc" } }, "explain": true }

Can anybody suggest solution to this problem? What am doing wrong?  
Thansk in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ef046043-c666-4d11-8bf9-b46d28b421eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ef046043-c666-4d11-8bf9-b46d28b421eb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hemant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemant/32/1337_2.png) [@Hemant](https://discuss.elastic.co/u/Hemant)\
**Post date:** [May 2, 2014, 10:34am UTC](https://discuss.elastic.co/t/problem-while-searching-for-date-range-or-date/17317/2 "2014-05-02T10:34:13Z")

</div>

Found the solution to same problem here -  
[https://groups.google.com/forum/#!searchin/elasticsearch/date/elasticsearch/eeTwWVf6Sfo/1jbHq0gca6QJ](https://groups.google.com/forum/#!searchin/elasticsearch/date/elasticsearch/eeTwWVf6Sfo/1jbHq0gca6QJ)

Thanks.

On Friday, May 2, 2014 3:13:30 PM UTC+5:30, Hemant wrote:

> Hello,
> 
> I have indexed some data, with default mapping -
> 
> 1. {
> 2. "inventory": {
> 3. "products": {
> 4. "properties": {
> 5. "exp\_date": {
> 6. "type": "date",
> 7. "format": "dateOptionalTime"
> 8. },
> 9. "man\_date": {
> 10. "type": "date",
> 11. "format": "dateOptionalTime"
> 12. },
> 13. "price": {
> 14. "type": "long"
> 15. },
> 16. "product\_description": {
> 17. "type": "string"
> 18. },
> 19. "product\_name": {
> 20. "type": "string"
> 21. },
> 22. "quan\_available": {
> 23. "type": "long"
> 24. }
> 25. }
> 26. }
> 27. }
> 28. }
> 
> Now when I perform a search to match some date, I am not getting the  
> expected result.  
> Consider query like this  
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "query": "exp\_date:[2013-03-1 TO 2013-03-5]"  
> }  
> }  
> }  
> },  
> "fields": [  
> "price",  
> "quan\_available",  
> "product\_name",  
> "product\_description",  
> "exp\_date",  
> "man\_date"  
> ],  
> "from": 0,  
> "size": 50,  
> "sort": {  
> "\_score": {  
> "order": "asc"  
> }  
> },  
> "explain": true  
> }
> 
> Gives me expected result, that is all the documents which matches this  
> date range, but when I remove the field Name exp\_date from the query  
> string, I am getting no result at all.  
> The following query results zero result.  
> { "query": { "filtered": { "query": { "query\_string": { "query":  
> "[2013-03-1 TO 2013-03-5]" } } } }, "fields": [ "price", "quan\_available",  
> "product\_name", "product\_description", "exp\_date", "man\_date" ], "from": 0,  
> "size": 50, "sort": { "\_score": { "order": "asc" } }, "explain": true }
> 
> Can anybody suggest solution to this problem? What am doing wrong?  
> Thansk in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5155a1ed-b2d2-4fa7-9f2e-c37dd3323d52%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5155a1ed-b2d2-4fa7-9f2e-c37dd3323d52%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:32am UTC](https://discuss.elastic.co/t/problem-while-searching-for-date-range-or-date/17317/3 "2017-07-06T01:32:09Z")

</div>


