# Obtain field names

**URL:** <https://discuss.elastic.co/t/obtain-field-names/7533>\
**Category:** Elasticsearch\
**Created:** [May 2, 2012, 9:11am UTC](https://discuss.elastic.co/t/obtain-field-names/7533 "2012-05-02T09:11:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmz/32/2842_2.png) [@nmz](https://discuss.elastic.co/u/nmz)\
**Post date:** [May 2, 2012, 9:11am UTC](https://discuss.elastic.co/t/obtain-field-names/7533/1 "2012-05-02T09:11:48Z")

</div>

Hi,

Is it possible to obtain the 'field names'[not values] of the indexed  
document using java API in elastic search?

---

<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:** [May 2, 2012, 9:17am UTC](https://discuss.elastic.co/t/obtain-field-names/7533/2 "2012-05-02T09:17:40Z")

</div>

IMHO

You could get the mapping of your document type.  
You can get your document as a Map and find field names as keys

Does it help ?

David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 2 mai 2012 à 11:11, nmz [s.namitha.s@gmail.com](mailto:s.namitha.s@gmail.com) a écrit :

> Hi,
> 
> Is it possible to obtain the 'field names'[not values] of the indexed  
> document using java API in Elasticsearch?

---

<div class="post-metadata">

**Author:** ![nmz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmz/32/2842_2.png) [@nmz](https://discuss.elastic.co/u/nmz)\
**Post date:** [May 2, 2012, 10:45am UTC](https://discuss.elastic.co/t/obtain-field-names/7533/3 "2012-05-02T10:45:55Z")

</div>

Hi,

Thanks for the reply.

I tried the following code:

ClusterState cs =  
client.admin().cluster().prepareState().execute().actionGet().getState();  
IndexMetaData imd = cs.getMetaData().index(INDEX\_NAME);  
MappingMetaData mmd = imd.mapping(DOCUMENT\_NAME);  
Map\<String, Object\> source = mmd.sourceAsMap();

source.keySet() -- only has the value 'properties'  
source.values() -- has the remaining part of the document mapping.

So do I have to parse the values() and extract the 'field names' or is  
there any other way to obtain the it.

Correct me if my approach is wrong.

On May 2, 2:17 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> IMHO
> 
> You could get the mapping of your document type.  
> You can get your document as a Map and find field names as keys
> 
> Does it help ?
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr
> 
> Le 2 mai 2012 à 11:11, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) a écrit :
> 
> > Hi,
> 
> > Is it possible to obtain the 'field names'[not values] of the indexed  
> > document using java API in Elasticsearch?

---

<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 2, 2012, 4:42pm UTC](https://discuss.elastic.co/t/obtain-field-names/7533/4 "2012-05-02T16:42:52Z")

</div>

You will need to navigate through the map, or parse the source (using  
jackson for example) in order to aggregate all the field names.

On Wed, May 2, 2012 at 1:45 PM, nmz [s.namitha.s@gmail.com](mailto:s.namitha.s@gmail.com) wrote:

> Hi,
> 
> Thanks for the reply.
> 
> I tried the following code:
> 
> ClusterState cs =  
> client.admin().cluster().prepareState().execute().actionGet().getState();  
> IndexMetaData imd = cs.getMetaData().index(INDEX\_NAME);  
> MappingMetaData mmd = imd.mapping(DOCUMENT\_NAME);  
> Map\<String, Object\> source = mmd.sourceAsMap();
> 
> source.keySet() -- only has the value 'properties'  
> source.values() -- has the remaining part of the document mapping.
> 
> So do I have to parse the values() and extract the 'field names' or is  
> there any other way to obtain the it.
> 
> Correct me if my approach is wrong.
> 
> On May 2, 2:17 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > IMHO
> > 
> > You could get the mapping of your document type.  
> > You can get your document as a Map and find field names as keys
> > 
> > Does it help ?
> > 
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr
> > 
> > Le 2 mai 2012 à 11:11, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) a écrit :
> > 
> > > Hi,
> > 
> > > Is it possible to obtain the 'field names'[not values] of the indexed  
> > > document using java API in Elasticsearch?

---

<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:30am UTC](https://discuss.elastic.co/t/obtain-field-names/7533/5 "2017-07-06T03:30:15Z")

</div>


