# How to get the field infomation when \_all and \_source was set disabled

**URL:** <https://discuss.elastic.co/t/how-to-get-the-field-infomation-when--all-and--source-was-set-disabled/19433>\
**Category:** Elasticsearch\
**Created:** [August 25, 2014, 7:39am UTC](https://discuss.elastic.co/t/how-to-get-the-field-infomation-when--all-and--source-was-set-disabled/19433 "2014-08-25T07:39:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arvin\_Wong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arvin_wong/32/25018_2.png) [@Arvin\_Wong](https://discuss.elastic.co/u/Arvin_Wong)\
**Post date:** [August 25, 2014, 7:39am UTC](https://discuss.elastic.co/t/how-to-get-the-field-infomation-when--all-and--source-was-set-disabled/19433/1 "2014-08-25T07:39:32Z")

</div>

Hi,  
I created an index, which was named test\_all, and it has a "table" :  
type1. I want to test the usage of "\_all" and "\_source". Now , I change  
their status to false. The mapping as follows:  
$ curl -XGET 'localhost:9200/test\_all/\_mapping/type1?pretty'  
{  
"test\_all" : {  
"mappings" : {  
"type1" : {  
"\_all" : {  
"enabled" :false  
},  
"\_source" : {  
"enabled" : false  
},  
"properties" : {  
"content" : {  
"type" : "string",  
"analyzer" : "ik"  
},  
"title" : {  
"type" : "string",  
"store" : true,  
"analyzer" : "ik"  
}  
}  
}  
}  
}  
}

In the table "type1", I store thetitle information. I insert five  
document in type1. But, when retrievaling them, I could not find the  
field "title" information.

$ curl -XGET 'localhost:9200/test\_all/type1/\_search?pretty'  
{  
"took" : 16,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 5,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test\_all",  
"\_type" : "type1",  
"\_id" : "zWQno3rLS56hkwJ\_Y108Dg",  
"\_score" : 1.0  
}, {  
"\_index" : "test\_all",  
"\_type" : "type1",  
"\_id" : "BDKa-IP7TDK\_iM2VNGFPYw",  
"\_score" : 1.0  
}, {  
"\_index" : "test\_all",  
"\_type" : "type1",  
"\_id" : "n97suWSwQACgx35APTOqPg",  
"\_score" : 1.0  
}, {  
"\_index" : "test\_all",  
"\_type" : "type1",  
"\_id" : "2P7OblUiQB2Y8ZCtWWWTdg",  
"\_score" : 1.0  
}, {  
"\_index" : "test\_all",  
"\_type" : "type1",  
"\_id" : "Lo\_PFVeKTEWazwCLbyKAqQ",  
"\_score" : 1.0  
} ]  
}  
}

Then, I try to resolve it by JAVA API:  
public static void indexSearch(Client client){  
SearchRequestBuilder searchRequestBuilder=client.prepareSearch("test\_all");  
searchRequestBuilder.setTypes("type1");  
SearchResponse searchResponse=searchRequestBuilder.execute().actionGet();  
SearchHit[]hits=searchResponse.getHits().getHits();  
System.out.println("count: "+hits.length);  
for(SearchHit hit:hits){  
System.out.println("----------------------------");  
System.out.println("docID: "+hit.getId());  
System.out.println("score: "+hit.getScore());  
System.out.println("title: "+hit.getFields().get("title").toString());  
}  
}

and it shows:

## Exception in thread "main" count: 5

java.lang.NullPointerException  
at es.api.Test\_All.indexSearch(Test\_All.java:64)  
at es.api.Test\_All.main(Test\_All.java:73)  
docID: zWQno3rLS56hkwJ\_Y108Dg  
score: 1.0

I guess the value doesn't exist.

Can you call me why?

Many 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 26, 2014, 1:29pm UTC](https://discuss.elastic.co/t/how-to-get-the-field-infomation-when--all-and--source-was-set-disabled/19433/2 "2014-08-26T13:29:24Z")

</div>

Hello Wang ,

By default the \_source field stores the input JSON and gives it back for  
each document match.  
If you disable , ES wont be able to return it.  
Hence the result you see.  
By default ES wont make any efforts to tap the "Stored" information , it  
rather takes the json stored in \_source field.

Now to get the text set as "stored" , you need to use the fields option.  
Typically , you need to tell ES , you need so and so fields.  
This information would be searched in "stored" field space rather than  
\_source field.

In your query , you need to mention the fields you are interested in -

```
    searchRequestBuilder.setTypes("type1").fields(["title"] )

```

( equal-ant in Java)

Thanks  
Vineeth

On Mon, Aug 25, 2014 at 1:09 PM, Wang Mingxing [wmx3ng@gmail.com](mailto:wmx3ng@gmail.com) wrote:

> Hi,  
> I created an index, which was named test\_all, and it has a "table" :  
> type1. I want to test the usage of "\_all" and "\_source". Now , I change  
> their status to false. The mapping as follows:  
> $ curl -XGET 'localhost:9200/test\_all/\_mapping/type1?pretty'  
> {  
> "test\_all" : {  
> "mappings" : {  
> "type1" : {  
> "\_all" : {  
> "enabled" : false  
> },  
> "\_source" : {  
> "enabled" : false  
> },  
> "properties" : {  
> "content" : {  
> "type" : "string",  
> "analyzer" : "ik"  
> },  
> "title" : {  
> "type" : "string",  
> "store" : true,  
> "analyzer" : "ik"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> In the table "type1", I store the title information. I insert five  
> document in type1. But, when retrievaling them, I could not find the  
> field "title" information.
> 
> $ curl -XGET 'localhost:9200/test\_all/type1/\_search?pretty'  
> {  
> "took" : 16,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 5,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test\_all",  
> "\_type" : "type1",  
> "\_id" : "zWQno3rLS56hkwJ\_Y108Dg",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "test\_all",  
> "\_type" : "type1",  
> "\_id" : "BDKa-IP7TDK\_iM2VNGFPYw",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "test\_all",  
> "\_type" : "type1",  
> "\_id" : "n97suWSwQACgx35APTOqPg",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "test\_all",  
> "\_type" : "type1",  
> "\_id" : "2P7OblUiQB2Y8ZCtWWWTdg",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "test\_all",  
> "\_type" : "type1",  
> "\_id" : "Lo\_PFVeKTEWazwCLbyKAqQ",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> Then, I try to resolve it by JAVA API:  
> public static void indexSearch(Client client){  
> SearchRequestBuilder  
> searchRequestBuilder=client.prepareSearch("test\_all");  
> searchRequestBuilder.setTypes("type1");  
> SearchResponse  
> searchResponse=searchRequestBuilder.execute().actionGet();  
> SearchHithits=searchResponse.getHits().getHits();  
> System.out.println("count: "+hits.length);  
> for(SearchHit hit:hits){  
> System.out.println("----------------------------");  
> System.out.println("docID: "+hit.getId());  
> System.out.println("score: "+hit.getScore());  
> System.out.println("title:  
> "+hit.getFields().get("title").toString());  
> }  
> }
> 
> and it shows:
> 
> ## Exception in thread "main" count: 5
> 
> java.lang.NullPointerException  
> at es.api.Test\_All.indexSearch(Test\_All.java:64)  
> at es.api.Test\_All.main(Test\_All.java:73)  
> docID: zWQno3rLS56hkwJ\_Y108Dg  
> score: 1.0
> 
> I guess the value doesn't exist.
> 
> Can you call me why?
> 
> Many 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mD1J2Jx%2B5\_%2BppYsd9Uc%3DkAtS%2B9fjTWbJjOYXmAorYP5w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mD1J2Jx%2B5_%2BppYsd9Uc%3DkAtS%2B9fjTWbJjOYXmAorYP5w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:06am UTC](https://discuss.elastic.co/t/how-to-get-the-field-infomation-when--all-and--source-was-set-disabled/19433/3 "2017-07-06T01:06:22Z")

</div>


