繁体   English   中英

无法在elasticsearch-hadoop上设置_id

[英]Unable to set _id on elasticsearch-hadoop

我正在尝试从rdd写到elasticsearch(pyspark,python 3.5)。 我能够正确地编写json的主体,但是使用elasticsearch而不是使用_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)

程序跟踪: 链接到图像

这是到索引的映射的设置,您可以在官方用户指南中找到。
样例代码如下:

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" }
            }
        }
    }
}'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM