5

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?

1 Answer 1

8

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 });
Sign up to request clarification or add additional context in comments.

2 Comments

No worries, happy to help :)
Thanksssss a lot . But I found the documentation of nest and es a little difficult to identify .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.