# Throws java.lang.NullPointerException when getSource

**URL:** https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633
**Category:** Elasticsearch
**Created:** [April 18, 2013, 4:27pm UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633 "2013-04-18T16:27:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)
#### Post date: [April 18, 2013, 4:27pm UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633/1 "2013-04-18T16:27:45Z")

</div>

Hi there,

When I was running a piece of code, which means to get some doc from my  
index, it throws the exception java.lang.NullPointerException。  
Is there anything I set wrongly? Thanks.

My code is like this:  
GetResponse response = client.prepareGet(indexName, "kba", stream\_id)  
.execute()  
.actionGet();  
String body\_cleansed = response.getSource().get("body\_cleansed").toString();

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [April 18, 2013, 4:29pm UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633/2 "2013-04-18T16:29:35Z")

</div>

## Did you disable source in mapping?

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 18 avr. 2013 à 18:27, Jingang Wang [bitwjg@gmail.com](mailto:bitwjg@gmail.com) a écrit :

> Hi there,
> 
> When I was running a piece of code, which means to get some doc from my index, it throws the exception java.lang.NullPointerException。  
> Is there anything I set wrongly? Thanks.
> 
> My code is like this:  
> GetResponse response = client.prepareGet(indexName, "kba", stream\_id)  
> .execute()  
> .actionGet();  
> String body\_cleansed = response.getSource().get("body\_cleansed").toString();
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)
#### Post date: [April 18, 2013, 4:40pm UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633/3 "2013-04-18T16:40:28Z")

</div>

Hi David,  
I don't think so. I preserved the source option when I was creating the  
indices.  
I remembered that I could run this program the other days.  
Is there other reasons could result in this situation?

On Friday, April 19, 2013 12:29:35 AM UTC+8, David Pilato wrote:

> ## Did you disable source in mapping?
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 18 avr. 2013 à 18:27, Jingang Wang \<[bit...@gmail.com](mailto:bit...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi there,
> 
> When I was running a piece of code, which means to get some doc from my  
> index, it throws the exception java.lang.NullPointerException。  
> Is there anything I set wrongly? Thanks.
> 
> My code is like this:  
> GetResponse response = client.prepareGet(indexName, "kba", stream\_id)  
> .execute()  
> .actionGet();  
> String body\_cleansed = response.getSource()  
> .get("body\_cleansed").toString();
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jingang\_Wang](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jingang\_Wang](https://discuss.elastic.co/u/Jingang_Wang)
#### Post date: [April 18, 2013, 5:04pm UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633/4 "2013-04-18T17:04:06Z")

</div>

I have checked it.  
When I use prepareSearch, getSource works fine.  
While when I use prepareGet, getSource throws this exception.

On Friday, April 19, 2013 12:29:35 AM UTC+8, David Pilato wrote:

> ## Did you disable source in mapping?
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 18 avr. 2013 à 18:27, Jingang Wang \<[bit...@gmail.com](mailto:bit...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi there,
> 
> When I was running a piece of code, which means to get some doc from my  
> index, it throws the exception java.lang.NullPointerException。  
> Is there anything I set wrongly? Thanks.
> 
> My code is like this:  
> GetResponse response = client.prepareGet(indexName, "kba", stream\_id)  
> .execute()  
> .actionGet();  
> String body\_cleansed = response.getSource()  
> .get("body\_cleansed").toString();
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:40am UTC](https://discuss.elastic.co/t/throws-java-lang-nullpointerexception-when-getsource/11633/5 "2017-07-06T02:40:36Z")

</div>


