简体   繁体   English

如何在Elasticsearch中突出显示日期字段?

[英]How to highlight date fields in Elasticsearch?

My mapping: 我的映射:

"mappings": {
     "my_type": {
        "properties": {
           "birthDate": {
              "type": "date",
              "format": "dateOptionalTime"
           },
           "name": {
              "type": "string"
           }
        }
     }
}

My search query: 我的搜索查询:

GET my_index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "babken"
          }
        },
        {
          "term": {
            "birthDate": {
              "value": "1999-01-01"
            }
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "*": {}
    }
  }
}

However in the response body, only the name field is highlighted, even though the birthDate field has matched as well: 但是,在响应正文中,即使birthDate字段也已匹配,也仅突出显示了name字段:

"hits": [
         {
            "_index": "my_index",
            "_type": "my_type",
            "_id": "1a82fbb4-1268-42b9-9999-ef932f67a114",
            "_score": 12.507131,
            "_source": {
               "name": "babken",
               "birthDate": "1999-01-01",
            },
            "highlight": {
               "name": [
                  "<em>babken</em>"
               ]
            }
         }
         ...

How can I make the birthDate field appear in "highlight" results as well if it has matched? 如果匹配,如何使birthDate字段也出现在“突出显示”结果中?

I'm using Elasticsearch 1.6 我正在使用Elasticsearch 1.6

You would need to change the the type to string to enable highlighting. 您需要将类型更改为string以启用突出显示。

Bare minimum requirement for a field to be enabled for highlighting is that it should be string type. 要使字段突出显示的最低要求是它应该是string类型。

The following issue has little more discussion about it. 以下问题对此没有更多讨论。

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

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