【问题标题】:Elasticsearch exclude bool "term" from getting highlightedElasticsearch 从突出显示中排除布尔“术语”
【发布时间】:2013-08-15 13:03:37
【问题描述】:

我有以下弹性搜索查询,其查询字符串应与所有字段匹配,术语查询应与下面给出的相应字段匹配。我只希望 query_string 成为突出显示的一部分。当我使用 required_field_match 时,它仅突出显示频道字段上的“电子邮件”一词。没有 required_field_match 它在我不想要的所有字段上匹配“电子邮件”和 query_string。您能告诉我如何从突出显示中排除“频道”字段吗?

 {
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "channel":"email"
               }
            },
            {
               "query_string":{
                  "query":"\"payment type\"",
                  "default_operator":"AND"
               }
            }
         ]
      }
   },
   "highlight":{
      "pre_tags":[
         "<span class='highlight'>"
      ],
      "post_tags":[
         "</span>"
      ],
      "require_field_match":false,
      "fields":{
         "requestSummary":{
            "number_of_fragments":0
         },
         "emails.emailBody":{
            "number_of_fragments":0
         },
         "chatTextArray.text":{
            "number_of_fragments":0
         },
         "chatTextArray.name":{
            "number_of_fragments":0
         }
      }
   },
   "facets":{
      "channel":{
         "terms":{
            "field":"channel"
         }
      },
      "siteId":{
         "terms":{
            "field":"siteId"
         }
      },
      "closeDt":{
         "terms":{
            "field":"closeDt"
         }
      },
      "srId":{
         "terms":{
            "field":"srId"
         }
      }
   }
}

搜索结果:

    {
       "highlight":{
          "emails.emailBody":[
             "helps keep your information safe, visit:  http://pages.half.ebay.com/help/policy/privacy.html#toc-02 
In this <span class='highlight'>email</span>"
          ],
          "requestSummary":[
             "Change <span class='highlight'>payment</span> <span class='highlight'>type</span>"
          ]
       }
    }

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这是弹性荧光笔的默认行为。 您可以使用 highlight_query 属性覆盖荧光笔查询

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_highlight_query

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-21
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      相关资源
      最近更新 更多