Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using Object Initializer syntax to create MultiMatchQuery

I'm using Nest 2.2.0 and am trying to build a multimatch query as follows:

var searchQuery = new MultiMatchQuery() 
{
    Fields = Field<Product>(p=>p.SKUName, 2),
    Query = "hello world"
};

When I run it however, it returns:

The non-generic type 'Nest.Field' cannot be used with type arguments.

I don't understand why I'm getting the error, since I've more or less taken this query straight from the documentation found at https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/multi-match-usage.html#_object_initializer_syntax_example_35.

In case it matters, I've defined the Product as follows:

[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; }
}

Is anyone able to help?

like image 685
pbc5501 Avatar asked Apr 19 '16 20:04

pbc5501


1 Answers

The Field type you're looking for is 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 });
like image 120
Russ Cam Avatar answered Nov 07 '22 16:11

Russ Cam