2

只是想知道。是否可以在 _source = false 的索引上突出显示 ElasticSearch 中的文本?

我的意思是我知道如果 ES 没有他不能做高亮的文档,但是有没有办法只使用 ES 作为高亮引擎而不是带有高亮的完整搜索引擎?(我在高亮查询中提供了完整的文档)

谢谢

4

3 回答 3

3

我不相信这是可能的。

但是,您可以在搜索查询和文档上使用 _analyze,然后比较标记以在代码中突出显示。

例如:

curl -XGET 'localhost:9200/test/_analyze?analyzer=snowball' -d 'some search query keywords'

{"tokens":[{"token":"some","start_offset":0,"end_offset":4,"type":"","position":1},{"token":"search", "start_offset":5,"end_offset":11,"type":"","position":2},{"token":"query","start_offset":12,"end_offset":17,"type" :"","position":3},{"token":"keyword","start_offset":18,"end_offset":26,"type":"","position":4}]}

curl -XGET 'localhost:9200/test/_analyze?analyzer=snowball' -d '$document_text'

{“令牌”:..}

然后在文档中查找那些令牌匹配项,偏移量应该为您提供文档中正确的突出显示位置。

于 2012-06-22T21:40:36.613 回答
1
{
  "query": {
    "query_string": {
      "query": "**",
      "fields["
      sometext "]}},"
      highlight {
        "pre_tags": ["<em>"],
        "post_tags[</em>"],
      "order": "score",
      "require_field_match": true,
      "fields": {
        "sometext": {
          "fragment_size": 180,
          "number_of_fragments": 1
        }
      }
    }
  }
于 2017-09-18T08:10:04.887 回答
0

如果默认情况下未停用源,您可以:

{
    "_source" :  ["_id"],
    "query": {
        "match" : {
            "attachment.content" : "Setup"
        }
    },
    "highlight": {
        "fields" : {
            "attachment.content" : {}
        }
    }
}

你必须在_score. 它仍然返回有关它找到的文档的每个“元数据”:

{
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 0.2919385,
        "hits": [
            {
                "_index": "test",
                "_type": "_doc",
                "_id": "xpto",
                "_score": 0.2919385,
                "_source": {},
                "highlight": {
                    "attachment.content": [
                        "<em>Setup</em> the [GenericCommand.properties] file\n\nThe commands that ought to be recognized have to be defined"
                    ]
                }
            }
        ]
    }
}
于 2019-05-22T15:15:35.827 回答