# Range value type int or float,result different

**URL:** <https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175>\
**Category:** Elasticsearch\
**Created:** [January 19, 2018, 6:41am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175 "2018-01-19T06:41:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 6:41am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/1 "2018-01-19T06:41:54Z")

</div>

1.range value type float  
code:  
GET /shops/baseShops/\_search?\_source=true&size=10  
{"query":{"match\_all":{}},"post\_filter":{"bool":{"must":[[{"term":{"company\_id":75}}],[{"term":{"manager\_id":"3685"}}],[{"range":{"out\_date":{"gte":1516291200.0,"lte":151698239.0}}}]]}},"sort":[{"created\_at":"desc"}]}

result:  
nothing  
 ![7715f710952a076d31a194a4fc11a398fbf068e5_1_690x185](https://us1.discourse-cdn.com/elastic/original/3X/a/9/a9cc074650efa15ac64cf37a3c2870c5aed71d2e.png)

2.range value type int  
code:  
GET /shops/baseShops/\_search?\_source=true&size=10  
{"query":{"match\_all":{}},"post\_filter":{"bool":{"must":[[{"term":{"company\_id":75}}],[{"term":{"manager\_id":"3685"}}],[{"range":{"out\_date":{"gte":1516291200,"lte":151698239}}}]]}},"sort":[{"created\_at":"desc"}]}  
result:  
three data

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c0efade24371124ca095ee462f781221532e71d.png)

why like this result different,they are all number???

---

<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:** [January 19, 2018, 6:49am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/2 "2018-01-19T06:49:33Z")

</div>

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with `</>` icon. Check the preview window.

What is your mapping?

---

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 6:57am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/3 "2018-01-19T06:57:12Z")

</div>

i do not set mapping for "out\_date" field, value is int(time stamp) or null

---

<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:** [January 19, 2018, 7:08am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/4 "2018-01-19T07:08:50Z")

</div>

What is your mapping?

```auto
GET shops/_mapping

```

---

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 7:32am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/5 "2018-01-19T07:32:21Z")

</div>

GET /shops/\_mapping

"out\_date": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
this type is wrong,I am not statement field type,this type is first time save value type........

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 19, 2018, 7:43am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/6 "2018-01-19T07:43:23Z")

</div>

Your `out_date` field is of type string, probably because when you send documents to ES your data is double quoted and hence ES detects it as a string.

If you want to do `range` queries properly, you'll need to change the type of that field to

```
"out_date": {
    "type": "date"
}

```

or at least

```
"out_date": {
    "type": "long"
}
```

---

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 7:57am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/7 "2018-01-19T07:57:21Z")

</div>

this field not statement field type,this type is first time save value type........

---

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 8:00am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/8 "2018-01-19T08:00:02Z")

</div>

why when I set  
{"range":{"out\_date":{"gte":1516291200,"lte":151698239}}}  
the result is right

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 19, 2018, 8:12am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/9 "2018-01-19T08:12:41Z")

</div>

That's a coincidence, try this query and you'll see what I'm talking about

{"range":{"out\_date":{"gte":1516291200,"lte":16}}}

`range` queries also work on string, however, the order is not numerical but lexicographical, i.e. 16 \> 1516291200

---

<div class="post-metadata">

**Author:** ![githubyyf](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@githubyyf](https://discuss.elastic.co/u/githubyyf)\
**Post date:** [January 19, 2018, 8:35am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/10 "2018-01-19T08:35:50Z")

</div>

Thank you very much.

---

<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:** [February 16, 2018, 8:35am UTC](https://discuss.elastic.co/t/range-value-type-int-or-float-result-different/116175/11 "2018-02-16T08:35:53Z")

</div>

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