Highlight consistent results across all fields

I want consistent results to be highlighted. This works for me if I mention the name of the field and returns the selected text, however, if I specify the field as "_all", it does not return any value. This works for me:

curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{ "highlight":{ "fields":{ "my_field":{} } } }' 

This returns the expected value as follows: [highlight] => stdClass Object ([my_field] => Array ([0] => stackoverflow is the best site for technicians))

But when I give this:

  curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{ "highlight":{ "fields":{ "_all":{} } } }' 

I get a null value / no result.

 [highlight] => stdClass Object ( [_all] => Array () ) 

How can I make it work in any field so as not to mention the field name?

+8
elasticsearch lucene
source share
4 answers

You need to map the _all field as saved. The image below should do the trick. Please note that this will add an index size.

 { "my_type": { "_all": { "enabled": true, "store": "yes" } }} 
+5
source share

To avoid having to add _all as a saved field in your index

Alternative quick fix: use * instead of _all :

 curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{ "highlight":{ "fields":{ "*":{} } } }' 
+27
source share

If you are using ES 2.x , you need to set the require_field_match option to false due to the changes made , from the document

The default value for the require_field_match parameter has changed from false to true, which means that the default tokens will only take into account the fields that were requested.

This means that when you request the _all field, trying to select on any field other than _all will not produce the selected fragments.

 "highlight": { "fields": { "*": {} }, "require_field_match": false } 
+16
source share

This library has query highlighting features, including highlighting in all fields. README explains how to create an elasticsearch index with a saved _all field, etc .: https://github.com/niranjan-uma-shankar/Elasticsearch-PHP-class

-one
source share

All Articles