Elasticsearch array of an object using logstash

Viewed 16

I have a mysql database working as a primary database and i'm ingesting data into elasticsearch from mysql using logstash. I have successfully indexed the users table into elasticsearch and it is working perfectly fine however, my users table has fields interest_id and interest_name which contains the ids and names of user interests as follows:

"interest_id" : "1,2",

"interest_name" : "Business,Farming"

What i'm trying to achieve:

I want to make an object of interests and this object should contain array of interest ids and interests_names like so:

interests : {

[

"interest_name" : "Business"

"interest_id" : "1"

],

[

"interest_name" : "Farming"

"interest_id" : "2"

]

}

Please let me know if its possible and also what is the best approach to achieve this.

My conf:

input {

jdbc { jdbc_driver_library => "/home/logstash-7.16.3/logstash-core/lib/jars/mysql-connector-java- 8.0.22.jar"

jdbc_driver_class => "com.mysql.jdbc.Driver"

jdbc_connection_string => "jdbc:mysql://localhost:3306/"

jdbc_user => "XXXXX"

jdbc_password => "XXXXXXX"

sql_log_level => "debug"

clean_run => true

record_last_run => false

statement_filepath => "/home/logstash-7.16.3/config/queries/query.sql"

}

}

filter {

mutate {

remove_field => ["@version", "@timestamp",]

}

}

output {

elasticsearch {

hosts => ["https://XXXXXXXXXXXX:443"]

index => "users"

action => "index"

user => "XXXX"

password => "XXXXXX"

template_name => "myindex"

template => "/home/logstash-7.16.3/config/my_mapping.json"

template_overwrite => true

}

}

I have tried doing this by creating a nested field interests in my mapping and then adding mutate filer in my conf file like this:

mutate {

rename => {

"interest_id" => "[interests][interest_id]"

"interest_name" => "[interests][interest_name]"

}

With this i'm only able to get this output:

"interests" : {

"interest_id" : "1,2",

"interest_name" : "Business,Farming"

}

0 Answers
Related