2017-02-24 7 views
0

今、LogStashが処理しているデータを取得するために "match_all"クエリを使用しています。私が得た出力は、イベントの一部であるすべての単一フィールドです。ここに私の質問があります:curlでLogstashを照会して特定のフィールドのみを返す方法

{ 
"query": { 
    "match_all" : { } 
}, 
    "size": 1, 
    "sort": [ 
{ 
"@timestamp": { 
    "order": "desc" 
    } 
    } 
    ] 
} 

ご覧のとおり、出力された最新の結果が常に得られるようにソートしています。ここで

が私の出力の例を示します。

{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 15768, 
    "max_score" : null, 
    "hits" : [ 
     { 
     "_index" : "filebeat-2017.02.24", 
     "_type" : "bro", 
     "_id" : "AVpx-pFtiEtl3Zqhg8tF", 
     "_score" : null, 
     "_source" : { 
      "resp_pkts" : 0, 
      "source" : "/usr/local/bro/logs/current/conn.log", 
      "type" : "bro", 
      "id_orig_p" : 56058, 
      "duration" : 848.388112, 
      "local_resp" : true, 
      "uid" : "CPndOf4NNf9CzTILFi", 
      "id_orig_h" : "192.168.137.130", 
      "conn_state" : "OTH", 
      "@version" : "1", 
      "beat" : { 
      "hostname" : "localhost.localdomain", 
      "name" : "localhost.localdomain", 
      "version" : "5.2.0" 
      }, 
      "host" : "localhost.localdomain", 
      "id_resp_h" : "192.168.137.141", 
      "id_resp_p" : 22, 
      "resp_ip_bytes" : 0, 
      "offset" : 115612, 
      "orig_bytes" : 32052, 
      "local_orig" : true, 
      "input_type" : "log", 
      "orig_ip_bytes" : 102980, 
      "orig_pkts" : 1364, 
      "missed_bytes" : 0, 
      "history" : "DcA", 
      "tunnel_parents" : [ ], 
      "message" : "{\"ts\":1487969779.653504,\"uid\":\"CPndOf4NNf9CzTILFi\",\"id_orig_h\":\"192.168.137.130\",\"id_orig_p\":56058,\"id_resp_h\":\"192.168.137.141\",\"id_resp_p\":22,\"proto\":\"tcp\",\"duration\":848.388112,\"orig_bytes\":32052,\"resp_bytes\":0,\"conn_state\":\"OTH\",\"local_orig\":true,\"local_resp\":true,\"missed_bytes\":0,\"history\":\"DcA\",\"orig_pkts\":1364,\"orig_ip_bytes\":102980,\"resp_pkts\":0,\"resp_ip_bytes\":0,\"tunnel_parents\":[]}", 
      "tags" : [ 
      "beats_input_codec_plain_applied" 
      ], 
      "@timestamp" : "2017-02-24T21:15:29.414Z", 
      "resp_bytes" : 0, 
      "proto" : "tcp", 
      "fields" : { 
      "sensorType" : "networksensor" 
      }, 
      "ts" : 1.487969779653504E9 
     }, 
     "sort" : [ 
      1487970929414 
     ] 
     } 
    ] 
    } 
} 

あなたが見ることができるように、それは、C#で書かれた外部のアプリケーション(ので、ガベージコレクションで処理するために、出力の多くが上の巨大ですこれらすべての文字列)、私はちょうど必要はありません。

私の質問は、私が必要とするフィールドだけを取得できるように、どのように設定できますか?

答えて

2

5.xについては、_sourceをフィルタリングする変更がありました。

{ 
"query": { 
    "match_all" : { } 
}, 
"size": 1, 
"_source": ["a","b"], 
... 

そして結果は以下のようになります:前5へ

バージョンの
{ 
    "took" : 2, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ 
     { 
     "_index" : "xxx", 
     "_type" : "xxx", 
     "_id" : "xxx", 
     "_score" : 1.0, 
     "_source" : { 
      "a" : 1, 
      "b" : "2" 
     } 
     } 
    ] 
    } 
} 

、あなたはフィールドパラメータでそれを行うことができます。そのためのドキュメントは、それは次のようになり、hereある

クエリでは、クエリのルートレベルで,"fields": ["field1","field2"...]を渡すことができます。それが戻って来るフォーマットは違うでしょうが、それは動作します。このような出力を生成します

{ 
"query": { 
    "match_all" : { } 
}, 
"size": 1, 
"fields": ["a","b"], 
... 

{ 
    "took": 9, 
    "timed_out": false, 
    "_shards": { 
    "total": 1, 
    "successful": 1, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 2077, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "xxx", 
     "_type": "xxx", 
     "_id": "xxxx", 
     "_score": 1, 
     "fields": { 
      "a": [ 
      0 
      ], 
      "b": [ 
      "xyz" 
      ] 
     } 
     } 
    ] 
    } 
} 

フィールドは常に(1.0 API以降)の配列であり、Elasticsearchは認識して、本質的にmutli-値であるため、その変更する方法はありません。 5.2を実行している

+0

、私は実際にそれからエラーを取得: 'code'を{ "エラー":{ "ROOT_CAUSE":[ { "タイプ": "parsing_exception"、 "理由":「フィールドが格納されていない場合は、[stored_fields]を使用してフィールドを保存するか、_sourceフィルタリングを使用してください。 "" line ":6、 " col ":13 } " status " 400 } 'code' – BenjaFriend

+0

' fields'の代わりに 'stored_fields'を使ってみましたか(私は5.xのAPIへのその変更を知らなかった) – Alcanzar

+0

私はやった私はただフィールドなしで出力を得ます – BenjaFriend

関連する問題