使用 Object Initializer 语法创建 MultiMatchQuery 时出错
Error using Object Initializer syntax to create MultiMatchQuery
我正在使用 Nest 2.2.0 并尝试构建一个多匹配查询,如下所示:
var searchQuery = new MultiMatchQuery()
{
Fields = Field<Product>(p=>p.SKUName, 2),
Query = "hello world"
};
当我运行它然而,它returns:
The non-generic type 'Nest.Field' cannot be used with type arguments.
我不明白为什么会收到错误消息,因为我或多或少是直接从 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; }
}
有人能帮忙吗?
您要查找的 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 });
我正在使用 Nest 2.2.0 并尝试构建一个多匹配查询,如下所示:
var searchQuery = new MultiMatchQuery()
{
Fields = Field<Product>(p=>p.SKUName, 2),
Query = "hello world"
};
当我运行它然而,它returns:
The non-generic type 'Nest.Field' cannot be used with type arguments.
我不明白为什么会收到错误消息,因为我或多或少是直接从 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; }
}
有人能帮忙吗?
您要查找的 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 });