# CreateIndexRequestBuilder and mappings from JSON (Java)

**URL:** <https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590>\
**Category:** Elasticsearch\
**Created:** [October 13, 2011, 2:39pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590 "2011-10-13T14:39:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremie\_BORDIER1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeremie_bordier1/32/2860_2.png) [@Jeremie\_BORDIER1](https://discuss.elastic.co/u/Jeremie_BORDIER1)\
**Post date:** [October 13, 2011, 2:39pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/1 "2011-10-13T14:39:26Z")

</div>

Hi,

I would like to create my indexes from a template stored in a JSON  
file using the CreateIndexRequestBuilder class (Java).

Unfortunately, it seems that the CreateIndexRequestBuilder object  
misses a method .source() and is also inconsistent in its members:  
setSettings(source) exists but setMappings(source) does not.

Is there any reason for that or I am missing something ?

Thanks,  
Jérémie

---

<div class="post-metadata">

**Author:** ![Jeremie\_BORDIER1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeremie_bordier1/32/2860_2.png) [@Jeremie\_BORDIER1](https://discuss.elastic.co/u/Jeremie_BORDIER1)\
**Post date:** [October 13, 2011, 7:49pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/2 "2011-10-13T19:49:08Z")

</div>

On Thu, Oct 13, 2011 at 4:39 PM, Jérémie BORDIER  
[jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com) wrote:

> Hi,
> 
> I would like to create my indexes from a template stored in a JSON  
> file using the CreateIndexRequestBuilder class (Java).
> 
> Unfortunately, it seems that the CreateIndexRequestBuilder object  
> misses a method .source() and is also inconsistent in its members:  
> setSettings(source) exists but setMappings(source) does not.
> 
> Is there any reason for that or I am missing something ?
> 
> Thanks,  
> Jérémie

Additionally, it does not seem to be able to configure Aliases  
directly through this call, whereas it is possible through the JSON +  
HTTP API.

If anybody has an hint, I'm really struggling with this 🙂

Jérémie

---

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [October 13, 2011, 7:52pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/3 "2011-10-13T19:52:07Z")

</div>

To add mapping you can use CreateIndexRequestBuilder#addMapping(String type,  
String mapping)

Regards,  
Alexandr Vasilenko

2011/10/13 Jérémie BORDIER [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com)

> On Thu, Oct 13, 2011 at 4:39 PM, Jérémie BORDIER  
> [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com) wrote:
> 
> > Hi,
> > 
> > I would like to create my indexes from a template stored in a JSON  
> > file using the CreateIndexRequestBuilder class (Java).
> > 
> > Unfortunately, it seems that the CreateIndexRequestBuilder object  
> > misses a method .source() and is also inconsistent in its members:  
> > setSettings(source) exists but setMappings(source) does not.
> > 
> > Is there any reason for that or I am missing something ?
> > 
> > Thanks,  
> > Jérémie
> 
> Additionally, it does not seem to be able to configure Aliases  
> directly through this call, whereas it is possible through the JSON +  
> HTTP API.
> 
> If anybody has an hint, I'm really struggling with this 🙂
> 
> Jérémie

---

<div class="post-metadata">

**Author:** ![Jeremie\_BORDIER1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeremie_bordier1/32/2860_2.png) [@Jeremie\_BORDIER1](https://discuss.elastic.co/u/Jeremie_BORDIER1)\
**Post date:** [October 13, 2011, 7:57pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/4 "2011-10-13T19:57:10Z")

</div>

Hello Alexandr,

Thanks for your answer, unfortunately my original question was how to  
fill a CreateIndexRequest using a JSON string, just as you can do an  
IndexRequest#source(String json).

Jérémie

On Thu, Oct 13, 2011 at 9:52 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com) wrote:

> To add mapping you can use CreateIndexRequestBuilder#addMapping(String type,  
> String mapping)
> 
> Regards,  
> Alexandr Vasilenko
> 
> 2011/10/13 Jérémie BORDIER [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com)
> 
> > On Thu, Oct 13, 2011 at 4:39 PM, Jérémie BORDIER  
> > [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I would like to create my indexes from a template stored in a JSON  
> > > file using the CreateIndexRequestBuilder class (Java).
> > > 
> > > Unfortunately, it seems that the CreateIndexRequestBuilder object  
> > > misses a method .source() and is also inconsistent in its members:  
> > > setSettings(source) exists but setMappings(source) does not.
> > > 
> > > Is there any reason for that or I am missing something ?
> > > 
> > > Thanks,  
> > > Jérémie
> > 
> > Additionally, it does not seem to be able to configure Aliases  
> > directly through this call, whereas it is possible through the JSON +  
> > HTTP API.
> > 
> > If anybody has an hint, I'm really struggling with this 🙂
> > 
> > Jérémie

--  
Jérémie 'ahFeel' BORDIER

---

<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:** [October 14, 2011, 1:18pm UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/5 "2011-10-14T13:18:55Z")

</div>

CreateIndexRequestBuilder has a method called addMapping(String type, String  
source), you can use that one to add a mapping defined in json as a String.  
Is that what you are after?

On Thu, Oct 13, 2011 at 9:57 PM, Jérémie BORDIER  
[jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com)wrote:

> Hello Alexandr,
> 
> Thanks for your answer, unfortunately my original question was how to  
> fill a CreateIndexRequest using a JSON string, just as you can do an  
> IndexRequest#source(String json).
> 
> Jérémie
> 
> On Thu, Oct 13, 2011 at 9:52 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)  
> wrote:
> 
> > To add mapping you can use CreateIndexRequestBuilder#addMapping(String  
> > type,  
> > String mapping)
> > 
> > Regards,  
> > Alexandr Vasilenko
> > 
> > 2011/10/13 Jérémie BORDIER [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com)
> > 
> > > On Thu, Oct 13, 2011 at 4:39 PM, Jérémie BORDIER  
> > > [jeremie.bordier@gmail.com](mailto:jeremie.bordier@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I would like to create my indexes from a template stored in a JSON  
> > > > file using the CreateIndexRequestBuilder class (Java).
> > > > 
> > > > Unfortunately, it seems that the CreateIndexRequestBuilder object  
> > > > misses a method .source() and is also inconsistent in its members:  
> > > > setSettings(source) exists but setMappings(source) does not.
> > > > 
> > > > Is there any reason for that or I am missing something ?
> > > > 
> > > > Thanks,  
> > > > Jérémie
> > > 
> > > Additionally, it does not seem to be able to configure Aliases  
> > > directly through this call, whereas it is possible through the JSON +  
> > > HTTP API.
> > > 
> > > If anybody has an hint, I'm really struggling with this 🙂
> > > 
> > > Jérémie
> 
> --  
> Jérémie 'ahFeel' BORDIER

---

<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:51am UTC](https://discuss.elastic.co/t/createindexrequestbuilder-and-mappings-from-json-java/5590/6 "2017-07-06T03:51:56Z")

</div>


