# Read the Headers in the index using Elasticsearch Java API

**URL:** https://discuss.elastic.co/t/read-the-headers-in-the-index-using-elasticsearch-java-api/91937
**Category:** Elasticsearch
**Created:** [July 5, 2017, 3:01pm UTC](https://discuss.elastic.co/t/read-the-headers-in-the-index-using-elasticsearch-java-api/91937 "2017-07-05T15:01:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)
#### Post date: [July 5, 2017, 3:01pm UTC](https://discuss.elastic.co/t/read-the-headers-in-the-index-using-elasticsearch-java-api/91937/1 "2017-07-05T15:01:18Z")

</div>

Hi,

I'm using Elasticsearch Java API 2.4.2 to fetch the data from Elasticsearch. Currently, by using the following code, I'm able to get the headers but what I need is to fetch the headers based on the data types of the field.

```
 Set<String> fieldSet = new HashSet<String>();
 BoolQueryBuilder query = new BoolQueryBuilder();

 SearchRequestBuilder req = client.prepareSearch(idxName).setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
	SearchResponse response = req.setQuery(query).execute().actionGet();
	for(SearchHit hit : response.getHits()){
		fieldSet.addAll(hit.getSource().keySet());
		break;
	}

```

for example, If there is a field AGE (INT) with integer data type, it should be added to numericalFieldSet, if it is a String, then add that header to fieldSet.  
Any help would be appreciated.  
Thanks,  
Sanjay Reddy.

---

<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: [August 2, 2017, 3:01pm UTC](https://discuss.elastic.co/t/read-the-headers-in-the-index-using-elasticsearch-java-api/91937/2 "2017-08-02T15:01:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
