Index Json with elasticsearch

{
        "_index" : "test_24_05",
        "_type" : "churn",
        "_id" : "8unq42oBKem4LGb_TnHI",
        "_score" : 1.0,
        "_source" : {
          "value" : "{\"label\":1.0,\"prediction\":1.0,\"probability\":{\"type\":1,\"values\":[0.1,0.9]}}"
        }
      },
      {
        "_index" : "test_24_05",
        "_type" : "churn",
        "_id" : "9unq42oBKem4LGb_TnHI",
        "_score" : 1.0,
        "_source" : {
          "value" : "{\"label\":1.0,\"prediction\":1.0,\"probability\":{\"type\":1,\"values\":[0.12578616352201258,0.8742138364779874]}}"
        }
      },

Hello
Is there a way to save the following Json with Json using scala , i want to insert "value" to elastcisearch :roll_eyes:
my scala code :

val resulttoDF = result.toDF("label", "prediction", "probability").toJSON
resulttoDF.saveToEs("test_24_05/ch")

hi all,
the solution is to extract value form Json object using from_json
i'm working with spark scala just i add this line

`.withColumn("label", from_json($"value", result.schema)("label"))

and i face others problems like playing aroud vector type so i just add this line

.withColumn("probability", getItem(from_json($"value", result.schema)("probability"), lit(0)))

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.