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

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;"
}

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

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