# Java API to get a mapping

**URL:** <https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482>\
**Category:** Elasticsearch\
**Created:** [May 26, 2011, 11:33am UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482 "2011-05-26T11:33:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [May 26, 2011, 11:33am UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482/1 "2011-05-26T11:33:13Z")

</div>

I don't find any Java API to get a mapping for an index. Did I missed something or it is just not implemented yet ?

If just not implemented, I can try to take care of implementing it and provide a patch.

Nicolas

---

<div class="post-metadata">

**Author:** ![plaflamme](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@plaflamme](https://discuss.elastic.co/u/plaflamme)\
**Post date:** [May 26, 2011, 1:16pm UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482/2 "2011-05-26T13:16:11Z")

</div>

Yeah, I had a hard time finding it also. You need to fetch the ClusterState,  
then get the IndexMetaData then you get your mapping from one of its  
mappings() methods.

To get "myType" mapping from the "myIndex" index:

ClusterState cs =  
client.admin().cluster().prepareState().setFilterIndices("myIndex").execute().actionGet().getState();  
IndexMetaData imd = cs.getMetaData().index("myIndex")  
MappingMetaData mdd = imd.mapping("myType")

Philippe

2011/5/26 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)

> I don't find any Java API to get a mapping for an index. Did I missed  
> something or it is just not implemented yet ?
> 
> If just not implemented, I can try to take care of implementing it and  
> provide a patch.
> 
> Nicolas

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [May 26, 2011, 1:22pm UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482/3 "2011-05-26T13:22:09Z")

</div>

Le 26 mai 2011 à 15:16, Philippe Laflamme a écrit :

> Yeah, I had a hard time finding it also. You need to fetch the ClusterState, then get the IndexMetaData then you get your mapping from one of its mappings() methods.
> 
> To get "myType" mapping from the "myIndex" index:
> 
> ClusterState cs = client.admin().cluster().prepareState().setFilterIndices("myIndex").execute().actionGet().getState();  
> IndexMetaData imd = cs.getMetaData().index("myIndex")  
> MappingMetaData mdd = imd.mapping("myType")

ha great thanks !

Nicolas

---

<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:** [May 26, 2011, 2:11pm UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482/4 "2011-05-26T14:11:12Z")

</div>

Here is a sample of how it is done in the REST GET mapping endpoint: [https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java](https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java)

On Thursday, May 26, 2011 at 4:22 PM, Nicolas Lalevée wrote:

> Le 26 mai 2011 à 15:16, Philippe Laflamme a écrit :
> 
> > Yeah, I had a hard time finding it also. You need to fetch the ClusterState, then get the IndexMetaData then you get your mapping from one of its mappings() methods.
> > 
> > To get "myType" mapping from the "myIndex" index:
> > 
> > ClusterState cs = client.admin().cluster().prepareState().setFilterIndices("myIndex").execute().actionGet().getState();  
> > IndexMetaData imd = cs.getMetaData().index("myIndex")  
> > MappingMetaData mdd = imd.mapping("myType")
> 
> ha great thanks !
> 
> Nicolas

---

<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, 4:05am UTC](https://discuss.elastic.co/t/java-api-to-get-a-mapping/4482/5 "2017-07-06T04:05:15Z")

</div>


