# \[ingest pipeline\] set convert in string

**URL:** <https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806>\
**Category:** Elasticsearch\
**Created:** [December 21, 2018, 8:14am UTC](https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806 "2018-12-21T08:14:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [December 21, 2018, 8:14am UTC](https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806/1 "2018-12-21T08:14:04Z")

</div>

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... 😟

```
"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. 🎄

Thanks.

---

<div class="post-metadata">

**Author:** ![jakelandis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakelandis/32/36163_2.png) [@jakelandis](https://discuss.elastic.co/u/jakelandis)\
**Post date:** [December 21, 2018, 11:19pm UTC](https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806/2 "2018-12-21T23:19:24Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [December 25, 2018, 6:52am UTC](https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806/3 "2018-12-25T06:52:56Z")

</div>

Got it thanks for the help.  
🙇‍♂️

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 22, 2019, 6:53am UTC](https://discuss.elastic.co/t/ingest-pipeline-set-convert-in-string/161806/4 "2019-01-22T06:53:01Z")

</div>

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