2016-07-04 14 views
0

私はPythonでElasticsearchを使用しています。私はpandasフレーム(3列)にデータを持っています。そして、_indexと_typeの2つの列を追加し、pandas inbuiltメソッドを使って各レコードと共にjsonにデータを変換しました。バルクデータをElasticsearchにロード中にエラーが発生しました。

data = data.to_json(orient='records') 

これが私のデータで、その後、

[{"op_key":99140046678,"employee_key":991400459,"Revenue Results":6625.76480192,"_index":"revenueindex","_type":"revenuetype"},  
{"op_key":99140045489,"employee_key":9914004258,"Revenue Results":6691.05435536,"_index":"revenueindex","_type":"revenuetype"}, 
...... 
}] 

私のマッピングは次のとおりです。helpers.bulk(ES、データ)を使用しながら、このエラーが直面している

user_mapping = { 
     "settings" : { 
      "number_of_shards": 3, 
      "number_of_replicas": 2 
     }, 

     'mappings': { 
      'revenuetype': { 
       'properties': { 
        'op_key':{'type':'string'}, 
        'employee_key':{'type':'string'}, 
        'Revenue Results':{'type':'float','index':'not_analyzed'}, 
       } 
      } 
     } 
    } 

Traceback (most recent call last): 
     File "/Users/adaggula/Documents/workspace/ElSearchPython/sample.py", line 59, in <module> 
     res = helpers.bulk(client,data) 
     File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 188, in bulk 
     for ok, item in streaming_bulk(client, actions, **kwargs): 
     File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 160, in streaming_bulk 
     for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs): 
     File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 89, in _process_bulk_chunk 
     raise e 
    elasticsearch.exceptions.RequestError: TransportError(400, u'action_request_validation_exception', u'Validation Failed: 1: index is 
missing;2: type is missing;3: index is missing;4: type is missing;5: index is 
missing;6: ....... type is missing;999: index is missing;1000: type is missing;') 

すべてのjsonオブジェクト、インデックス、およびtのようですypeさんは行方不明です。これを克服する方法は?

答えて

0

パンダのデータフレームからjsonへの変換は、この問題を解決したトリックです。

data = data.to_json(orient='records') 
data= json.loads(data) 
+0

これは、 'data = to_dict(orient = 'records')'に短縮できることについて、ちょうどコメントしていました。そして、私は1.000.000行と50列のデータフレームで短いテストを実行し、あなたのバージョンがかなり速く実行されていることを発見しました...変わった 'df.to_dict()'は驚くほど遅いです。 – Dirk

+1

私は同様のエラーがあり、 'obj.to_dict(include_meta = True)'に 'include_meta = True'を追加することでそれを取り除きました。 – Anupam

関連する問題