【问题标题】:ElasticSearch Query Search with Highlight C# NestElasticSearch Query Search with Highlight C# Nest
【发布时间】:2017-12-20 04:06:13
【问题描述】:

我正在为以下查询搜索返回突出显示结果。需要一些帮助来为我指明正确的方向。\

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

这里是请求 JSON

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

【问题讨论】:

  • 你能发布实际的http请求吗
  • 我添加了请求 JSON。

标签: c# elasticsearch nest


【解决方案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":{}}
                ]
            }
            }  
            }
           }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2017-01-07
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    相关资源
    最近更新 更多