# Index Json with elasticsearch

**URL:** <https://discuss.elastic.co/t/index-json-with-elasticsearch/182619>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 10:41am UTC](https://discuss.elastic.co/t/index-json-with-elasticsearch/182619 "2019-05-24T10:41:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barhoumi\_Mohamed\_ali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barhoumi_mohamed_ali/32/46782_2.png) [@Barhoumi\_Mohamed\_ali](https://discuss.elastic.co/u/Barhoumi_Mohamed_ali)\
**Post date:** [May 24, 2019, 10:41am UTC](https://discuss.elastic.co/t/index-json-with-elasticsearch/182619/1 "2019-05-24T10:41:31Z")

</div>

```
{
        "_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 🙄  
my scala code :

val resulttoDF = result.toDF("label", "prediction", "probability").toJSON  
resulttoDF.saveToEs("test\_24\_05/ch")

---

<div class="post-metadata">

**Author:** ![Barhoumi\_Mohamed\_ali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barhoumi_mohamed_ali/32/46782_2.png) [@Barhoumi\_Mohamed\_ali](https://discuss.elastic.co/u/Barhoumi_Mohamed_ali)\
**Post date:** [June 12, 2019, 2:43pm UTC](https://discuss.elastic.co/t/index-json-with-elasticsearch/182619/2 "2019-06-12T14:43:32Z")

</div>

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)))

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 10, 2019, 2:43pm UTC](https://discuss.elastic.co/t/index-json-with-elasticsearch/182619/3 "2019-07-10T14:43:39Z")

</div>

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