NEST2 initialization on .NET C# WebAPI

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!