繁体   English   中英

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

[英]How to highlight date fields in Elasticsearch?

我的映射:

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

我的搜索查询:

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

但是,在响应正文中,即使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>"
               ]
            }
         }
         ...

如果匹配,如何使birthDate字段也出现在“突出显示”结果中?

我正在使用Elasticsearch 1.6

您需要将类型更改为string以启用突出显示。

要使字段突出显示的最低要求是它应该是string类型。

以下问题对此没有更多讨论。

暂无
暂无

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

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