2017-07-15 124 views
0

我正打算爲以下查詢搜索獲取突出顯示結果。需要一些幫助來點我的正確方向。\帶有突出顯示的C#嵌套的ElasticSearch查詢搜索

使用巢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)))) 
)); 

這裏是請求JSON

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

你能夠發佈實際的http請求 – Alok

+0

我添加了請求JSON。 –

回答

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":{}} 
       ] 
      } 
      } 
      } 
      }