Elasticsearch NEST客户端ReindexOnServer类型问题



基本上我想重写这个代码:

var values = "{"source":{"index": "" + oldIndex.Index + "","type": "" + MyType+ ""},"
+ "","size": "" + size + ""},"
+ ""dest": {"index": "" + tempIndex + "","type": "_doc"}}";
var result = this.httpClient.PostAsync(ReIndexUrl, new StringContent(values, System.Text.Encoding.UTF8, "application/json")).Result;
var response = result.Content.ReadAsStringAsync().Result;

至NEST客户:

var response = elasticClient.ReindexOnServer(
r => r
.Source(
s => s
.Index(sourceIndex)
)
.Destination(
d => d
.Index(targetIndex)
).Refresh(false).Size(maximumDocuments)
.WaitForCompletion()
);

当使用NEST版本将文档从V6重新索引到V7时,由于目标上的重复类型,我会出现错误:

java.lang.IllegalArgumentException: Rejecting mapping update to [audit-trail-2020-04-temp] as the final mapping would have more than 1 type: [_doc, audittrailentry]

我找不到使用NEST解决此问题的方法,因为无法排除类型?

不幸的是,我没有找到使用NEST客户端的解决方案。最后我写了我自己的扩展:

internal static long ReIndex(this IElasticClient elasticClient, ReindexModel reindexModel)
{
elasticClient.DisableRefreshing(reindexModel.SourceIndex);
var result = HttpClient.PostAsync(ReIndexUrl, new StringContent(JsonConvert.SerializeObject(reindexModel.Value), Encoding.UTF8, "application/json")).Result;
var response = result.Content.ReadAsStringAsync().Result;
var responseObj = JsonConvert.DeserializeObject<ReindexResponse>(response);
return responseObj.Total;
}
internal class ReindexModel
{     
public ReindexModel(string sourceIndex, string targetIndex, string docType, int maxBulkSize)
{
this.SourceIndex = sourceIndex;
this.TargetIndex = targetIndex;
this.DocType = docType;           
this.Value = new { source = new { index = this.SourceIndex, type = this.DocType, size = maxBulkSize }, dest = new { index = this.TargetIndex, type = "_doc" } };
}
public object Value { get; }
public string SourceIndex { get; }
public string TargetIndex { get; }
private string DocType { get; }
}
internal class ReindexResponse
{
[JsonProperty]
public long Total { get; set; }
}

最新更新