Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighter exception (0.90.0) #3109

Closed
aantoniadis opened this Issue May 29, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@aantoniadis
Copy link

aantoniadis commented May 29, 2013

When applying highlight on fields that are declared as stored at index mapping but do not actually exists the following exception occurs (in version 0.90.x)

{
   "took":6,
   "timed_out":false,
   "_shards":{
      "total":3,
      "successful":2,
      "failed":1,
      "failures":[
         {
            "index":"myindex",
            "shard":1,
            "status":500,
            "reason":"FetchPhaseExecutionException[[myindex][1]: query[filtered(name:p*)->cache(_type:myindextype)],from[0],size[10]: Fetch Failed [Failed to highlight field [surname]]]; nested: NullPointerException; "
         }
      ]
   },
   "hits":{
      "total":1,
      "max_score":1.0,
      "hits":[

      ]
   }
}.

You can reproduce the error by doing the following on an empty cluster

 # create index 

curl -XPUT 'http://192.168.56.150:9200/myindex/' -d '{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 0
    }
}'

# create the mapping

curl -XPUT http://192.168.56.150:9200/myindex/myindextype/_mapping -d '
    { "myindextype" : {"properties" : { "name":{"type":"string", "store":"yes", "analyzer":"simple"}, "surname":{"type":"string", "store":"yes", "analyzer":"simple"} } } }
'

# add a record 
curl -XPUT http://192.168.56.150:9200/myindex/myindextype/1 -d '{ "name":"panagiotis" }'

# query with highlighting

curl -XGET 'http://192.168.56.150:9200/myindex/myindextype/_search' -d '
{
  "query": {
    "query_string": {
      "query": "name:p*"
    }
  },
  "highlight": {
    "order": "score",
    "fields": {
      "name": {},
      "surname": {}
    }
  }
}
'

I think that ES should not throw an exception on that case (as did in 0.20.X and earlier versions) due to the schema-free philosophy that is built on.

The problematic code is HighlightPhase.java:191 and one easy patch is to to replace that line with the following lines

if (fieldVisitor.fields() == null)
    textsToHighlight = new ArrayList<Object>();
else
    textsToHighlight = fieldVisitor.fields().get(mapper.names().indexName());

I think that the same logic where in previous versions.

Thank you,
Alex

@ghost ghost assigned jpountz May 29, 2013

@jpountz

This comment has been minimized.

Copy link
Contributor

jpountz commented May 29, 2013

Thanks for the comprehensive report! Indeed, this kind of query shouldn't fail, I'll look into it.

jpountz added a commit to jpountz/elasticsearch that referenced this issue May 30, 2013

Highlighting shouldn't fail when the field to highlight is absent.
PlainHighlighter fails with a NPE when the field to highlight is marked as
stored in the mapping but doesn't exist in a hit. This patch makes
FieldsVisitor.fields less error-prone by returning an empty list instead
of null when no matching stored field was found.

Closes: elastic#3109

@jpountz jpountz closed this in 5ea6c77 May 30, 2013

jpountz added a commit that referenced this issue May 30, 2013

Highlighting shouldn't fail when the field to highlight is absent.
PlainHighlighter fails with a NPE when the field to highlight is marked as
stored in the mapping but doesn't exist in a hit. This patch makes
FieldsVisitor.fields less error-prone by returning an empty list instead
of null when no matching stored field was found.

Closes #3109
@s1monw

This comment has been minimized.

Copy link
Contributor

s1monw commented May 30, 2013

thanks adrien!

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Highlighting shouldn't fail when the field to highlight is absent.
PlainHighlighter fails with a NPE when the field to highlight is marked as
stored in the mapping but doesn't exist in a hit. This patch makes
FieldsVisitor.fields less error-prone by returning an empty list instead
of null when no matching stored field was found.

Closes elastic#3109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.