簡體   English   中英

是否可以僅突出顯示match_phrase查詢?

[英]Is it possible to highlight only match_phrase query?

我有這樣的布爾查詢

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "type": [
              "bill",
              "press release"
            ]
          }
        },
        {
          "match_phrase": {
            "title": "health"
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "policy_content": {}
    }
  },
  "sort": [
    {
      "publishdate": {
        "order": "desc"
      }
    }
  ]
}

用戶正在搜索關鍵字“健康”,關鍵字被突出顯示,但是“帳單”和“新聞稿”也被突出顯示,這是我不希望的。 我應該如何解決這個問題?

您可以通過highlight_query指定用於突出顯示的查詢。

因此,您可以通過將查詢的突出顯示部分更新為以下內容來利用這一點:

"highlight" : {
    "fields" : {
        "policy_content" : {
            "highlight_query" : {
                "match_phrase" : {
                    "policy_content" : "health"
                }
            }
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM