MiXaiL
MiXaiL

Reputation: 207

The type arguments for method 'ElasticClient.Index<T>(IIndexRequest<T>)' cannot be inferred from the usage

I am learning ElasticSearch following the example elasticsearch-net-example. The error occurs in the following code:

        foreach (var package in packages)
        {
            var result = Client.Index(package); <--The type arguments for method 'ElasticClient.Index<T>(IIndexRequest<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

            if (!result.IsValid)
            {
                Console.WriteLine(result.DebugInformation);
                Console.Read();
                Environment.Exit(1);
            }
        }

I tried to specify the type of the argument as follows:

var result = Client.Index<FeedPackage>(package);

but this leads to another error:

Argument 1: cannot convert from 'NuSearch.Domain.Model.FeedPackage' to 'Nest.IIndexRequest' NuSearch.Indexer

Can you please tell me what am I doing wrong? Perhaps the question is too simple, but I had difficulties with it.

Upvotes: 2

Views: 724

Answers (3)

Alex J.
Alex J.

Reputation: 11

I just met the same problem. Changing the code to var result = Client.Index<FeedPackage>(package, i => i.Type("package")); as MiXaiL suggested in his upvoted answer does not work because it won't compile. However, simply changing Index() to IndexDocument() works beautifully:

var result = Client.IndexDocument(package);

Upvotes: 1

Jan W
Jan W

Reputation: 474

I've had the same issue just a minute ago. Make sure you are using proper .net client version. In my case I was looking at doc for version 1.x while using version 7.x of the client - may bad :)

Current version is available here: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html

Upvotes: 0

MiXaiL
MiXaiL

Reputation: 207

As I understand it, ElasticSearch could not determine the type name by the input value, so you need to add its name in the second parameter:

var result = Client.Index<FeedPackage>(package, i => i.Type("package"));

Upvotes: 1

Related Questions