使用索引模板从Spark向Elasticsearch提取数据

时间:2016-08-30 12:24:20

标签: elasticsearch apache-spark spark-streaming

在我们现有的设计中,我们使用logstash从Kafka(JSON)获取数据并将其放入ElasticSearch。

我们还在将数据从logstash插入ES时使用索引模板映射,这可以通过设置'模板来完成。 logstash的ES输出插件的属性,例如,

output {
  elasticsearch {
    template => "elasticsearch-template.json", //template file path
    hosts => "localhost:9200"
    template_overwrite => true
    manage_template => true
    codec=>plain
   }
}

elasticsearch-template.json如下所示,

{
  "template" : "logstash-*",
   "settings" : {
       "index.refresh_interval" : "3s"
   },
   "mappings" : {
    "_default_" : {
      "_all" : {"enabled" : true},
       "dynamic_templates" : [ {
         "string_fields" : {
           "match" : "*",
           "match_mapping_type" : "string",
           "mapping" : {
             "type" : "string", "index" : "analyzed", "omit_norms" : true,
             "fields" : {
               "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256, "doc_values":true}
              }
           }
        }
       } ],
      "properties" : {
         "@version": { "type": "string", "index": "not_analyzed" },
         "geoip"  : {
            "type" : "object",
            "dynamic": true,
            "properties" : {
               "location" : { "type" : "geo_point" }
            }
          }
       }
      }
    }
  }

现在我们要用Apache Spark替换logstash,我希望在将数据插入ES时在Spark中使用类似的索引模板用法。

我正在使用elasticsearch-spark_2.11库进行此实现。

感谢。

0 个答案:

没有答案