Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting matched results on _all fields

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 is not returning 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 website for techies ) )

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 null value/no result.

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

How do I get it to work on any field so that I don't have to mention the field name?

like image 770
Ninja Avatar asked Nov 27 '11 14:11

Ninja


People also ask

How do you highlight matched cells in Excel?

On the Home tab, click Conditional Formatting, point to Highlight Cells Rules, and then click Text that Contains. In the box next to containing, type the text that you want to highlight, and then click OK.

How do I automatically highlight cells in Excel based on value?

On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules. Select the command you want, such as Between, Equal To Text that Contains, or A Date Occurring. Enter the values you want to use, and then select a format.


1 Answers

To avoid the need to add _all as a stored field in your index

An alternative quick fix: use * instead of _all:

curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{
  "highlight":{
    "fields":{
      "*":{}
    }
  }
}'
like image 67
Bosh Avatar answered Oct 11 '22 13:10

Bosh