0

I saw here https://github.com/elastic/elasticsearch/pull/32213 that Elasticsearch added support for ingest of hex strings as type long or integer for version 7.0.0 and moving forward.

But when I use my Elasticsearch 7.3 and set the type to "integer" or "long" and then try to index a value of "0x1234" I get an error[1].

[1] this is from python:

RequestError: RequestError(400, u'mapper_parsing_exception', u'failed to parse field [KEYWORD] of type [long] in document with id '#############'. Preview of field's value: 0x1234'")

Elasticsearch: how do you ingest a hex string as a number type (integer or long)?

Maybe there is some sort of config value to turn this feature on... but I couldn't find any in the documentation.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177

1 Answers1

1

The PR you're referencing concerns ingest pipelines -- a collection of tools to help prepare document values before they're inserted into ES.

But good that you've mentioned it -- the convert processor is a suitable solution here:

  1. Store a pipeline that converts the string content of the field KEYWORD into a long:
PUT _ingest/pipeline/hex-converter
{
  "description": "converts the content of the KEYWORD field to a long",
  "processors" : [
    {
      "convert" : {
        "field" : "KEYWORD",
        "type": "long"
      }
    }
  ]
}
  1. Use this pipeline as you insert the docs:
POST myindex/_doc?pipeline=hex-converter
{
  "KEYWORD": "0x1234"
}
  1. Verify that it worked -- we're expecting 4660 as the result:
POST myindex/_search

Pipelines make some quite powerful operations possible: see here or here.

Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68