elasticsearch学习笔记

本文介绍了解决Elasticsearch在写入数据时遇到的异常情况,包括配置synonym.txt文件来避免错误,以及如何通过调整Spark配置来实现更灵活的数据写入操作。

1.Caused by: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Cannot determine write shards for

config/analysis下创建 synonym.txt文件即可


The index operation automatically creates an index if it has not been created before (check out thecreate index API for manually creating an index), and also automatically creates a dynamic type mapping for the specific type if one has not yet been created (check out the put mapping API for manually creating a type mapping)

es 会自动创建index和type如果不存在的话


2.

//利用隐式转换,native的支持

  implicit class ESConfig(conf: SparkConf) {

    def build(index: String, typeTable: String, mapId: Option[String] = None): SparkConf = {
      val sc = conf
        //        .set("spark.buffer.pageSize", "8m")
        .set("es.nodes", config.nodes)
        .set("es.port", config.port)
        .set("es.scroll.size", "2000")
        .set("es.resource", s"$index/$typeTable")
        .set("es.index.auto.create", "true")
        .set("es.write.operation", "upsert")
        .set("es.batch.size.entries", config.batchSize)
      mapId match {
        case Some(id) => sc.set("es.mapping.id", id)
        case None => sc
      }
    }


  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值