# Using java api to get index types

**URL:** <https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703>\
**Category:** Elasticsearch\
**Created:** [July 8, 2013, 3:05pm UTC](https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703 "2013-07-08T15:05:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![my3sons](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@my3sons](https://discuss.elastic.co/u/my3sons)\
**Post date:** [July 8, 2013, 3:05pm UTC](https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703/1 "2013-07-08T15:05:05Z")

</div>

I have been beating my head against the wall trying to find a way to get  
just the "types" that are associated to a given index. Ultimately, I am  
trying to retrieve the mappings for a given index/type combination. I know  
how to get the mappings from the IndexMetaData object, but it requires that  
I know the types. What I am doing is building an UI to allow users to view  
the mappings for a chosen index and type. However, I cannot find a way to  
just fetch the types for a given index using the java API. From a UI  
perspective, I am trying to do the following:

1. Present list of indices defined in my ES cluster (done)
2. Based on selection from #1, present list of "type(s)" associated to that  
index (???)
3. Present mappings for that index/type combination (done, once I solve #2)

Thanks!

--  
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:** ![imdhmd](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@imdhmd](https://discuss.elastic.co/u/imdhmd)\
**Post date:** [July 8, 2013, 3:18pm UTC](https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703/2 "2013-07-08T15:18:33Z")

</div>

// `client` is an object of `org.elasticsearch.client.Client`  
ClusterStateResponse clusterStateResponse =  
client.admin().cluster().prepareState().execute().actionGet();  
ImmutableMap\<String,MappingMetaData\> indexMappings =  
clusterStateResponse.state().getMetaData().index(indexName).getMappings();  
// The keys in `indexMappings` correspond to type names

On Monday, July 8, 2013 8:35:05 PM UTC+5:30, my3sons wrote:

> I have been beating my head against the wall trying to find a way to get  
> just the "types" that are associated to a given index. Ultimately, I am  
> trying to retrieve the mappings for a given index/type combination. I know  
> how to get the mappings from the IndexMetaData object, but it requires that  
> I know the types. What I am doing is building an UI to allow users to view  
> the mappings for a chosen index and type. However, I cannot find a way to  
> just fetch the types for a given index using the java API. From a UI  
> perspective, I am trying to do the following:
> 
> 1. Present list of indices defined in my ES cluster (done)
> 2. Based on selection from #1, present list of "type(s)" associated to  
> that index (???)
> 3. Present mappings for that index/type combination (done, once I solve #2)
> 
> Thanks!

--  
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:** ![my3sons](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@my3sons](https://discuss.elastic.co/u/my3sons)\
**Post date:** [July 8, 2013, 3:44pm UTC](https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703/3 "2013-07-08T15:44:24Z")

</div>

perfect, thanks Imdad!

On Mon, Jul 8, 2013 at 10:18 AM, Imdad Ahmed [imdhmd@gmail.com](mailto:imdhmd@gmail.com) wrote:

> // `client` is an object of `org.elasticsearch.client.Client`  
> ClusterStateResponse clusterStateResponse =  
> client.admin().cluster().prepareState().execute().actionGet();  
> ImmutableMap\<String,MappingMetaData\> indexMappings =  
> clusterStateResponse.state().getMetaData().index(indexName).getMappings();  
> // The keys in `indexMappings` correspond to type names
> 
> On Monday, July 8, 2013 8:35:05 PM UTC+5:30, my3sons wrote:
> 
> > I have been beating my head against the wall trying to find a way to get  
> > just the "types" that are associated to a given index. Ultimately, I am  
> > trying to retrieve the mappings for a given index/type combination. I know  
> > how to get the mappings from the IndexMetaData object, but it requires that  
> > I know the types. What I am doing is building an UI to allow users to view  
> > the mappings for a chosen index and type. However, I cannot find a way to  
> > just fetch the types for a given index using the java API. From a UI  
> > perspective, I am trying to do the following:
> > 
> > 1. Present list of indices defined in my ES cluster (done)
> > 2. Based on selection from #1, present list of "type(s)" associated to  
> > that index (???)
> > 3. Present mappings for that index/type combination (done, once I solve  
> > #2)
> > 
> > Thanks!
> 
> --  
> 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:** ![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:27am UTC](https://discuss.elastic.co/t/using-java-api-to-get-index-types/12703/4 "2017-07-06T02:27:35Z")

</div>


