title: Elasticsearch array of an object using logstash
body: <p>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:</p>
  <p>&quot;interest_id&quot; : &quot;1,2&quot;,</p>
  <p>&quot;interest_name&quot; : &quot;Business,Farming&quot;</p>
  <p><strong>What i'm trying to achieve:</strong></p>
  <p>I want to make an object of interests and this object should contain array of interest ids and interests_names like so:</p>
  <p>interests : {</p>
  <p>[</p>
  <p>&quot;interest_name&quot; : &quot;Business&quot;</p>
  <p>&quot;interest_id&quot; : &quot;1&quot;</p>
  <p>],</p>
  <p>[</p>
  <p>&quot;interest_name&quot; : &quot;Farming&quot;</p>
  <p>&quot;interest_id&quot; : &quot;2&quot;</p>
  <p>]</p>
  <p>}</p>
  <p><strong>Please let me know if its possible and also what is the best approach to achieve this.</strong></p>
  <p><strong>My conf:</strong></p>
  <p>input {</p>
  <p>jdbc {
  jdbc_driver_library =&gt; &quot;/home/logstash-7.16.3/logstash-core/lib/jars/mysql-connector-java-
  8.0.22.jar&quot;</p>
  <p>jdbc_driver_class =&gt; &quot;com.mysql.jdbc.Driver&quot;</p>
  <p>jdbc_connection_string =&gt; &quot;jdbc:mysql://localhost:3306/&quot;</p>
  <p>jdbc_user =&gt; &quot;XXXXX&quot;</p>
  <p>jdbc_password =&gt; &quot;XXXXXXX&quot;</p>
  <p>sql_log_level =&gt; &quot;debug&quot;</p>
  <p>clean_run =&gt; true</p>
  <p>record_last_run =&gt; false</p>
  <p>statement_filepath =&gt; &quot;/home/logstash-7.16.3/config/queries/query.sql&quot;</p>
  <p>}</p>
  <p>}</p>
  <p>filter {</p>
  <p>mutate {</p>
  <p>remove_field =&gt; [&quot;@version&quot;, &quot;@timestamp&quot;,]</p>
  <p>}</p>
  <p>}</p>
  <p>output {</p>
  <p>elasticsearch {</p>
  <p>hosts =&gt; [&quot;https://XXXXXXXXXXXX:443&quot;]</p>
  <p>index =&gt; &quot;users&quot;</p>
  <p>action =&gt; &quot;index&quot;</p>
  <p>user =&gt; &quot;XXXX&quot;</p>
  <p>password =&gt; &quot;XXXXXX&quot;</p>
  <p>template_name =&gt; &quot;myindex&quot;</p>
  <p>template =&gt; &quot;/home/logstash-7.16.3/config/my_mapping.json&quot;</p>
  <p>template_overwrite =&gt; true</p>
  <p>}</p>
  <p>}</p>
  <p><strong>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:</strong></p>
  <p>mutate {</p>
  <p>rename =&gt; {</p>
  <p>&quot;interest_id&quot; =&gt; &quot;[interests][interest_id]&quot;</p>
  <p>&quot;interest_name&quot; =&gt; &quot;[interests][interest_name]&quot;</p>
  <p>}</p>
  <p><strong>With this i'm only able to get this output:</strong></p>
  <p>&quot;interests&quot; : {</p>
  <p>&quot;interest_id&quot; : &quot;1,2&quot;,</p>
  <p>&quot;interest_name&quot; : &quot;Business,Farming&quot;</p>
  <p>}</p>