I want the matched results to be highlighted. This works for me if I mention the field name and it returns the highlighted text, however if I give the field as \"_all\", it
This library has functions for query highlighting including highlighting across all fields. The README explains how to create an elasticsearch index with _all field stored etc: https://github.com/niranjan-uma-shankar/Elasticsearch-PHP-class
You need to map the _all field as stored. The mapping below should do the trick. Note though that this will add to the index size.
{
"my_type": {
"_all": {
"enabled": true,
"store": "yes"
}
}}
If you are using ES 2.x
then you need to set require_field_match
option to false
due to changes made, From the doc
The default value for the require_field_match option has changed from false to true, meaning that the highlighters will, by default, only take the fields that were queried into account.
This means that, when querying the _all field, trying to highlight on any field other than _all will produce no highlighted snippets.
"highlight": {
"fields": {
"*": {}
},
"require_field_match": false
}
_all
as a stored field in your indexAn alternative quick fix: use *
instead of _all
:
curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{
"highlight":{
"fields":{
"*":{}
}
}
}'