# How to put Geo\_type mapping with JsonObject

**URL:** <https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045>\
**Category:** Elasticsearch\
**Created:** [March 6, 2019, 7:57am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045 "2019-03-06T07:57:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 6, 2019, 7:57am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/1 "2019-03-06T07:57:39Z")

</div>

Hi all ,does everyone knows how to use :  
IndexResponse createData(Client client, String jsonObject,  
String index, String type, String id);  
to put Geo\_type and other mappings?  
I used Map resolve this issue,but I also don't know how to save PolygonBuilder to a Object and then Object to json, and then put json to Elasticsearch, if u see this issue, pls tell how to do it.Thank you very much!

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 6, 2019, 2:49pm UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/2 "2019-03-06T14:49:55Z")

</div>

I don't really understand what you are trying to do, could you please try to expand your explanation, maybe adding some pseudo-code with what you are trying to.

---

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 7, 2019, 3:10am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/3 "2019-03-07T03:10:14Z")

</div>

Failed to execute phase [query], all shards failed; shardFailures {[eQoH4XkNTUutOsYZZsTVcA][landsat8][0]: RemoteTransportException[[eQoH4Xk][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: QueryShardException[Field [polygon] is not of type [geo\_shape] but of type [text]];  
kibana shows:  
"polygon" : """  
{  
"type" : "polygon",  
"orientation" : "right",  
"coordinates" : [  
[  
[  
116.45673,  
39.96037  
],  
[  
119.15366,  
39.94163  
],  
[  
119.0907,  
37.82628  
],  
[  
116.47263,  
37.84366  
],  
[  
116.45673,  
39.96037  
]  
]  
]  
}  
""".  
I don't know how to put geo\_type use JavaCode.  
There is two problems:

1. how to put mapping geo\_type from a JsonObject?  
like:

I can use mapping and update to solve this, but I think there is another way.  
2. how to put a geo\_type polygon from a JsonObject?  
If  
"polygon"{  
"type":"geo\_type"  
}  
how can I put a JsonObject to put it?  
example:  
class Location{  
private String polygon;  
}  
or I need to do like this :  
class Location{  
private PolygonBuilder polygon;  
}  
but if like this,I can't do polygon to json.  
😅  
pls tell me how to do this. thank you very much!  
And thank for your patient~

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 7, 2019, 3:48am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/4 "2019-03-07T03:48:46Z")

</div>

You probably did not define a mapping when you indexed your first document.  
So the current mapping contains a `polygon` field with a `text` type.

You need to fix the mapping.

---

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 7, 2019, 8:16am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/5 "2019-03-07T08:16:10Z")

</div>

Can I use JavaCode to define a mapping?  
Or just can define a mapping use kibana?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 7, 2019, 8:46am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/6 "2019-03-07T08:46:20Z")

</div>

Both are possible.  
[https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-create-index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-create-index.html)

---

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 8, 2019, 2:05am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/7 "2019-03-08T02:05:49Z")

</div>

If I define a mapping is not text, Can I use JsonObject to put to ES?  
Thank you for your answer.

---

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 8, 2019, 3:21am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/8 "2019-03-08T03:21:38Z")

</div>

If I have a json like this: `{"extractType":"dsafa","filePath":"123","location":"154"}`,I used `client.prepareIndex(index, type,id) .setSource(json, XContentType.JSON).get()`  
it just can define the type text.If I fix the mapping, I can't put json by this way.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 4:39am UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/9 "2019-03-08T04:39:34Z")

</div>

I don't understand the full picture TBH. Could you share a full example of what you are doing and what the recent problem is?

Don't forget to format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

---

<div class="post-metadata">

**Author:** ![ChenSijia](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@ChenSijia](https://discuss.elastic.co/u/ChenSijia)\
**Post date:** [March 8, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/10 "2019-03-08T15:07:13Z")

</div>

JavaCode:  
`class MTL{  
private String polygon;

```
    private String polygon;

    private String id;
}
MTL mtl = new MTL();
PolygonBuilder polygonBuilder = new PolygonBuilder(coordinate);
mtl.setPolygon(polygonBuilder.toString);
String str = JSON.toJSONString(mtl);
client.prepareIndex(index, type,id)
            .setSource(str, XContentType.JSON).get();

```

`  
I get the mapping is String,not geo\_shape.If I fixed the mapping to geo\_shape,I can't put it to ES.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 4:11pm UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/11 "2019-03-08T16:11:06Z")

</div>

I can't reproduce anything with that. You should share a full demo project on Github.

---

<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:** [April 5, 2019, 4:11pm UTC](https://discuss.elastic.co/t/how-to-put-geo-type-mapping-with-jsonobject/171045/12 "2019-04-05T16:11:08Z")

</div>

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