Elasticsearch NEST MultiGet 跨多个索引
Elasticsearch NEST MultiGet across multiple indexes
我想运行 MultiGet (mget
) 对两个索引中多个 ID 的搜索查询。这是因为我有两个索引,但我不知道哪个索引包含我的 ID。这是查询:
GET _mget
{
"docs" : [
{
"_id": "id1",
"_index": "index1"
},
{
"_id": "id1",
"_index": "index2"
}
/* .... */
]
}
手动查询效果很好 - 我得到了结果,我只是忽略了 returns found: false
.
的结果
Nest
不支持此功能,仅在一个索引上。所以我尝试使用低级客户端来实现这一点,如下所示:
var data = PostData.Serializable(new
{
docs = new[]
{
new {
_id = "1",
_index = "index1"
},
new
{
_id = "1",
_index = "index2"
}
}
});
var response = await lowLevelClient.MultiGetAsync<MultiGetResponse>(data);
但是,我收到以下异常:Elasticsearch.Net.UnexpectedElasticsearchClientException: 'Constructor on type 'Nest.MultiGetResponseFormatter' not found.'
。
这是实现我想要的目标的正确方法吗?
以下内容将帮助您使用 NEST 实现您的目标
var request = new MultiGetRequest();
request.Documents = new IMultiGetOperation[]
{
new MultiGetOperation<object>("id1") { Index = "index1" },
new MultiGetOperation<object>("id1") { Index = "index2" },
};
var multiGetResponse = await client.MultiGetAsync(request);
我想运行 MultiGet (mget
) 对两个索引中多个 ID 的搜索查询。这是因为我有两个索引,但我不知道哪个索引包含我的 ID。这是查询:
GET _mget
{
"docs" : [
{
"_id": "id1",
"_index": "index1"
},
{
"_id": "id1",
"_index": "index2"
}
/* .... */
]
}
手动查询效果很好 - 我得到了结果,我只是忽略了 returns found: false
.
Nest
不支持此功能,仅在一个索引上。所以我尝试使用低级客户端来实现这一点,如下所示:
var data = PostData.Serializable(new
{
docs = new[]
{
new {
_id = "1",
_index = "index1"
},
new
{
_id = "1",
_index = "index2"
}
}
});
var response = await lowLevelClient.MultiGetAsync<MultiGetResponse>(data);
但是,我收到以下异常:Elasticsearch.Net.UnexpectedElasticsearchClientException: 'Constructor on type 'Nest.MultiGetResponseFormatter' not found.'
。
这是实现我想要的目标的正确方法吗?
以下内容将帮助您使用 NEST 实现您的目标
var request = new MultiGetRequest();
request.Documents = new IMultiGetOperation[]
{
new MultiGetOperation<object>("id1") { Index = "index1" },
new MultiGetOperation<object>("id1") { Index = "index2" },
};
var multiGetResponse = await client.MultiGetAsync(request);