The jdbc plugin will create a JSON document with one field for each column. So to keep consistent with your example, if you had that data it would be imported as a document that looks like this:
{
"sensor_id": 567,
"temp": 90,
"humidity": 6,
"timestamp": "{time}",
"@timestamp": "{time}" // auto-created field, the time Logstash received the document
}
You were right when you said that if you set document_id
to your primary key, it would get overwritten. You can disregard document_id
unless you want to update existing documents in Elasticsearch, which I don't imagine you would want to do with this type of data. Let Elasticsearch generate the document id for you.
Now let's talk about document_type
. If you want to set the document type, you need to set the type
field in Logstash to some value (which will propagate into Elasticsearch). So the type field in Elasticsearch is used to group similar documents. If all of the documents in your table that you're importing with the jdbc plugin are of the same type (they should be!), you can set type
in the jdbc input like this...
input {
jdbc {
jdbc_driver_library => "mysql-connector-java-5.1.36-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/mydb"
jdbc_user => "mysql"
parameters => { "favorite_artist" => "Beethoven" }
schedule => "* * * * *"
statement => "SELECT * from songs where artist = :favorite_artist"
...
type => "weather"
}
}
Now, in Elasticsearch you can take advantage of the type
field by setting a mapping for that type. For example you might want:
PUT my_index
{
"mappings": {
"weather": {
"_all": { "enabled": false },
"properties": {
"sensor_id": { "type": "integer" },
"temp": { "type": "integer" },
"humidity": { "type": "integer" },
"timestamp": { "type": "date" }
}
}
}
}
Hope this helps! :)