在弹性搜索中将数字字段索引为 int 和 string

indexing numeric field as both int and string in elastic search

如何使用 multi_field 将数字字段索引为整数和字符串。由于 multi_field 现在已弃用。我如何使用版本 2.x 中的 "fields" 字段实现相同的目的。我听说可以使用 "fields" 以不同的方式对字段进行索引和分析。但是在elasticsearch中能不能索引为不同的类型呢?

我面临的问题是 elastic 中的经典数字字段搜索突出显示问题 search.where 我无法突出显示数字字段。所以我想将该字段索引为字符串和整数,以便我可以对数据进行搜索、突出显示和执行范围操作。

您也可以像这样使用 fields 将您的数字设为 string

{
  "mappings": {
    "test": {
      "properties": {
        "my_numeric": {
          "type": "integer",
          "fields": {
            "as_string": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}