如何通过spark读取elasticsearch的几列?

How to read a few columns of elasticsearch by spark?

在es集群中,它的数据量很大,我们使用spark来计算数据,但是是elasticsearch-hadoop的方式,后面是https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html

我们必须读取索引的完整列。有什么帮助吗?

是的,您可以分别设置配置参数"es.read.field.include"或"es.read.field.exclude"。完整详情 here。假设 Spark 2 或更高版本的示例。

val sparkSession:SparkSession = SparkSession
  .builder()
  .appName("jobName")
  .config("es.nodes", "elastichostc1n1.example.com")
  .config("es.read.field.include", "foo,bar")
  .getOrCreate()