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

问题描述

我的映射:

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

OR

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

我得到了点击0;
但是当我将order_id更改为1016081511482088 7 时,我得到了点击。
但是,返回的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

我搜索1016081511482088 7 - >结果是1016081511482088 8

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

那么,我的问题?

推荐答案

这是因为。

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

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,因为它也在搜索时被舍入到10160815114820888。

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.

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

09-16 04:09