在ElasticSearch中使用突出显示_source:false

时间:2012-06-14 22:21:17

标签: lucene highlight elasticsearch

只是想知道。 是否可以使用_source = false?

在索引上突出显示ElasticSearch中的文本

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

由于

3 个答案:

答案 0 :(得分:3)

我不相信这是可能的。

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

例如:

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

{ “标记”:[{ “令牌”: “一些”, “start_offset”:0 “end_offset”:4, “类型”: “”, “位置”:1},{ “标记”:”搜索”, “start_offset”:5 “end_offset”:11, “类型”: “”, “位置”:2},{ “标记”: “查询”, “start_offset”:12, “end_offset”:17, “类型”: “”, “位置”:3},{ “标记”: “关键字”, “start_offset”:18, “end_offset”:26, “类型”: “”, “位置”:4}]}

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

{ “标记”:..}

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

答案 1 :(得分: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
        }
      }
    }
  }

答案 2 :(得分: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"
                    ]
                }
            }
        ]
    }
}