Range value type int or float,result different

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
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


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

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?

i do not set mapping for “out_date” field, value is int(time stamp) or null

What is your mapping?

GET shops/_mapping

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…

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"
}

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

why when I set

{“range”:{“out_date”:{“gte”:1516291200,“lte”:151698239}}}

the result is right

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

Thank you very much.

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