Marcel
Marcel

Reputation: 1074

Search over all fields with highlighting

I recently working with Elasticsearch 2 and would like to request a query over all text fields.

GET myindex/mydata/_search
{
  "query": {
    "simple_query_string": {
      "query": "Raketenfahrrad"
    }
  },
  "highlight": {
    "fields": [ { "*": {} } ]
  }
}

The query returns the expected results but without any highlighting. I experienced that I get highlighting when I narrow the search fields manually:

{
  "query": {
    "simple_query_string": {
      "query": "Raketenfahrrad",
      "fields": ["MainTitle","SubTitle","Author","Content"]
    }
  },
  "highlight": {
    "fields": [ { "*": {} } ]
  }
}

But that doesn't fit my requirement "Search over all" and will fail when the next new property is added to mydata type.

Upvotes: 2

Views: 4791

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

From ES 2.0, highlighting will be performed only on queried fields, you have to set require_field_match option to false. Here is the link to the change

Try this

{
  "query": {
    "simple_query_string": {
      "query": "Raketenfahrrad"
    }
  },
  "highlight": {
    "fields": {
      "*": {}
    },
    "require_field_match" : false
  }
}

Upvotes: 5

Related Questions