简体   繁体   English

ElasticSearch Javascript,突出显示不起作用

[英]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. 我们最近切换到了ElasticSearch Angular版本,除Highlight突出显示外,其他所有功能均按预期工作,该功能完全未返回。

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. 如果我将相同的代码与经典XmlHttpRequest一起使用并传递包含突出显示的查询模型,则会返回一个JSON,其中每个结果均包含一个突出显示数组,而使用ElasticSearch Angular客户端时查询会成功,但不会返回突出。

Am I doing something wrong? 难道我做错了什么?

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 https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-request-highlighting.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM