簡體   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