# Logstash jdbc type conflicts with statement field

**URL:** <https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121>\
**Category:** Logstash\
**Created:** [March 10, 2017, 9:31am UTC](https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121 "2017-03-10T09:31:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![copywrite](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@copywrite](https://discuss.elastic.co/u/copywrite)\
**Post date:** [March 10, 2017, 9:31am UTC](https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121/1 "2017-03-10T09:31:56Z")

</div>

i have a conf as follows

input {  
jdbc {  
statement =\> 'select type from item'  
type =\> "item"  
}  
}

output {  
elasticsearch {  
document\_type =\> '%{type}'  
}  
}

the output type value is from statement field.

what i want is the value defined by type =\> "item".

any sugguestions?

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [March 10, 2017, 12:56pm UTC](https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121/2 "2017-03-10T12:56:18Z")

</div>

Having `type => "item"` in the input declaration will set the value of field `type` to `item`, regardless of what is in your `statement`. This is because Logstash "decorates" the event with whatever `tags` you define, as well as `type`, _after_ the input plugin has completed its data collection.

As data leaves an input block it becomes an event, and the decorator fields `tags` and `type` are added to the event.

Unfortunately, that makes `type` a semi-protected field because

```auto
document_type => '%{type}'

```

is already the default behavior in the Elasticsearch output plugin code. If a `type` field exists, that value will always be used as the `document_type`. Because Elasticsearch requires a "type" for mapping (and this becomes the `_type` metadata field in Elasticsearch), if _no_ `type` field exists in a Logstash event, a default of `logs` will be assigned.

If you omit or comment the line `type => "item"`, it should work, as there will be no decorator added for `type` in this case. The other possibility is to change your SQL to `select type from item as mytype`, and use the field `mytype` instead.

---

<div class="post-metadata">

**Author:** ![copywrite](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@copywrite](https://discuss.elastic.co/u/copywrite)\
**Post date:** [March 14, 2017, 10:20am UTC](https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121/3 "2017-03-14T10:20:18Z")

</div>

Thanks  
problem solved.

---

<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:** [April 11, 2017, 10:20am UTC](https://discuss.elastic.co/t/logstash-jdbc-type-conflicts-with-statement-field/78121/4 "2017-04-11T10:20:18Z")

</div>

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