# ES 9.1 query with "range" facets over dates may produce invalid conversion from "to" to "to\_str"

**URL:** <https://discuss.elastic.co/t/es-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str/3207>\
**Category:** Elasticsearch\
**Created:** [August 11, 2010, 8:29pm UTC](https://discuss.elastic.co/t/es-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str/3207 "2010-08-11T20:29:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Key](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_key/32/3321_2.png) [@Jack\_Key](https://discuss.elastic.co/u/Jack_Key)\
**Post date:** [August 11, 2010, 8:29pm UTC](https://discuss.elastic.co/t/es-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str/3207/1 "2010-08-11T20:29:26Z")

</div>

Using ES 9.1 snapshot from 2010-08-02.

After running the following range facet query using dates, I found that the "to" provided in the query green did not match the "to\_str" listed in result red.  
It almost looks like the "to\_str" in the result is being derived from the "from" value instead.  
Has anyone else noticed this?

**\<query.sh\>**  
#!/bin/bash

curl -XPOST localhost:9200/biocompare/Antibodies/\_search -d '  
{  
"from" : 0,  
"size" : 0,  
"query" : {  
"match\_all" : { }  
},  
"facets" : {  
"range1" : {  
"range" : {  
"field" : "modified",  
"ranges" : [  
{  
"from" : "2000-01-01T00:00:00",  
"to" : "2010-01-01T00:00:00"  
},  
{  
"from" : "2010-01-01T00:00:00",  
"to" : "2010-02-01T00:00:00"  
}  
]  
}  
}  
}  
}  
' | python -mjson.tool  
**\</query.sh\>**

{  
"\_shards": {  
"failed": 0,  
"successful": 5,  
"total": 5  
},  
"facets": {  
"range1": {  
"\_key\_field": "modified",  
"\_type": "range",  
"\_value\_field": "modified",  
"ranges": [  
{  
"count": 99,  
"from": 946684800000.0,  
"from\_str": "2000-01-01T00:00:00",  
"mean": 1225301118181.8181,  
"to": 1262304000000.0,  
"to\_str": "2000-01-01T00:00:00",   
"total": 121304810700000.0  
},  
{  
"count": 0,  
"from": 1262304000000.0,  
"from\_str": "2010-01-01T00:00:00",  
"mean": "NaN",  
"to": 1264982400000.0,  
"to\_str": "2010-01-01T00:00:00",   
"total": 0.0  
}  
]  
}  
},  
"hits": {  
"hits": [],  
"max\_score": 1.0,  
"total": 884801  
}  
}

Regards, Jack

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 11, 2010, 8:46pm UTC](https://discuss.elastic.co/t/es-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str/3207/2 "2010-08-11T20:46:44Z")

</div>

Almost looks like? Exactly looks like ;). Pushed a fix to master. By the  
way, I am not too happy with the naming I gave it (to\_str and from\_str,  
pretty lacking on the imaginary side). I do want to return in the to / from  
the actual numeric values that were used for the range test (a date, at the  
end, is stored as a long).

-shay.banon

On Wed, Aug 11, 2010 at 11:29 PM, Jack Key [joeandrewkey@gmail.com](mailto:joeandrewkey@gmail.com) wrote:

> Using ES 9.1 snapshot from 2010-08-02.
> 
> After running the following range facet query using dates, I found that the  
> "to" provided in the query green did not match the "to\_str" listed in  
> result  
> red.  
> It almost looks like the "to\_str" in the result is being derived from the  
> "from" value instead.  
> Has anyone else noticed this?
> 
> \<query.sh\>  
> #!/bin/bash
> 
> curl -XPOST localhost:9200/biocompare/Antibodies/\_search -d '  
> {  
> "from" : 0,  
> "size" : 0,  
> "query" : {  
> "match\_all" : { }  
> },  
> "facets" : {  
> "range1" : {  
> "range" : {  
> "field" : "modified",  
> "ranges" : [  
> {  
> "from" : "2000-01-01T00:00:00",  
> "to" : "2010-01-01T00:00:00"  
> },  
> {  
> "from" : "2010-01-01T00:00:00",  
> "to" : "2010-02-01T00:00:00"  
> }  
> ]  
> }  
> }  
> }  
> }  
> ' | python -mjson.tool  
> \</query.sh\>
> 
> { "\_shards": { "failed": 0, "successful": 5, "total": 5 }, "facets": { "range1": { "\_key\_field": "modified", "\_type": "range", "\_value\_field": "modified", "ranges": [{ "count": 99, "from": 946684800000.0, "from\_str": "2000-01-01T00:00:00", "mean": 1225301118181.8181, "to": 1262304000000.0, "to\_str": "2000-01-01T00:00:00", "total": 121304810700000.0 }, { "count": 0, "from": 1262304000000.0, "from\_str": "2010-01-01T00:00:00", "mean": "NaN", "to": 1264982400000.0, "to\_str": "2010-01-01T00:00:00", "total": 0.0 }] } }, "hits": { "hits": [], "max\_score": 1.0, "total": 884801 } }
> 
> Regards, Jack
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/ES-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str-tp1093130p1093130.html](http://elasticsearch-users.115913.n3.nabble.com/ES-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str-tp1093130p1093130.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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, 4:20am UTC](https://discuss.elastic.co/t/es-9-1-query-with-range-facets-over-dates-may-produce-invalid-conversion-from-to-to-to-str/3207/3 "2017-07-06T04:20:55Z")

</div>

Closed on July 6, 2017, 4:20am UTC


