2017-02-09 8 views
1

大きなJSONドキュメントをElasticsearch 5.1にインポートしようとしています。データの小さな部分は、次のようになります。CURLを使用してJSONをElasticsearch 5.1にインポートする

[ 
    { 
     "id": 1, 
     "region": "ca-central-1", 
     "eventName": "CreateRole", 
     "eventTime": "2016-02-04T03:41:19.000Z", 
     "userName": "[email protected]" 
    }, 
    { 
     "id": 2, 
     "region": "ca-central-1", 
     "eventName": "AddRoleToInstanceProfile", 
     "eventTime": "2016-02-04T03:41:19.000Z", 
     "userName": "[email protected]" 
    }, 
    { 
     "id": 3, 
     "region": "ca-central-1", 
     "eventName": "CreateInstanceProfile", 
     "eventTime": "2016-02-04T03:41:19.000Z", 
     "userName": "[email protected]" 
    }, 
    { 
     "id": 4, 
     "region": "ca-central-1", 
     "eventName": "AttachGroupPolicy", 
     "eventTime": "2016-02-04T01:42:36.000Z", 
     "userName": "[email protected]" 
    }, 
    { 
     "id": 5, 
     "region": "ca-central-1", 
     "eventName": "AttachGroupPolicy", 
     "eventTime": "2016-02-04T01:39:20.000Z", 
     "userName": "[email protected]" 
    } 
] 

私は、可能な場合は、ソースデータに変更を加えることなく、データをインポートしたいと思いますので、私は_bulkコマンドアウトルールは私が必要だろうとと信じて各エントリの詳細を追加します。

私はいくつかの方法を試しましたが、運がなかった。このドキュメントをそのままインポートしようと時間を無駄にしていますか?

私が試してみた:

curl -XPOST 'demo.ap-southeast-2.es.amazonaws.com/rea/test' --data-binary @Records.json 

をしかし、それはエラーで失敗します。

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400} 

ありがとう!

答えて

1

ファイルを変更しない場合、バルクAPIは機能しません。

jqをご覧ください。 コマンドラインjsonパーサーです。バルクAPIを実行するために必要なドキュメントを生成するのに役立ちます。

cat Records.json | 
jq -c ' 
.[] | 
{ index: { _index: "index_name", _type: "type_name" } }, 
. ' 

これを試して、バルクAPIに渡すことができます。お役に立てれば。

また、このようなカールコールを試すこともできます。

cat Records.json | 
jq - 
.[] | 
{ index: { _index: "index_name", _type: "type_name" } }, 
. ' | curl -XPOST demo.ap-southeast-2.es.amazonaws.com/_bulk --data-binary @- 

2番目の部分は試していませんが動作するはずです。

+0

返信いただきありがとうございます。私はこれらのオプションを試し、報告して戻します! –

0

stream2esをチェックアウトすることができます。これは、ElasticSearchにドキュメントを送信するのに便利なユーティリティです。私はそれがあなたがする必要があることをするかもしれないと思います。

あなたはそれがインストールされていたら、あなたはそれを使用することができるはずです。このような何か:

cat Records.json | ./stream2es stdin --target 'http://demo.ap-southeast-2.es.amazonaws.com/rea/test' 
+0

返信いただきありがとうございます。私もstream2esを試してみましょう! –

関連する問題