[ingest pipeline] set convert in string

Hi,

Using Elasticsearch 6.5.1

I tried to set a value using set and my new value become a string:

Here my debug simulate:

POST _ingest/pipeline/_simulate
{
  "pipeline" : {
    "description": "debug",
  "processors": [
    {
      "set": {
        "field": "end_int",
        "value": "(int){{end}}"
      }
    },
    {
      "set": {
        "if": "ctx.end > 2400;",
        "field": "result",
        "value": "Big"
      }
    },
    {
      "set": {
        "if": "ctx.end_int < 2400;",
        "field": "result",
        "value": "Small"
      }
    },
    {
      "remove": {
        "field": "end_int"
      }
    }
  ]},
  "docs": [
    {
      "_index": "banana",
      "_type": "_doc",
      "_id": "125468",
      "_score": 1,
      "_source": {
        "end": 2000
      }
    }
  ]
}

And it crash on the second condition the first condition is ok as end is integer but the one I set became a string... :worried:

"script_stack" : [
          "ctx.end_int < 2400;",
          "   ^---- HERE"
        ],
        "script" : "ctx.end_int < 2400;",
        "lang" : "painless",
        "caused_by" : {
          "type" : "class_cast_exception",
          "reason" : "Cannot apply [<] operation to types [java.lang.String] and [java.lang.Integer]."
        }

How can I keep the integer type when I use set?
As you can see in the simulate I add (int) but it not affect.

Only way to make it work is using convert

  "processors": [
{
  "set": {
    "field": "end_int",
    "value": "{{end}}"
  }
},
{
  "convert" : {
    "field" : "end_int",
    "type": "integer"
  }
},
....

If I set an integer I expect that my value stay integer. Did I mistake in the set definition?

Merry christmas. :christmas_tree:

Thanks.

If you run the simulation with verbose (POST _ingest/pipeline/_simulate?verbose) you can see you end up with "end_int" : "(int)2000" as the result of the set processor. That is still a String type.

Convert is the correct way to do this. You can simplify a bit like this:

      "convert": {
        "field": "end",
        "type": "integer",
        "target_field": "end_int"
      }
    }

Got it thanks for the help.
:bowing_man:

But just to confirm, the "set" always cast in string? maybe adding a line in the documentation about can be helpful.
The field end is a integer, if I want to copy it I need to use "convert" to keep the type not "set" that will cast it in string.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.