c# - 使用Highlight C#Nest进行ElasticSearch查询搜索

标签 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))))
));

这是请求JSON
{
  "highlight": {
   "fields": {
    "*": {
      "highlight_query": {
      "query_string": {
        "query": "a"
      }
    }
  }
}
  },
  "query": {
    "query_string": {
      "query": "a"
    }
  }
}

最佳答案

我没有将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":{}}
                ]
            }
            }  
            }
           }

关于c# - 使用Highlight C#Nest进行ElasticSearch查询搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45113405/

相关文章:

elasticsearch - 嵌套DSL语法中的多个术语

elasticsearch - 如何使用Nest在ElasticSearch中以纯文本形式搜索字段?

c# - 从对象中删除访问器

elasticsearch - 根据可能不存在的日期字段对查询进行排序和查询

elasticsearch - 使用kafka连接器推送到Elasticsearch时为invalid_argument_exception

elasticsearch - 为每个过滤后的Elasticsearch文档运行一个子查询

C#:对象到字符串数组。 [*] 到 [] 错误(了解 VB.NET 和 C# 会有所帮助)

c# - 我需要从表中获取数字类型列

c# - 在 Unity 中运行时设置法线贴图

c# - 将日志重定向到logstash实例而不是ElasticSearch