首页 > 解决方案 > Elasticsearch:如何将十六进制字符串作为数字类型(整数或长整数)摄取?

问题描述

我在这里看到https://github.com/elastic/elasticsearch/pull/32213,Elasticsearch 添加了对 7.0.0 版本的长或整数类型的十六进制字符串摄取的支持并向前发展。

但是当我使用我的 Elasticsearch 7.3 并将类型设置为“整数”或“长”,然后尝试索引“0x1234”的值时,我得到一个错误[1]。

[1] 这是来自 python:

RequestError: RequestError(400, u'mapper_parsing_exception', u'failed to parse field [KEYWORD] of type [long] in document with id '#############'。预览字段值: 0x1234'")

Elasticsearch:如何将十六进制字符串作为数字类型(整数或长整数)摄取?

也许有某种配置值可以打开此功能......但我在文档中找不到任何内容。

标签: elasticsearch

解决方案


您引用的 PR 涉及摄取管道 - 一组工具,可帮助在将文档值插入 ES之前准备文档值。

但是很好,你已经提到了——convert处理器是一个合适的解决方案:

  1. 存储将字段的字符串内容转换为的KEYWORD管道long
PUT _ingest/pipeline/hex-converter
{
  "description": "converts the content of the KEYWORD field to a long",
  "processors" : [
    {
      "convert" : {
        "field" : "KEYWORD",
        "type": "long"
      }
    }
  ]
}
  1. 在插入文档时使用此管道:
POST myindex/_doc?pipeline=hex-converter
{
  "KEYWORD": "0x1234"
}
  1. 验证它是否有效——我们预计结果为 4660:
POST myindex/_search

管道使一些非常强大的操作成为可能:请参见此处此处


推荐阅读