Elasticsearch , 映射类型的最大长度 long [英] Elasticsearch , Max length of mapping type long

查看:51
本文介绍了Elasticsearch , 映射类型的最大长度 long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的映射:

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 更改为 10160815114820887 时,我得到了点击.但是,返回的 JSON ES 显示:

I got hits 0; But when I change order_id to 10160815114820887 , I got hits. However, the JSON ES returned shows :

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

我搜索了 10160815114820888 -> 没有结果

I searched 10160815114820888 -> no result

我搜索了 10160815114820887 -> 结果是 10160815114820888

I searched 10160815114820887 -> result is 10160815114820888

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

I find long type in official doc :

long

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

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

My data is not longer than 2^63-1

那么,我的问题是什么?

So,what is my problem?

推荐答案

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

That's due to a rounding issue for IEEE-754 double-precision floating point values.

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

Whole values up until 53 bits can be represented safely, however, 10160815114820887 is 54 bits long (100100000110010011010100011111100011000001110100010111)

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

The real number you have indexed was indeed 10160815114820887, but due to the above-mentioned rounding issues, it was indexed and shows as 10160815114820888

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

You can try the following in your browser's Javascript console:

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

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

You can also try a quick test in your ES:

# create doc with 10160815114820887
POST test/test/1
{ "number": 10160815114820887 }

# get doc 1
GET test/test/1
# result
{ "number": 10160815114820888 }

如您所见,您编入索引的数字 (10160815114820887) 显示为 10160815114820888,并且可以找到为 10160815114820887,因为它也在搜索时四舍五入为 1016082158188p.

As you can see, the number you have indexed (10160815114820887) shows up as 10160815114820888, and can be found as 10160815114820887 because it also gets rounded to 10160815114820888 at search time.

这篇关于Elasticsearch , 映射类型的最大长度 long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆