ElasticSearch查询突出显示C#Nest

时间:2017-07-15 00:51:16

标签: c# elasticsearch nest

我想要获得以下查询搜索的高亮显示结果。需要一些帮助指出我正确的方向。\

使用Nest 5.4.0和ElasticSearch服务器5.5.0

var results = client.Search<Customer>(s => s
              .Query(q => q.QueryString(qs=>qs.Query(searchTerm)))
              .Highlight(h=>
                    h.Fields(f=>
                       f.Field("*")
                       .HighlightQuery(q => 
                          q.QueryString(qs => s.Query(searchTerm))))
));

这是Request JSON

{
  "highlight": {
   "fields": {
    "*": {
      "highlight_query": {
      "query_string": {
        "query": "a"
      }
    }
  }
}
  },
  "query": {
    "query_string": {
      "query": "a"
    }
  }
}

1 个答案:

答案 0 :(得分:1)

我没有将query_string查询更改为multi_match

{
   "from": 0,
   "size": 10,
   "query": {
   "multi_match" : {
         "query":    "Troy", 
         "fields": [ 
               "customer_num^2", 
               "full_name^3", 
               "invoice_numbers", 
               "ticket_number", 
               "transaction_number" ]                        
                }
            },
            "highlight" : {
                    "fields" : [
                    {"customer_num":{}}, 
                    {"full_name":{}},                         
                    {"invoice_numbers":{}}, 
                    {"ticket_number":{}}, 
                    {"transaction_number":{}}
                ]
            }
            }  
            }
           }