Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: [filtered] query does not support [highlight]

I am new to Elasticsearch. I have a filtered query as follows

{
    "query": {
        "filtered" : {
            "query" : {
                "term" : {
                    "title" : "crime"
                }
            },
            "highlight" : {
                "fields" : {
                    "title" : {}
                }
            },
            "filter" : {
                "term" : { "year" : 1961 }
            }
        }
    }
}

When I tried this query and got the error:

[filtered] query does not support [highlight]

Does filtered query support highlight? If not, how can I achieve highlight in query with filters? I have to use filters.

Thanks and regards!

like image 889
curious1 Avatar asked Aug 02 '14 21:08

curious1


1 Answers

The "highlight" parameter should go at the same level as the "query" parameter, not embedded within it. In your case it should look something like this:

{
    "query": {
        "filtered" : {
            "query" : {
                "term" : {
                    "title" : "crime"
                }
            },
            "filter" : {
                "term" : { "year" : 1961 }
            }
        }
    },
    "highlight" : {
        "fields" : {
            "title" : {}
        }
    }
}
  • Highlighting reference

  • Highlights problems with a filtered query

like image 161
John Petrone Avatar answered Dec 08 '22 16:12

John Petrone