# Failed to highlight field: NullPointerException

**URL:** <https://discuss.elastic.co/t/failed-to-highlight-field-nullpointerexception/11691>\
**Category:** Elasticsearch\
**Created:** [April 25, 2013, 9:34am UTC](https://discuss.elastic.co/t/failed-to-highlight-field-nullpointerexception/11691 "2013-04-25T09:34:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pat\_3](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@Pat\_3](https://discuss.elastic.co/u/Pat_3)\
**Post date:** [April 25, 2013, 9:34am UTC](https://discuss.elastic.co/t/failed-to-highlight-field-nullpointerexception/11691/1 "2013-04-25T09:34:28Z")

</div>

Hi,

I have a field called "snippet" which contains text and may occur multiple  
times on the root level of my document. I want to highlight two other  
fields plus highlighted fragments from "snippet". Alas, sometimes it works,  
sometimes it doesn't. I'm using the following highlighting definition:

"highlight": {  
"fields": {  
"maintitle": {},  
"subtitle": {},  
"snippet": {  
"pre\_tags": [  
""  
],  
"post\_tags": [  
""  
],  
"fragment\_size": 50,  
"number\_of\_fragments": 10  
}  
}  
}

I get an error like the following:

{  
"error" : "SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], total failure; shardFailures  
{[5mQh1Kr5QISWdJuk2Falzw][hrfesad][0]: FetchPh  
aseExecutionException[[hrfesad][0]:  
query[filtered(title:test)-\>cache(\_type:searchdoc)],from[0],size[5],sort[\<custom:"sortkey1":  
[org.elasticsearch.index.fi](http://org.elasticsearch.index.fi)  
elddata.fieldcomparator.BytesRefFieldComparatorSource@6f69a0a0\>!,\<custom:"sortkey2":  
org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldCompara  
torSource@7fb0a184\>]: Fetch Failed [Failed to highlight field [snippet]]];  
nested: NullPointerException; }]",  
"status" : 500  
}

Here, the "snippet" field seems to be problematic but sometimes also  
"subtitle" is show in the error. I will try to investigate in which cases  
it works, but currently I have no idea where to start.

--  
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:** ![Pat\_3](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@Pat\_3](https://discuss.elastic.co/u/Pat_3)\
**Post date:** [April 25, 2013, 11:13am UTC](https://discuss.elastic.co/t/failed-to-highlight-field-nullpointerexception/11691/2 "2013-04-25T11:13:19Z")

</div>

Oh, the answer seems to be embarrasingly simple: One of the problematic  
documents didn't contain a snippet field, because in the database it was  
empty. I still have to verify if this is really the reason. But I think  
Elasticsearch should ignore an empty field instead of throwing an exception.

--  
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:39am UTC](https://discuss.elastic.co/t/failed-to-highlight-field-nullpointerexception/11691/3 "2017-07-06T02:39:40Z")

</div>


