Elasticsearch将bool“term”排除在突出显示之外

时间:2013-08-13 19:05:14

标签: elasticsearch

我有以下弹性搜索查询,查询字符串应匹配所有字段,术语查询应与下面给出的相应字段匹配。我只希望query_string成为亮点的一部分。当我使用required_field_match时,它仅突出显示频道字段中的术语“电子邮件”。没有required_field_match它匹配我不想要的所有字段上的“email”和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>"
          ]
       }
    }

1 个答案:

答案 0 :(得分:0)

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

覆盖突出显示器查询

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