我对 Elasticsearch 还很陌生。我使用的是elasticsearch-hadoop 6.2.4
版本,我正在从HDFS
读取文件,转换为bean对象并写入elasticsearch。我正在使用 Spark 结构化流。
StreamingQuery query = dataSet
.writeStream()
.format("org.elasticsearch.spark.sql")
//.outputMode(OutputMode.Append())
.option("checkpointLocation", "\tmp\ckpt1")
.option("es.nodes","abc.dev.cm.par.xy.hp")
.option("es.port","9200")
.option("es.mapping.id", "CustomerID")
.option("es.resource", "testIndex/testType")
.start();
在写作时,我将 pojo 类中的字段之一 (CustomerID
) 指定为映射 ID。我们可以给多个字段或字段组合作为映射 ID 吗?例如,我的文件包含客户 ID 和订单 ID 字段。我们可以将这两个字段组合为 CustomerID+OrderID 之类的东西吗?
最佳答案
不,您不能将多个属性设置为 "es.mapping.id" 。您可以做的一件事是,无论您想要什么复合 ID,创建它并将其附加到数据框并使用相同的。
关于java - Elastic Search - Spark 中的多个字段作为映射 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50756060/