【问题标题】:Elasticsearch: How to highlight any field in document which contain searched string?Elasticsearch:如何突出显示文档中包含搜索字符串的任何字段?
【发布时间】:2017-01-13 21:51:14
【问题描述】:

我正在尝试为数千个具有动态结构的文档构建全文搜索查询。

但 highlight 方法仅适用于特定命名的字段。

如果我想对 _all 或 _source 使用搜索,它不会显示任何突出显示的结果。

我已经尝试了很多不同的方法并尝试“谷歌搜索”但没有成功。

基本查询:

POST tracking*/_search
{
    "query": {
    "query_string": {
      "query": "ci1483967534008.6100622@czcholsint372_te"
    }
  },
  "highlight": {
    "require_field_match": false
  }
}

将返回:

  "hits": {
    "total": 8,
    "max_score": 13.482396,
    "hits": [
      {
        "_index": "tracking-2017.01.09",
        "_type": "cyclone",
        "_id": "Cyclone1-UAT-ci1483967534008.6100622@czcholsint372_te-Messaging.Message.MessageUnpackaged.Request",
        "_score": 13.482396,
        "_source": {
        ... truncated ...
          "received": "2017-01-09T13:12:14.008Z",
          "tags": [],
          "@timestamp": "2017-01-09T13:12:14.008Z",
          "size": "3169",
          "pairing": " ci1483967534008.6100622@czcholsint372_te <60a93b9-159835b287e-159835b79041a66cd1@ip.net> ErpExJets_RDC1_ProcessPurchaseOrder_9.4.1_20170109131207169 ErpExJets_RDC1_ProcessPurchaseOrder_9.4.1_20170109131207169",
        }
      },

但即使搜索到的字符串在配对字段中也不会突出显示。

有可能吗?

谢谢 雷迪

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    Elastic doumentation 将此作为注释提到 - “为了执行突出显示,需要字段的实际内容。如果存储有问题的字段(在映射中将 store 设置为 true),它将被使用,否则,将加载实际的 _source 并从中提取相关字段。”

    因此,除非您将 _all 设置为 true,否则请使用以下查询。

    {
        "query": {
            "query_string": {
                "query": "ci1483967534008.6100622@czcholsint372_te"
            }
        },
        "highlight": {
            "require_field_match": false,
            "fields": {
                "pairing": {}
            }
        }
    }
    

    如果您将源文档的 _all 设置为 true,请使用以下内容

    {
        "query": {
            "query_string": {
                "query": "ci1483967534008.6100622@czcholsint372_te"
            }
        },
        "highlight": {
            "require_field_match": false,
            "fields": {
                "_all": {}
            }
        }
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多