2016-12-24 1 views
0

rddからelasticsearch(pyspark、python 3.5)に書き込もうとしています。 私はjsonのボディを正しく書くことができますが、私の_idを取る代わりにelasticsearchを作成すると、それは独自のものになります。elasticsearch-hadoopに_idを設定できません

マイコード:

class Article: 
    def __init__(self, title, text, text2): 
     self.id_ = title 
     self.text = text 
     self.text2 = text2 

if __name__ == '__main__': 

    pt=_sc.parallelize([Article("rt", "ted", "ted2"),Article("rt2", "ted2", "ted22")]) 
     save=pt.map(lambda item: 
     (item.id_, 
      { 
      'text' : item.text, 
      'text2' : item.text2 
      } 
     )) 

     es_write_conf = { 
      "es.nodes": "localhost", 
      "es.port": "9200", 
      "es.resource": 'db/table1' 
     } 
     save.saveAsNewAPIHadoopFile(
      path='-', 
      outputFormatClass="org.elasticsearch.hadoop.mr.EsOutputFormat", 
      keyClass="org.apache.hadoop.io.NullWritable", 
      valueClass="org.elasticsearch.hadoop.mr.LinkedMapWritable", 
      conf=es_write_conf) 

プログラムトレース: link to the image

答えて

0

これは、インデックスへのマッピングの設定で、uが公式ユーザーガイドで見つけることができます。
サンプルコードは次のとおりです。

curl -XPOST localhost:9200/test -d '{ 
    "settings" : { 
     "number_of_shards" : 1, 
     "number_of_replicas":0 
    }, 
    "mappings" : { 
     "test1" : { 
      "_id":{"path":"mainkey"}, 
      "_source" : { "enabled" : false }, 
      "properties" : { 
       "mainkey" : { "type" : "string", "index" : "not_analyzed" } 
      } 
     } 
    } 
}' 
関連する問題