Raffaeu
Raffaeu

Reputation: 6973

ElasticSearch Javascript, Highlight not working

we switched recently to ElasticSearch Angular version and everything is working as expected except the Highlight, which is not returned at all.

This is how I setup a demo query:

$esClient.search({
            index: 'myIndex',
            body: {
                size: 10,
                from: 0,
                query: query,
                highlight: {
                    fields: {
                        "_all": { "pre_tags": ["<em>"], "post_tags": ["</em>"] }
                    }
                }
            }
        }).then(function (result) {

            // map the resultset for Row Template
            var currentRows = result.hits.hits.map(function (record) {
                return {
                    "type": record._type,
                    "entity": record._source,           // the result
                    "highlight": record.highlight,      // the highlights
                    "id": record._id                    // Search record ID
                };
            });

        });

If I use the same code with a classic XmlHttpRequest and pass the query model inlcuding the highlight, I get back a JSON which contains an highlight array per each result, while using the ElasticSearch Angular client the query succeed but I don't get back the highlight.

Am I doing something wrong?

Upvotes: 1

Views: 573

Answers (1)

Vishal Rao
Vishal Rao

Reputation: 912

I think you might want to change to this format:

{
"query" : {...},
"highlight" : {
    "pre_tags" : ["<tag1>"],
    "post_tags" : ["</tag1>"],
    "fields" : {
        "_all" : {}
    }
}}

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html

Upvotes: 2

Related Questions