# Java API - Create index/mapping examples

**URL:** <https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069>\
**Category:** Elasticsearch\
**Created:** [August 5, 2013, 10:27am UTC](https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069 "2013-08-05T10:27:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim\_siney](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tim\_siney](https://discuss.elastic.co/u/tim_siney)\
**Post date:** [August 5, 2013, 10:27am UTC](https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069/1 "2013-08-05T10:27:00Z")

</div>

Hi,

I'm trying to create an index and mapping using the Java API but I am not  
getting the results I expect. Using the code shown in the gist below  
results in the index being created, but the mapping isn't applied to the  
index:

> <https://gist.github.com/TimSin/6154882>

When I then hit the URL '[http://localhost:9200/testindex/\_mapping](http://localhost:9200/testindex/_mapping)', I see  
the following results:

{"testindex":{"testobject":{"properties":{}}}}

Creating the index/mapping using the REST API directly via curl works. I've tried a few different permutations using the Java API based on various examples on this list without success , so I am at a bit of a loss as to what is going on here. Does anyone have some concrete examples of successfully creating an index/mapping using the Java API?

Thanks!

Tim

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [August 5, 2013, 12:03pm UTC](https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069/2 "2013-08-05T12:03:22Z")

</div>

Hey Tim,

Have a look at: [https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/util/ESHelper.java?source=cc](https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/util/ESHelper.java?source=cc)

I think you could find some info here.

Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 août 2013 à 12:27, tim\_siney@salvationarmy.org a écrit :

Hi,

I'm trying to create an index and mapping using the Java API but I am not getting the results I expect. Using the code shown in the gist below results in the index being created, but the mapping isn't applied to the index:

> <https://gist.github.com/TimSin/6154882>

When I then hit the URL '[http://localhost:9200/testindex/\_mapping](http://localhost:9200/testindex/_mapping)', I see the following results:

{"testindex":{"testobject":{"properties":{}}}}

Creating the index/mapping using the REST API directly via curl works. I've tried a few different permutations using the Java API based on various examples on this list without success , so I am at a bit of a loss as to what is going on here. Does anyone have some concrete examples of successfully creating an index/mapping using the Java API?

Thanks!

## Tim

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![tim\_siney](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tim\_siney](https://discuss.elastic.co/u/tim_siney)\
**Post date:** [August 5, 2013, 3:10pm UTC](https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069/3 "2013-08-05T15:10:44Z")

</div>

Thanks David, that gave me the information I was looking for. For  
reference, I refactored the code in the original email into this:

> <https://gist.github.com/TimSin/6156670>

The problem with my original code was that I was trying to create the index  
and mapping in the same API call. Splitting them into 2 separate calls  
fixed the issue.

On Monday, August 5, 2013 1:03:22 PM UTC+1, David Pilato wrote:

> Hey Tim,
> 
> Have a look at:  
> [https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/util/ESHelper.java?source=cc](https://github.com/scrutmydocs/scrutmydocs/blob/master/src/main/java/org/scrutmydocs/webapp/util/ESHelper.java?source=cc)
> 
> I think you could find some info here.
> 
> Does it help?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 5 août 2013 à 12:27, [tim\_...@salvationarmy.org](mailto:tim_...@salvationarmy.org) \<javascript:\> a écrit :
> 
> Hi,
> 
> I'm trying to create an index and mapping using the Java API but I am not  
> getting the results I expect. Using the code shown in the gist below  
> results in the index being created, but the mapping isn't applied to the  
> index:
> 
> [Elasticsearch Java create mapping · GitHub](https://gist.github.com/TimSin/6154882)
> 
> When I then hit the URL '[http://localhost:9200/testindex/\_mapping](http://localhost:9200/testindex/_mapping)', I see  
> the following results:
> 
> {"testindex":{"testobject":{"properties":{}}}}
> 
> Creating the index/mapping using the REST API directly via curl works. I've tried a few different permutations using the Java API based on various examples on this list without success , so I am at a bit of a loss as to what is going on here. Does anyone have some concrete examples of successfully creating an index/mapping using the Java API?
> 
> Thanks!
> 
> Tim
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:22am UTC](https://discuss.elastic.co/t/java-api-create-index-mapping-examples/13069/4 "2017-07-06T02:22:51Z")

</div>


