# Logstash's Elasticsearch output script context is getting an Integer field as a String

**URL:** <https://discuss.elastic.co/t/logstashs-elasticsearch-output-script-context-is-getting-an-integer-field-as-a-string/165779>\
**Category:** Logstash\
**Created:** [January 25, 2019, 1:10pm UTC](https://discuss.elastic.co/t/logstashs-elasticsearch-output-script-context-is-getting-an-integer-field-as-a-string/165779 "2019-01-25T13:10:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ffknob](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ffknob/32/37008_2.png) [@ffknob](https://discuss.elastic.co/u/ffknob)\
**Post date:** [January 25, 2019, 1:10pm UTC](https://discuss.elastic.co/t/logstashs-elasticsearch-output-script-context-is-getting-an-integer-field-as-a-string/165779/1 "2019-01-25T13:10:34Z")

</div>

Hello,  
I'm confused by why the Elasticsearch output is getting an Integer field as String. The effect I'm getting is that when I tryh to increment this field, it appends the incremental value (1) to the end of the field's value.

Thank you for your help

Elasticsearch mapping, forcing the field to be an Integer:

```
{
  "settings": {
    "index": {
      "mapping": {
        "total_fields.limit": 2000
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "qtdEventos": {
          "type": "integer"
        }
      }
    }
  }
}

```

Field initialization in Logstash (relevant part)...:

```
mutate {
	add_field => {
		"qtdEventos" => 0
	}

	# I don't know if this is necessary... just trying anything to get thi to work
	convert => {
		"qtdEventos" => "integer"
	}
}

```

Output to Elasticsearch:

```
elasticsearch {
	hosts => ["vmsrv103:9200"]
	index => "nfe"
	document_type => "_doc"
	document_id => "%{id}"
	action => "update"
	doc_as_upsert => true
	script_lang => "painless"
	script_type => "inline"
	script => "ctx._source.qtdEventos += 1;"
}
```

---

<div class="post-metadata">

**Author:** ![ffknob](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ffknob/32/37008_2.png) [@ffknob](https://discuss.elastic.co/u/ffknob)\
**Post date:** [January 25, 2019, 1:54pm UTC](https://discuss.elastic.co/t/logstashs-elasticsearch-output-script-context-is-getting-an-integer-field-as-a-string/165779/2 "2019-01-25T13:54:26Z")

</div>

I've managed to get this to work with the following script:

`script => "ctx._source.qtdEventos = (Integer.parseInt(ctx._source.qtdEventos) + 1).toString();"`

But I still don't understand why the context thinks the Integer field is a 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:** [February 22, 2019, 1:54pm UTC](https://discuss.elastic.co/t/logstashs-elasticsearch-output-script-context-is-getting-an-integer-field-as-a-string/165779/3 "2019-02-22T13:54:35Z")

</div>

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