# Correct Mapping into ElasticSearch for JSON

**URL:** https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871
**Category:** Elasticsearch
**Created:** [July 20, 2015, 6:18am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871 "2015-07-20T06:18:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Aditya\_Patel](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@Aditya\_Patel](https://discuss.elastic.co/u/Aditya_Patel)
#### Post date: [July 20, 2015, 6:18am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/1 "2015-07-20T06:18:02Z")

</div>

Hi Guys,

I am pretty new to elasticsearch and was trying to get data from a postgres database to elasticsearch. I have currently used the following link to get data:

> **[jprante/elasticsearch-jdbc](https://github.com/jprante/elasticsearch-jdbc)**
>
> elasticsearch-jdbc - JDBC importer for Elasticsearch

The issue, i am facing is the mapping of the incoming data. As mapping is done default and it uses the first element of the input. My JSON obecjt from postgres is being recognised as a string .  
eg.

"field": "{"max"=\>28, "min"=\>18, "custom"=\>[{"id"=\>"6017279726270", "name"=\>"Product\_Viewers\_30"}], "ana1"=\>[2], "an2"=\>{"ana21"=\>["GA"], "an3"=\>["home"]}, "types"=\>["elastic"]}"

This is a JSON object in postgres. Can anyone let me know, how to go about it.

Thanks !

---

<div class="post-metadata">

### Author: ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)
#### Post date: [July 20, 2015, 6:26am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/2 "2015-07-20T06:26:42Z")

</div>

Two things come to mind.

The JSON object you describe has escaped quotes. Therefore it is not a JSON object. Maybe you should unescape those quotes.

Does the JDBC importer recognizes the JSON-object as a JSON-object? Or is it just any other value?

---

<div class="post-metadata">

### Author: ![Aditya\_Patel](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@Aditya\_Patel](https://discuss.elastic.co/u/Aditya_Patel)
#### Post date: [July 20, 2015, 7:00am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/3 "2015-07-20T07:00:46Z")

</div>

Hi

Thanks for the reply!

I think its just taking it as a string , so elasticsearch itself assumes it to be a string as well. I was thinking, can we save mapping in a way that the string can be stripped and get converted into a json object. My final goal is to essentially use the fields such as (max and min) and plot data via kibana

---

<div class="post-metadata">

### Author: ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)
#### Post date: [July 20, 2015, 10:18am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/4 "2015-07-20T10:18:14Z")

</div>

You could look into the document field type to use in your mapping.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-object-type.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-object-type.html)

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [July 20, 2015, 11:14am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/5 "2015-07-20T11:14:17Z")

</div>

The JDBC importer can not recognize the JSON automatically und decided to proceed with a string. To be valid ES document JSON, it must have embracing `{` and `}`. You can tweak your SQL statement with string concatenation to achieve this.

---

<div class="post-metadata">

### Author: ![Aditya\_Patel](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@Aditya\_Patel](https://discuss.elastic.co/u/Aditya_Patel)
#### Post date: [July 20, 2015, 5:23pm UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/6 "2015-07-20T17:23:58Z")

</div>

Hi

Thanks for the reply !  
Currently i went ahead with a python script. Not sure about the sql statement though.

---

<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 6, 2017, 12:00am UTC](https://discuss.elastic.co/t/correct-mapping-into-elasticsearch-for-json/25871/7 "2017-07-06T00:00:20Z")

</div>


