How to group all the values for a column into an array jdbc mysql


I am trying to import data from mysql to elasticsearch via logstash and i would like to know if it's possible to group all the values for a column into an array per id.

for example in mysql, results of query is

 '_id',   'name'       , 'tag' 
'1', 'Reparer PC', 'tec'
'1', 'Reparer PC', 'Urgent'
'1', 'Reparer PC', 'jdbc'

and i would like to create a unique document like this in elasticsearch.

id:1, 'Reparer PC', task.tag { tec, Urgent, jdbc}

logstash configuration

input {
    jdbc {
        # Postgres jdbc connection string to our database, mydb
        jdbc_connection_string => "jdbc:mysql://******:3306/demo_es"
        # The user we wish to execute our statement as
        jdbc_user => "admin"
        jdbc_password => "******"
        # The path to our downloaded jdbc driver
        jdbc_driver_library => "/root/elasticsearch-jdbc-"
        # The name of the driver class for Postgresql
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        # our query
        statement => "select AS '_id', AS '', AS 'task.tags' from taches inner join tagstaches ON = tagstaches.idtache inner join tags on tagstaches.idtag = tags.idtags order by"

output {
    elasticsearch {
        protocol => http
        index => "tasks"
        document_type => "task"
        document_id => "%{_id}"
        host => "localhost"

This conf create a document where task.tag have only jdbc.

Thanks for your help,


1 Like

Hi @clp,

Have you found a solution to your problem? I encountered the same problem where I would like to group the values for one column into an array per id.
It would even be better if there was functionality which allows to create a nested object such that you can add multiple columns per id.