2017-02-14 2 views
0

J'ai un champ imbriqué avec des tableaux en tableau dans JSON comme ce qui suit:Comment traiter tableau JSON imbriqué dans Logstash

{ 
    "foo": { 
     "bar": [ 
      [ 
       "a", 
       "b" 
      ], 
      [ 
       "c", 
       "d" 
      ] 
     ] 
    } 
} 

Ce qui suit est mon fichier de configuration:

input { 
    file { 
     codec => "json" 
     path => "pathtofile" 
     type => "footype" 
     start_position => "beginning" 
    } 
} 
filter { 
    json { 
     source => "message" 
     remove_field => [ "host", "message", "path" ] 
    } 
} 
output { 
    elasticsearch { 
     action => "index" 
     index => "bar" 
     hosts => [ "http://localhost:9200" ] 
    } 
} 

Je suis la erreur suivante:

09:40:47.725 [[main]>worker0] WARN logstash.outputs.elasticsearch - Failed action. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"bar", :_type=>"footype", :_routing=>nil}, 2017-02-13T01:40:30.387Z myconnection %{message}], :response=>{"index"=>{"_index"=>"bar", "_type"=>"footype", "_id"=>"AVo1IN0vK2jgwdCXqZ-q", "status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"mapper [foo.bar] of different type, current_type [long], merged_type [text]"}}}}

J'ai l'impression que c'est le problème du tableau. J'ai fait des recherches et je sais que ce tableau n'est pas bien supporté. Mais j'ai besoin d'ingérer le tableau dans elasticsearch. Y a-t-il un moyen de faire cela?

Toute aide sera appréciée.

Répondre

0

Je résolu ce problème en utilisant un filtre rubis:

ruby { 
     code => ' 
      j = 0 
      for i in event.get("[foo][bar]") do 
       #i is an array element in the big array 
       l = 0 
       for k in i do 
        event.set("item#" + j.to_s + "#" + l.to_s, k) 
        l = l + 1 
       end 
       j = j + 1 
      end 
     ' 
    } 

Ce qui finira par produire des champs

item#0#0 = "a" 
item#0#1 = "b" 
item#1#0 = "c" 
item#1#1 = "d"