Bailey Smith
Bailey Smith

Reputation: 2933

Elasticsearch 2.x, search not returning highlight array

I'm having a really tough time spotting what's wrong with this query. I do get results for the query, but highlights are not included.

{ "query": { "query_string": { "query": "foo", "default_operator":"AND" }
}, "highlight":{ "fields": { "title":{} } } }

Upvotes: 0

Views: 76

Answers (1)

codegrep_admin
codegrep_admin

Reputation: 529

I am guessing elasticsearch is matching _all for querystring query and hence is not highlighting. Try

{
    "query": {
        "query_string": {
            "query": "title:foo", 
            "default_operator":"AND"
        }

    },
    "highlight":{
        "fields": {
            "title":{}
        } 
    }
}

Alternatively, you can specify default_field like this:

{
    "query": {
        "query_string": {
            "query": "foo",
            "default_field": "title", 
            "default_operator":"AND"
        }

    },
    "highlight":{
        "fields": {
            "title":{}
        } 
    }
}

Upvotes: 1

Related Questions