# How Do You Get The List of Fields For An Index?

**URL:** <https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277>\
**Category:** Elasticsearch\
**Created:** [April 9, 2012, 7:13pm UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277 "2012-04-09T19:13:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Brown\_VSTI](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@Ed\_Brown\_VSTI](https://discuss.elastic.co/u/Ed_Brown_VSTI)\
**Post date:** [April 9, 2012, 7:13pm UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/1 "2012-04-09T19:13:56Z")

</div>

How do you query and index for the list of fields in the index?

Thanks.

* * *

Ed Brown

---

<div class="post-metadata">

**Author:** ![Ed\_Brown\_VSTI](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@Ed\_Brown\_VSTI](https://discuss.elastic.co/u/Ed_Brown_VSTI)\
**Post date:** [April 9, 2012, 7:23pm UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/2 "2012-04-09T19:23:24Z")

</div>

Using the Java API?

On Monday, April 9, 2012 3:13:56 PM UTC-4, Ed Brown VSTI wrote:

> How do you query and index for the list of fields in the index?
> 
> Thanks.
> 
> * * *
> 
> Ed Brown

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 10, 2012, 10:46pm UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/3 "2012-04-10T22:46:51Z")

</div>

// Get cluster state  
ClusterState clusterState =  
client1.admin().cluster().prepareState().execute().actionGet().state();

// Get mapping from the cluster state  
MappingMetaData mappingMetaData =  
clusterState.metaData().index("my\_index").mappings().get("my\_type");

// Get the list of fields from the mapping  
Map\<String, Object\> fields = (Map\<String, Object\>)  
mappingMetaData.sourceAsMap().get("properties");

On Monday, April 9, 2012 3:23:24 PM UTC-4, Ed Brown VSTI wrote:

> Using the Java API?
> 
> On Monday, April 9, 2012 3:13:56 PM UTC-4, Ed Brown VSTI wrote:
> 
> > How do you query and index for the list of fields in the index?
> > 
> > Thanks.
> > 
> > * * *
> > 
> > Ed Brown

---

<div class="post-metadata">

**Author:** ![Ed\_Brown\_VSTI](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@Ed\_Brown\_VSTI](https://discuss.elastic.co/u/Ed_Brown_VSTI)\
**Post date:** [April 11, 2012, 2:57am UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/4 "2012-04-11T02:57:50Z")

</div>

Thanks!

On Tuesday, April 10, 2012 6:46:51 PM UTC-4, Igor Motov wrote:

> // Get cluster state  
> ClusterState clusterState =  
> client1.admin().cluster().prepareState().execute().actionGet().state();
> 
> // Get mapping from the cluster state  
> MappingMetaData mappingMetaData =  
> clusterState.metaData().index("my\_index").mappings().get("my\_type");
> 
> // Get the list of fields from the mapping  
> Map\<String, Object\> fields = (Map\<String, Object\>)  
> mappingMetaData.sourceAsMap().get("properties");
> 
> On Monday, April 9, 2012 3:23:24 PM UTC-4, Ed Brown VSTI wrote:
> 
> > Using the Java API?
> > 
> > On Monday, April 9, 2012 3:13:56 PM UTC-4, Ed Brown VSTI wrote:
> > 
> > > How do you query and index for the list of fields in the index?
> > > 
> > > Thanks.
> > > 
> > > * * *
> > > 
> > > Ed Brown

---

<div class="post-metadata">

**Author:** ![Kunal\_Parmar](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@Kunal\_Parmar](https://discuss.elastic.co/u/Kunal_Parmar)\
**Post date:** [December 11, 2012, 2:27pm UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/5 "2012-12-11T14:27:27Z")

</div>

This was really helpful. Thanks. 🙂

On Wednesday, 11 April 2012 04:16:51 UTC+5:30, Igor Motov wrote:

> // Get cluster state  
> ClusterState clusterState =  
> client1.admin().cluster().prepareState().execute().actionGet().state();
> 
> // Get mapping from the cluster state  
> MappingMetaData mappingMetaData =  
> clusterState.metaData().index("my\_index").mappings().get("my\_type");
> 
> // Get the list of fields from the mapping  
> Map\<String, Object\> fields = (Map\<String, Object\>)  
> mappingMetaData.sourceAsMap().get("properties");
> 
> On Monday, April 9, 2012 3:23:24 PM UTC-4, Ed Brown VSTI wrote:
> 
> > Using the Java API?
> > 
> > On Monday, April 9, 2012 3:13:56 PM UTC-4, Ed Brown VSTI wrote:
> > 
> > > How do you query and index for the list of fields in the index?
> > > 
> > > Thanks.
> > > 
> > > * * *
> > > 
> > > Ed Brown

--

---

<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:00am UTC](https://discuss.elastic.co/t/how-do-you-get-the-list-of-fields-for-an-index/7277/6 "2017-07-06T03:00:18Z")

</div>


