2016-05-31 14 views
0

私はELKスタック、特にESを新しくしました。 Google Admin SDK APIを使用して取得したJSONファイルをインポートしようとしていますが、これをElasticsearchにインポートします。Google API JSONファイルをElasticsearchにインポートする

これまでのところ、これは私のデータのJSON構造である:

curl -s -XPOST 'localhost:9200/_bulk' --data-binary @documents.json 

しかし、私は若干の誤差が出る:

{ 
"kind": "reports#activities", 
"nextPageToken": string, 
"items": [ 
{ 
"kind": "audit#activity", 
    "id": { 
    "time": datetime, 
    "uniqueQualifier": long, 
    "applicationName": string, 
    "customerId": string 
    }, 
    "actor": { 
    "callerType": string, 
    "email": string, 
    "profileId": long, 
    "key": string 
    }, 
    "ownerDomain": string, 
    "ipAddress": string, 
    "events": [ 
    { 
     "type": string, 
     "name": string, 
     "parameters": [ 
     { 
      "name": string, 
      "value": string, 
      "intValue": long, 
      "boolValue": boolean 
     } 
     ] 
    } 
    ] 
    } 
] 
} 

は、だから私は、最初のESにJSONファイルをアップロードするには、このコマンドを使用することにしました:

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected START_OBJECT or END_OBJECT but found [START_ARRAY]"}],"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected START_OBJECT or END_OBJECT but found [START_ARRAY]"},"status":400} 

どうすればよいですか?

ありがとうございました!

答えて

0

JSONがドキュメント構造を定義していると思われるので、最初にその構造に一致するマッピングを持つインデックスを作成する必要があります。あなたのケースでは、あなたはこのようにそれを行うことができます:

curl -XPUT localhost:9200/reports -d '{ 
    "nextPageToken": { 
    "type": "string" 
    }, 
    "items": { 
    "properties": { 
     "kind": { 
     "type": "string" 
     }, 
     "id": { 
     "properties": { 
      "time": { 
      "type": "date", 
      "format": "date_time" 
      }, 
      "uniqueQualifier": { 
      "type": "long" 
      }, 
      "applicationName": { 
      "type": "string" 
      }, 
      "customerId": { 
      "type": "string" 
      } 
     } 
     }, 
     "actor": { 
     "properties": { 
      "callerType": { 
      "type": "string" 
      }, 
      "email": { 
      "type": "string" 
      }, 
      "profileId": { 
      "type": "long" 
      }, 
      "key": { 
      "type": "string" 
      } 
     } 
     }, 
     "ownerDomain": { 
     "type": "string" 
     }, 
     "ipAddress": { 
     "type": "string" 
     }, 
     "events": { 
     "properties": { 
      "type": { 
      "type": "string" 
      }, 
      "name": { 
      "type": "string" 
      }, 
      "parameters": { 
      "properties": { 
       "name": { 
       "type": "string" 
       }, 
       "value": { 
       "type": "string" 
       }, 
       "intValue": { 
       "type": "long" 
       }, 
       "boolValue": { 
       "type": "boolean" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
}' 

これが行われている、ことができます一括呼び出しを使用して上記の構造に従ってください今すぐインデックスあなたのreports#activities書類。バルクコールの構文は、正確にはhereと定義されています。つまり、コマンドライン(何をする)が必要なのでしょうか?

したがって、documents.jsonファイルをこのように再フォーマットする必要があります(2行目以降に改行を追加してください)。また、プロセスを説明するためにいくつかのダミーデータを追加したことにも注意してください。

{"index": {"_index": "reports", "_type": "activity"}} 
{"kind":"reports#activities","nextPageToken":"string","items":[{"kind":"audit#activity","id":{"time":"2016-05-31T00:00:00.000Z","uniqueQualifier":1,"applicationName":"string","customerId":"string"},"actor":{"callerType":"string","email":"string","profileId":1,"key":"string"},"ownerDomain":"string","ipAddress":"string","events":[{"type":"string","name":"string","parameters":[{"name":"string","value":"string","intValue":1,"boolValue":true}]}]}]} 
+0

チップをありがとうVal!実際に私のJSONデータには配列(items []、events []、parameters [])が含まれているので、中括弧を中括弧に置き換えてインデックス作成に関するコードを少し編集しました。 – Felz

+0

いいえ、それは意図的に行われたものではありません.ESはそれらの配列を作成します;)[this](https://www.elastic.co/guide/re/current/array.html ) – Val

関連する問題