NEST2 initialization on .NET C# WebAPI

2019-09-06 07:36发布

问题:

I defined the NEST2 client dependencies like this:

  container.RegisterType<IElasticClient, ElasticClient>(
        new InjectionConstructor(
            new ResolvedParameter<IConnectionSettingsValues>(),
            new OptionalParameter<IConnection>(),
            new OptionalParameter<IElasticsearchSerializer>(),
            new OptionalParameter<ITransport>()));

I was using NEST and ElasticSearch. Now I moved to NEST 2 and ElasticSearch 2 and I had to change INestSerializer into IElasticsearchSerializer

Unfortunately now I've got this error on ITransport

Using the generic type ITransport requires 1 type arguments

What should I pass to ITransport? I tried changing the line to:

 new OptionalParameter<ITransport<IConnectionConfigurationValues>>()));

but I get this exception at runtime:

The type Nest.ElasticClient does not have a constructor that takes the parameters (IConnectionSettingsValues, IConnection, IElasticsearchSerializer, ITransport`1)

What should I do now?

EDIT

The current constructors for the ElasticClient class are:

  • ()
  • (IConnectionSettingValues connSettings)
  • (ITransport<IConnectionSettingValues tran)
  • (Uri uri)

So basically I can pass nothing, a connection setting, a transport or the URL endpoint

My Elasticsearch 2 is using username and a password so I bet I should use either the second or the third constructor overload