我想mget跨兩個索引對多個 ID 運行 MultiGet ( ) 搜索查詢。這是因為我有兩個索引,但我不知道哪個索引包含我的 ID。這是查詢:
GET _mget
{
"docs" : [
{
"_id": "id1",
"_index": "index1"
},
{
"_id": "id1",
"_index": "index2"
}
/* .... */
]
}
該查詢手動作業得很好 - 我得到了結果,我只是忽略了回傳的結果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.'.
這是實作我想要的正確方法嗎?
uj5u.com熱心網友回復:
以下將幫助您通過 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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/448766.html
