如何使用映射将数据帧保存到Elasticsearch

时间:2017-09-07 06:23:18

标签: scala apache-spark elasticsearch

我有以下代码将数据帧保存到弹性搜索。效果很好。

val conf = new SparkConf(true).set("spark.cassandra.connection.host", host)
    conf.set("spark.es.index.auto.create", "true")
    conf.set("spark.es.nodes", host)

 val features = sqlContext.read.parquet(input)

    features.write.format("org.elasticsearch.spark.sql")
      .mode(SaveMode.Append)
      .option("es.resource","{ts}/log").save()

当它不存在时,它会自动创建索引。但是当我尝试查询某些字段时。它显示以下错误

Set fielddata=true on [country] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.

我知道将文本字段设为关键字的映射

{
  "your_field": {
    "type" "keyword",
    "index": true
  }
}

但是在使用此代码

创建索引时,我找不到如何使用这些映射

1 个答案:

答案 0 :(得分:0)

根据我的经验,Elasticsearch for hadoop还为您创建了一个带有关键字类型的 .keyword

尝试使用country.keyword