我使用的是Nest 2.2.0,并尝试按如下方式构建多匹配查询:
var searchQuery = new MultiMatchQuery()
{
Fields = Field<Product>(p=>p.SKUName, 2),
Query = "hello world"
};
但是当我运行它时,它会返回:
非泛型类型&#39; Nest.Field&#39;不能与类型参数一起使用。
我不明白为什么我会收到错误,因为我或多或少直接从https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/multi-match-usage.html#_object_initializer_syntax_example_35的文档中获取了此查询。
如果重要,我已将产品定义如下:
[ElasticsearchType(Name="product", IdProperty="Id")]
public class Product
{
[Nest.Number(Store = true)]
public int Id {get;set;}
[String(Name="name", Store = true, Index=FieldIndexOption.Analyzed)]
public string SKUName { get; set; }
}
有人能帮忙吗?
答案 0 :(得分:8)
您正在寻找的Field
类型是Nest.Infer.Field
var searchQuery = new MultiMatchQuery()
{
Fields = Nest.Infer.Field<Product>(p => p.SKUName, 2),
Query = "hello world"
};
client.Search<Product>(new SearchRequest { Query = searchQuery });