# Get query result when \_source set disabled using Java API

**URL:** <https://discuss.elastic.co/t/get-query-result-when--source-set-disabled-using-java-api/24062>\
**Category:** Elasticsearch\
**Created:** [June 22, 2015, 8:22am UTC](https://discuss.elastic.co/t/get-query-result-when--source-set-disabled-using-java-api/24062 "2015-06-22T08:22:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunho\_Shin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gunho_shin/32/12210_2.png) [@Gunho\_Shin](https://discuss.elastic.co/u/Gunho_Shin)\
**Post date:** [June 22, 2015, 8:22am UTC](https://discuss.elastic.co/t/get-query-result-when--source-set-disabled-using-java-api/24062/1 "2015-06-22T08:22:39Z")

</div>

Hi, I learning ES for log management system.  
I was run on my index using putMapping() method, and set '\_source : disabled'.  
I confirmed at HEAD plugin that it has been applied.  
My type has two columns that one is stored and another is not.

When I use match query, getTotalHits() method returns 4 but each SearchHit's getSource() method returns null in my loop clause.

So, I change my source code like this

```
SearchResponse searchResponse = client.prepareSearch(indexName).setTypes(typeName)***.addFields(field[0])***//Added
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(matchQuery(field[0], value))
            .setFrom(0).setSize(1000).execute().actionGet();

SearchHit[] result = searchResponse.getHits().getHits();

 for (SearchHit hit : result) {
//My new code
        **Set<String> keys = hit.fields().keySet();**
        **Iterator<String> keyItr = keys.iterator();**
        **while(keyItr.hasNext()){**
            **SearchHitField hitField = hit.field(keyItr.next());**
            **System.out.println(hitField.getValue().toString());**
        **}**
// My older code
// Map<String, Object> r = hit.getSource();
// System.out.println(r);
    }

```

Changed code looks not bad. Returned data set looks like correct one.  
But because I can't see my data list at my HEAD plugin, I can't be sure this code.  
Is it right way? I need anyone to answer. Thanks!

---

<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, 12:06am UTC](https://discuss.elastic.co/t/get-query-result-when--source-set-disabled-using-java-api/24062/2 "2017-07-06T00:06:14Z")

</div>


