【发布时间】:2022-10-07 14:27:39
【问题描述】:
我在 Elastic Search 中有 3 个索引,我将一次查询一个(意思是 - 我想要任何时候仅来自 1 个索引的结果)。如何声明 ElasticSearch 客户端并重用?
在 SearchRequest 中添加索引名称看起来不像是一个选项,因为当我在启动客户端时没有提供任何默认索引名称时,它会给出异常。在下面添加代码,任何帮助表示赞赏。
string cloudid = \"something\";
var credentials = new BasicAuthenticationCredentials(\"something\", \"something\");
var connectionPool = new CloudConnectionPool(cloudid, credentials);
var settings = new ConnectionSettings(connectionPool);
var client = new ElasticClient(settings); //EXCEPTION HERE THAT - Index Name is NULL
ISearchRequest searchRequest = new SearchRequest(\"indexname\")
{
Query = new TermQuery { Field = Infer.Field<Doctor>(d => d.FirstName), Value = \"FirstName73069\" },
Size = 10000
};
var secondSearchResponse = await client.SearchAsync<Doctor>(searchRequest);
这是我拥有的代码,它在第 5 行中断(添加注释)。 注意:我的用例必须使用 SearchRequest 对象。请相应地提出建议。
使用 Nest 7.17.4 版本。
标签: c# .net elasticsearch nest