elasticsearch-hadoop

Spark Scala - How to construct Scala Map from nested JSON?

北城以北 提交于 2019-12-02 19:07:28
问题 I've a nested json data with nested fields that I want to extract and construct a Scala Map. Heres the sample JSON: "nested_field": [ { "airport": "sfo", "score": 1.0 }, { "airport": "phx", "score": 1.0 }, { "airport": "sjc", "score": 1.0 } ] I want to use saveToES() and construct a Scala Map to index the field into ES index with mapping as below: "nested_field": { "properties": { "score": { "type": "double" }, "airport": { "type": "keyword", "ignore_above": 1024 } } } The json file is read

Spark Scala - How to construct Scala Map from nested JSON?

醉酒当歌 提交于 2019-12-02 08:25:29
I've a nested json data with nested fields that I want to extract and construct a Scala Map. Heres the sample JSON: "nested_field": [ { "airport": "sfo", "score": 1.0 }, { "airport": "phx", "score": 1.0 }, { "airport": "sjc", "score": 1.0 } ] I want to use saveToES() and construct a Scala Map to index the field into ES index with mapping as below: "nested_field": { "properties": { "score": { "type": "double" }, "airport": { "type": "keyword", "ignore_above": 1024 } } } The json file is read into the dataframe using spark.read.json("example.json"). Whats the right way to construct the Scala Map

Save Spark Dataframe into Elasticsearch - Can’t handle type exception

家住魔仙堡 提交于 2019-11-27 05:12:55
I have designed a simple job to read data from MySQL and save it in Elasticsearch with Spark. Here is the code: JavaSparkContext sc = new JavaSparkContext( new SparkConf().setAppName("MySQLtoEs") .set("es.index.auto.create", "true") .set("es.nodes", "127.0.0.1:9200") .set("es.mapping.id", "id") .set("spark.serializer", KryoSerializer.class.getName())); SQLContext sqlContext = new SQLContext(sc); // Data source options Map<String, String> options = new HashMap<>(); options.put("driver", MYSQL_DRIVER); options.put("url", MYSQL_CONNECTION_URL); options.put("dbtable", "OFFERS"); options.put(