# PutMappingRequestBuilder

**URL:** <https://discuss.elastic.co/t/putmappingrequestbuilder/5844>\
**Category:** Elasticsearch\
**Created:** [November 11, 2011, 3:30pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844 "2011-11-11T15:30:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronak\_Patel](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ronak\_Patel](https://discuss.elastic.co/u/Ronak_Patel)\
**Post date:** [November 11, 2011, 3:30pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/1 "2011-11-11T15:30:41Z")

</div>

Hello,

I'm trying to register a GeoPoint type with an embedded ElasticSearch  
node and am wondering what the correct API usage is.

I understand I have to use the PutMappingRequestBuilder...but what do  
I use for the source Map? It lacks generics and as such, I'm confused  
what I should add there.

final PutMappingRequestBuilder mappingRequestBuilder = new  
PutMappingRequestBuilder(this.searchService.admin().indices());

Thanks,

Ronak Patel

---

<div class="post-metadata">

**Author:** ![Mauricio\_Alarcon](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mauricio\_Alarcon](https://discuss.elastic.co/u/Mauricio_Alarcon)\
**Post date:** [November 11, 2011, 6:58pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/2 "2011-11-11T18:58:06Z")

</div>

Why don't you use the provided  
org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
and build the json source mapping based on

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Take a look to  
[https://github.com/elasticsearch/elasticsearch/blob/master/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/geo/GeoDistanceTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/geo/GeoDistanceTests.java)

lines 67-70

I'm doing via

client.admin()  
.indices()  
.putMapping(Requests.putMappingRequest(indexName)  
.source(mappingSource)  
.type(type)

On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:

> Hello,
> 
> I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> node and am wondering what the correct API usage is.
> 
> I understand I have to use the PutMappingRequestBuilder...but what do  
> I use for the source Map? It lacks generics and as such, I'm confused  
> what I should add there.
> 
> final PutMappingRequestBuilder mappingRequestBuilder = new  
> PutMappingRequestBuilder(this.searchService.admin().indices());
> 
> Thanks,
> 
> Ronak Patel

---

<div class="post-metadata">

**Author:** ![Ronak\_Patel](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ronak\_Patel](https://discuss.elastic.co/u/Ronak_Patel)\
**Post date:** [November 11, 2011, 7:55pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/3 "2011-11-11T19:55:27Z")

</div>

So that means this API should not be used?  
I would rather not have to deal with building JSON and let the API do  
it.  
This hides any changes to the Elasticsearch low level protocol away  
from my code.

On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:

> Why don't you use the provided  
> org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> and build the json source mapping based on
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma)...
> 
> Take a look tohttps://github.com/elasticsearch/elasticsearch/blob/master/modules/te...
> 
> lines 67-70
> 
> I'm doing via
> 
> client.admin()  
> .indices()  
> .putMapping(Requests.putMappingRequest(indexName)  
> .source(mappingSource)  
> .type(type)
> 
> On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > Hello,
> 
> > I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> > node and am wondering what the correct API usage is.
> 
> > I understand I have to use the PutMappingRequestBuilder...but what do  
> > I use for the source Map? It lacks generics and as such, I'm confused  
> > what I should add there.
> 
> > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > PutMappingRequestBuilder(this.searchService.admin().indices());
> 
> > Thanks,
> 
> > Ronak Patel

---

<div class="post-metadata">

**Author:** ![Mauricio\_Alarcon](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mauricio\_Alarcon](https://discuss.elastic.co/u/Mauricio_Alarcon)\
**Post date:** [November 11, 2011, 10:11pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/4 "2011-11-11T22:11:18Z")

</div>

As far as I know this is the only way to set the mapping for an index,  
is not that you're writing json on your own but instead using the java  
API provided to do it.

Anybody wants to add her/his two cents here?

~M

On Nov 11, 2:55 pm, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:

> So that means this API should not be used?  
> I would rather not have to deal with building JSON and let the API do  
> it.  
> This hides any changes to the Elasticsearch low level protocol away  
> from my code.
> 
> On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> 
> > Why don't you use the provided  
> > org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> > and build the json source mapping based on
> 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma)...
> 
> > Take a look tohttps://github.com/elasticsearch/elasticsearch/blob/master/modules/te...
> 
> > lines 67-70
> 
> > I'm doing via
> 
> > client.admin()  
> > .indices()  
> > .putMapping(Requests.putMappingRequest(indexName)  
> > .source(mappingSource)  
> > .type(type)
> 
> > On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > > Hello,
> 
> > > I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> > > node and am wondering what the correct API usage is.
> 
> > > I understand I have to use the PutMappingRequestBuilder...but what do  
> > > I use for the source Map? It lacks generics and as such, I'm confused  
> > > what I should add there.
> 
> > > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > > PutMappingRequestBuilder(this.searchService.admin().indices());
> 
> > > Thanks,
> 
> > > Ronak Patel

---

<div class="post-metadata">

**Author:** ![Ronak\_Patel](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ronak\_Patel](https://discuss.elastic.co/u/Ronak_Patel)\
**Post date:** [November 12, 2011, 2:09pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/5 "2011-11-12T14:09:50Z")

</div>

Some other questions related to the Java API:

Using the Java API, what is the preferred way to index a GeoPoint?

Is this not valid?

final Map\<String, Object\> sourceMap = new HashMap\<String, Object\>();  
sourceMap.put("coordinate", new GeoPoint(event.getLatitudeDeg(),  
event.getLongitudeDeg()));

On Nov 11, 5:11 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:

> As far as I know this is the only way to set the mapping for an index,  
> is not that you're writing json on your own but instead using the java  
> API provided to do it.
> 
> Anybody wants to add her/his two cents here?
> 
> ~M
> 
> On Nov 11, 2:55 pm, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > So that means this API should not be used?  
> > I would rather not have to deal with building JSON and let the API do  
> > it.  
> > This hides any changes to the Elasticsearch low level protocol away  
> > from my code.
> 
> > On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> 
> > > Why don't you use the provided  
> > > org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> > > and build the json source mapping based on
> 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma)...
> 
> > > Take a look tohttps://github.com/elasticsearch/elasticsearch/blob/master/modules/te...
> 
> > > lines 67-70
> 
> > > I'm doing via
> 
> > > client.admin()  
> > > .indices()  
> > > .putMapping(Requests.putMappingRequest(indexName)  
> > > .source(mappingSource)  
> > > .type(type)
> 
> > > On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > > > Hello,
> 
> > > > I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> > > > node and am wondering what the correct API usage is.
> 
> > > > I understand I have to use the PutMappingRequestBuilder...but what do  
> > > > I use for the source Map? It lacks generics and as such, I'm confused  
> > > > what I should add there.
> 
> > > > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > > > PutMappingRequestBuilder(this.searchService.admin().indices());
> 
> > > > Thanks,
> 
> > > > Ronak Patel

---

<div class="post-metadata">

**Author:** ![Ronak\_Patel](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ronak\_Patel](https://discuss.elastic.co/u/Ronak_Patel)\
**Post date:** [November 12, 2011, 2:49pm UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/6 "2011-11-12T14:49:16Z")

</div>

Same goes for Dates. What is the preferred way to get dates into and  
out of the Elasticsearch API.  
I don't imagine having to use the SimpleDateFormat from java.text do  
I?

On Nov 12, 9:09 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:

> Some other questions related to the Java API:
> 
> Using the Java API, what is the preferred way to index a GeoPoint?
> 
> Is this not valid?
> 
> final Map\<String, Object\> sourceMap = new HashMap\<String, Object\>();  
> sourceMap.put("coordinate", new GeoPoint(event.getLatitudeDeg(),  
> event.getLongitudeDeg()));
> 
> On Nov 11, 5:11 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> 
> > As far as I know this is the only way to set the mapping for an index,  
> > is not that you're writing json on your own but instead using the java  
> > API provided to do it.
> 
> > Anybody wants to add her/his two cents here?
> 
> > ~M
> 
> > On Nov 11, 2:55 pm, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > > So that means this API should not be used?  
> > > I would rather not have to deal with building JSON and let the API do  
> > > it.  
> > > This hides any changes to the Elasticsearch low level protocol away  
> > > from my code.
> 
> > > On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> 
> > > > Why don't you use the provided  
> > > > org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> > > > and build the json source mapping based on
> 
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma)...
> 
> > > > Take a look tohttps://github.com/elasticsearch/elasticsearch/blob/master/modules/te...
> 
> > > > lines 67-70
> 
> > > > I'm doing via
> 
> > > > client.admin()  
> > > > .indices()  
> > > > .putMapping(Requests.putMappingRequest(indexName)  
> > > > .source(mappingSource)  
> > > > .type(type)
> 
> > > > On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > > > > Hello,
> 
> > > > > I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> > > > > node and am wondering what the correct API usage is.
> 
> > > > > I understand I have to use the PutMappingRequestBuilder...but what do  
> > > > > I use for the source Map? It lacks generics and as such, I'm confused  
> > > > > what I should add there.
> 
> > > > > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > > > > PutMappingRequestBuilder(this.searchService.admin().indices());
> 
> > > > > Thanks,
> 
> > > > > Ronak Patel

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 13, 2011, 8:55am UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/7 "2011-11-13T08:55:10Z")

</div>

Yes, mappings can only be provided using their json representation, which  
you can build however you want (read it from a file, build it using  
your favorite json lib, or use elasticsearch XContent).

On Sat, Nov 12, 2011 at 12:11 AM, maverick [mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com)wrote:

> As far as I know this is the only way to set the mapping for an index,  
> is not that you're writing json on your own but instead using the java  
> API provided to do it.
> 
> Anybody wants to add her/his two cents here?
> 
> ~M
> 
> On Nov 11, 2:55 pm, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> 
> > So that means this API should not be used?  
> > I would rather not have to deal with building JSON and let the API do  
> > it.  
> > This hides any changes to the Elasticsearch low level protocol away  
> > from my code.
> > 
> > On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> > 
> > > Why don't you use the provided  
> > > org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> > > and build the json source mapping based on
> > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma).  
> > > ..
> > 
> > > Take a look tohttps://  
> > > [github.com/elasticsearch/elasticsearch/blob/master/modules/te](http://github.com/elasticsearch/elasticsearch/blob/master/modules/te)...
> > 
> > > lines 67-70
> > 
> > > I'm doing via
> > 
> > > client.admin()  
> > > .indices()
> 
> .putMapping(Requests.putMappingRequest(indexName)
> 
> > > ```
> > > .source(mappingSource)
> > > .type(type)
> > > 
> > > ```
> > 
> > > On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> > 
> > > > Hello,
> > 
> > > > I'm trying to register a GeoPoint type with an embedded Elasticsearch  
> > > > node and am wondering what the correct API usage is.
> > 
> > > > I understand I have to use the PutMappingRequestBuilder...but what do  
> > > > I use for the source Map? It lacks generics and as such, I'm confused  
> > > > what I should add there.
> > 
> > > > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > > > PutMappingRequestBuilder(this.searchService.admin().indices());
> > 
> > > > Thanks,
> > 
> > > > Ronak Patel

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 13, 2011, 8:56am UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/8 "2011-11-13T08:56:03Z")

</div>

GeoPoint will not help, its an internal class used in ES, not meant to  
construct points to be indexed. Just build the structure you want to index  
that maps to the document.

On Sat, Nov 12, 2011 at 4:09 PM, Ronak Patel [ronak2121@gmail.com](mailto:ronak2121@gmail.com) wrote:

> Some other questions related to the Java API:
> 
> Using the Java API, what is the preferred way to index a GeoPoint?
> 
> Is this not valid?
> 
> final Map\<String, Object\> sourceMap = new HashMap\<String, Object\>();  
> sourceMap.put("coordinate", new  
> GeoPoint(event.getLatitudeDeg(),  
> event.getLongitudeDeg()));
> 
> On Nov 11, 5:11 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> 
> > As far as I know this is the only way to set the mapping for an index,  
> > is not that you're writing json on your own but instead using the java  
> > API provided to do it.
> > 
> > Anybody wants to add her/his two cents here?
> > 
> > ~M
> > 
> > On Nov 11, 2:55 pm, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> > 
> > > So that means this API should not be used?  
> > > I would rather not have to deal with building JSON and let the API do  
> > > it.  
> > > This hides any changes to the Elasticsearch low level protocol away  
> > > from my code.
> > 
> > > On Nov 11, 1:58 pm, maverick [mauricio.alar...@gmail.com](mailto:mauricio.alar...@gmail.com) wrote:
> > 
> > > > Why don't you use the provided  
> > > > org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder() class  
> > > > and build the json source mapping based on
> > 
> > > >
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-ma)...
> 
> > > > Take a look tohttps://  
> > > > [github.com/elasticsearch/elasticsearch/blob/master/modules/te](http://github.com/elasticsearch/elasticsearch/blob/master/modules/te)...
> > 
> > > > lines 67-70
> > 
> > > > I'm doing via
> > 
> > > > client.admin()  
> > > > .indices()
> 
> .putMapping(Requests.putMappingRequest(indexName)
> 
> > > >
> 
> .source(mappingSource)
> 
> > > > ```
> > > > .type(type)
> > > > 
> > > > ```
> > 
> > > > On Nov 11, 10:30 am, Ronak Patel [ronak2...@gmail.com](mailto:ronak2...@gmail.com) wrote:
> > 
> > > > > Hello,
> > 
> > > > > I'm trying to register a GeoPoint type with an embedded  
> > > > > Elasticsearch  
> > > > > node and am wondering what the correct API usage is.
> > 
> > > > > I understand I have to use the PutMappingRequestBuilder...but what  
> > > > > do  
> > > > > I use for the source Map? It lacks generics and as such, I'm  
> > > > > confused  
> > > > > what I should add there.
> > 
> > > > > final PutMappingRequestBuilder mappingRequestBuilder = new  
> > > > > PutMappingRequestBuilder(this.searchService.admin().indices());
> > 
> > > > > Thanks,
> > 
> > > > > Ronak Patel

---

<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, 3:48am UTC](https://discuss.elastic.co/t/putmappingrequestbuilder/5844/9 "2017-07-06T03:48:53Z")

</div>


