Elasticsearch,Max的映射类型长度很长

我的映射:

POST /packtwo-order-sku-log { "settings": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "baitu": { "properties": { "order_id":{ "type": "long" }, .... } } } } 

当我搜索

"query": {"term" : {"order_id" : 10160815114820888}}

要么

 "query": {"match" : {"order_id" : 10160815114820888}} 

我得到了0; 但当我将order_id更改为1016081511482088 7时 ,我获得了点击率。 但是,返回的JSON ES显示:

  "hits": [ { "_index": "packtwo-order-sku-log", "_type": "baitu", "_id": "AVaMWcchVwJTsNV878q2", "_score": 2.7917593, "_source": { "order_id": 10160815114820888, ... } } 

我搜索了10160815114820888 – >没有结果

我搜索了1016081511482088 7 – >结果是1016081511482088 8

我在官方文档中找到了long类型:

 long A signed 64-bit integer with a minimum value of -2^63 and a maximum value of 2^63-1 

我的数据不超过2 ^ 63-1

那么,我的问题是什么?

这是由于IEEE-754双精度浮点值的舍入问题 。

可以安全地表示直到53位的整个值,但是,10160815114820887是54位长(100100000110010011010100011111100011000001110100010111)

您索引的实数确实是10160815114820887,但由于上述四舍五入问题,它被编入索引并显示为10160815114820888

您可以在浏览器的Javascript控制台中尝试以下操作:

 > var num = 10160815114820887; <--- assign value < undefined > num <--- display value < 10160815114820888 

您也可以在ES中尝试快速测试:

 # create doc with 10160815114820887 POST test/test/1 { "number": 10160815114820887 } # get doc 1 GET test/test/1 # result { "number": 10160815114820888 } 

正如您所看到的,您编入索引的数字(10160815114820887)显示为10160815114820888,可以找到10160815114820887,因为它在搜索时也会四舍五入为10160815114820888。