设置 scaling_factor 参数时的奇怪行为

Strange behavior when scaling_factor parameter is set

我正在使用 Elasticsearch 6.2.1,现在试图了解当 scaling_factor 参数设置为某个值时它是如何工作的。

根据文档,字段值乘以 scaling_factor,然后在索引时存储为 long。当 scaling_factor 为 100 时,我希望值 1.234 将在内部存储为 123,之后可以在索引中找到 1.23。我现在看到的是值 1.234 并没有失去它的精度,我可以从原始形式的索引中得到它:1.234.

是不是这个版本的Elasticsearch有bug?如果没有,有人可以解释一下幕后发生的事情吗?

更新

@Val 的回答阐明了 Elasticsearch 的行为,但我想了解为什么可以通过原始原始值查找文档,尽管索引仅包含缩放值。例如在以下映射的情况下:

{
  "mappings": {
    "properties": {
      "num": {
        "type": "scaled_float",
        "scaling_factor": 100
      }
    }
  }
}

我可以索引文档

{
  "num": 1.234
}

然后通过以下查询找到它:

{
  "query": {
    "match": {
      "num": 1.234
    }
  }
}

我预计上面的查询不会找到任何东西,因为索引只包含四舍五入的值 1.23。

如果你在源文件中看到1.234,那是正常的,ES从不修改源文件本身的任何东西。

鉴于此映射:

PUT scaling
{
  "mappings": {
    "properties": {
      "num": {
        "type": "scaled_float",
        "scaling_factor": 100
      }
    }
  }
}

如果您存储此文档

PUT scaling/_doc/1
{
  "num": "1.234"
}

然后检索文档,将产生与您索引相同的数据:

GET scaling/_doc/1
=>
{
  "num": "1.234"
}

但是,检索 num 字段的文档值将产生您期望的结果:

GET scaling/doc/_search
{
  "docvalue_fields": ["num"],
  "script_fields": {
    "doc_value": {
      "script": {
        "source": "doc.num.value"
      }
    },
    "raw_value": {
      "script": {
        "source": "params._source.num"
      }
    }
  }
}

=>

  {
    "_index" : "scaling",
    "_type" : "doc",
    "_id" : "1",
    "_score" : 1.0,
    "fields" : {
      "raw_value" : [
        "1.234"                  <--- raw value that was sent for indexing
      ],
      "doc_value" : [
        1.23                     <--- scaled doc value that was indexed
      ],
      "num" : [
        1.23                     <--- scaled doc value that was indexed
      ]
    }
  }