精度
es查询结果超过16位导致精度丢失
Elasticsearch • ELKer 回复了问题 • 6 人关注 • 5 个回复 • 5049 次浏览 • 2019-11-19 18:40
float类型存储在es中会有精度损失
Elasticsearch • wjx1015 回复了问题 • 5 人关注 • 3 个回复 • 14077 次浏览 • 2018-09-25 15:04
elasticsearch 聚合函数 sum() 精度的问题
Elasticsearch • Cheetah 回复了问题 • 4 人关注 • 2 个回复 • 11033 次浏览 • 2017-08-31 10:53
你应该是从doc里读取的数据,如果从_source里读取就没这个问题。 不太清楚doc_values为什么对float类型会有精度损失,不过测试了一下,如果用double,则doc value里读取出来的精度和source里的一样,没有这个问题。[code]P... 显示全部 »
你应该是从doc里读取的数据,如果从_source里读取就没这个问题。 不太清楚doc_values为什么对float类型会有精度损失,不过测试了一下,如果用double,则doc value里读取出来的精度和source里的一样,没有这个问题。[code]PUT testme
{
"settings": {},
"mappings": {
"doc": {
"properties": {
"id": {
"type": "double"
}
}
}
}
}
POST testme/doc
{
"id": 1.01
}
POST testme/_search
{
"docvalue_fields": [
"id"
]
}
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits":
}
}
]
}
}
或者觉得doulbe精度过高,浪费存储空间的话,也可以用scaled_float,看起来也是OK的[code]PUT testme
{
"settings": {},
"mappings": {
"doc": {
"properties": {
"id": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
POST testme/doc
{
"id": 1.01
}
POST testme/_search
{
"docvalue_fields": [
"id"
]
}
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits":
}
}
]
}
}
{
"settings": {},
"mappings": {
"doc": {
"properties": {
"id": {
"type": "double"
}
}
}
}
}
POST testme/doc
{
"id": 1.01
}
POST testme/_search
{
"docvalue_fields": [
"id"
]
}
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits":
}
}
]
}
}
或者觉得doulbe精度过高,浪费存储空间的话,也可以用scaled_float,看起来也是OK的[code]PUT testme
{
"settings": {},
"mappings": {
"doc": {
"properties": {
"id": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
POST testme/doc
{
"id": 1.01
}
POST testme/_search
{
"docvalue_fields": [
"id"
]
}
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits":
}
}
]
}
}
elasticsearch 聚合函数 sum() 精度的问题
回复Elasticsearch • Cheetah 回复了问题 • 4 人关注 • 2 个回复 • 11033 次浏览 • 2017-08-31 10:53