# CompletionSuggestion.Entry.Option.getPayloadAsMap() throws NPE if no payload is indexed

**URL:** <https://discuss.elastic.co/t/completionsuggestion-entry-option-getpayloadasmap-throws-npe-if-no-payload-is-indexed/17507>\
**Category:** Elasticsearch\
**Created:** [May 14, 2014, 7:44am UTC](https://discuss.elastic.co/t/completionsuggestion-entry-option-getpayloadasmap-throws-npe-if-no-payload-is-indexed/17507 "2014-05-14T07:44:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markus\_Wiesenbacher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Markus\_Wiesenbacher](https://discuss.elastic.co/u/Markus_Wiesenbacher)\
**Post date:** [May 14, 2014, 7:44am UTC](https://discuss.elastic.co/t/completionsuggestion-entry-option-getpayloadasmap-throws-npe-if-no-payload-is-indexed/17507/1 "2014-05-14T07:44:00Z")

</div>

Hi,

some of my documents don´t have a payload but some do. If I use following,  
I always get a NPE:

```
        ...
        Iterator<? extends Option> iterator = 

```

response.getSuggest().iterator().next().getEntries().get(0).iterator();  
while (iterator.hasNext()) {

```
            CompletionSuggestion.Entry.Option completionOption = 

```

(CompletionSuggestion.Entry.Option)iterator.next();  
System.out.println("###: " +  
completionOption.getPayloadAsMap()); // in ES v1.1.1  
getPayloadAsMap() results in NPE  
...

Stacktrace:

java.lang.NullPointerException  
at  
org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:117)  
at  
org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:116)  
at  
org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:75)  
at  
org.elasticsearch.search.suggest.completion.CompletionSuggestion$Entry$Option.getPayloadAsMap(CompletionSuggestion.java:105)

Best regards  
Markus

--  
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/60f54701-b8e2-4f7c-8802-add7c4121934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/60f54701-b8e2-4f7c-8802-add7c4121934%40googlegroups.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:29am UTC](https://discuss.elastic.co/t/completionsuggestion-entry-option-getpayloadasmap-throws-npe-if-no-payload-is-indexed/17507/2 "2017-07-06T01:29:32Z")

</div>


