Hi Igor, agreed, sorry.
Create mapping:
curl -H 'Content-Type: application/json' -XPUT 'localhost:9200/_template/test-stats?pretty' -d'
{
"order" : 500,
"index_patterns" : [
"test-stats*"
],
"mappings" : {
"metrics" : {
"properties" : {
"double_field" : {
"type" : "double"
},
"float_field" : {
"type" : "float"
},
"small_float_field" : {
"type" : "float"
}
}
}
}
}'
Then pump in some test data:
curl -X POST "localhost:9200/test-stats/metrics/_bulk?pretty" -H 'Content-Type: application/json' -d'
{ "index" : { "_id" : "1" } }
{ "float_field" : 1000000000.100, "small_float_field" : 100.100, "double_field" : 1000000000.100 }
{ "index" : { "_id" : "2" } }
{ "float_field" : 1000000011.200, "small_float_field" : 200.100, "double_field" : 1000000011.200 }
{ "index" : { "_id" : "3" } }
{ "float_field" : 1000000022.300, "small_float_field" : 300.100, "double_field" : 1000000022.300 }
{ "index" : { "_id" : "4" } }
{ "float_field" : 1000000033.400, "small_float_field" : 400.100, "double_field" : 1000000033.400 }
{ "index" : { "_id" : "5" } }
{ "float_field" : 1000000044.500, "small_float_field" : 500.100, "double_field" : 1000000044.500 }
'
My findings:
- The problem only happens with large floats but I am not sure why because as you can see these float values are not too large or are they?
- For small float values and double values, the range query works fine.
These are the range queries for small float values and double values which work fine:
curl -X GET "localhost:9200/test-stats/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"small_float_field" : {
"gte" : 100,
"lte" : 400
}
}
}
}
'
Output
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000112E9,
"small_float_field" : 200.1,
"double_field" : 1.0000000112E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000001E9,
"small_float_field" : 100.1,
"double_field" : 1.0000000001E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000223E9,
"small_float_field" : 300.1,
"double_field" : 1.0000000223E9
}
}
]
}
}
curl -X GET "localhost:9200/test-stats/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"double_field" : {
"gte" : 1000000020,
"lte" : 1000000040
}
}
}
}
'
Output
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000334E9,
"small_float_field" : 400.1,
"double_field" : 1.0000000334E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000223E9,
"small_float_field" : 300.1,
"double_field" : 1.0000000223E9
}
}
]
}
}
But the range query for the large float field (which should return exactly the same results as the range query done for the double_field) returns results outside of the range:
curl -X GET "localhost:9200/test-stats/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"float_field" : {
"gte" : 1000000020,
"lte" : 1000000040
}
}
}
}
'
Output
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000445E9,
"small_float_field" : 500.1,
"double_field" : 1.0000000445E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000112E9,
"small_float_field" : 200.1,
"double_field" : 1.0000000112E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000334E9,
"small_float_field" : 400.1,
"double_field" : 1.0000000334E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000001E9,
"small_float_field" : 100.1,
"double_field" : 1.0000000001E9
}
},
{
"_index" : "test-stats",
"_type" : "metrics",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"float_field" : 1.0000000223E9,
"small_float_field" : 300.1,
"double_field" : 1.0000000223E9
}
}
]
}
}