“克隆"索引映射 [英] "Clone" index mappings

查看:95
本文介绍了“克隆"索引映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要重新编制索引的索引.目前,我想创建一个新索引,其中应包含与原始索引中可以找到的完全相同的映射.

I have an index which I will be reindexing. At the moment I want to create a new index, which should contain the exact same mappings that can be found in the original index.

我有这个:

var srcMappings = client.GetMapping(new GetMappingRequest((Indices)sourceIndexName)).Mappings;

然后我尝试创建一个索引:

And I try to create an index:

var response = client.CreateIndex(destinationIndex, c => c
    .Settings(...my settings ...)
    .Mappings(... what here? ...)
);

我应该确切地传递给上面的.Mappings(...),以便将源索引中的映射复制到目标索引中?我不想明确地了解"类型.

What exactly should I pass to the .Mappings(...) above so that the mappings from the source index are replicated into the target index? I don't want to explicitly 'know' about the types.

我正在尝试使用Nest.

I am trying to use Nest.

或者,是否有一个Reindex API,它将使用目标索引名称并为我创建索引以及源映射?

Alternatively, is there a Reindex API which would take the destination index name and create the index for me, together with the mappings of the source?

推荐答案

您可以从一个索引中获取映射,并使用它们在另一个索引中创建映射,

You can get the mappings from one index and use them to create the mappings in another index with

var client = new ElasticClient();

var getIndexResponse = client.GetIndex("assignments");

var createIndexResponse = client.CreateIndex("assignments2", c => c
    .Mappings(m => Promise.Create(getIndexResponse.Indices["assignments"].Mappings))
);

您需要实现IPromise<T>来实现

public class Promise
{
    public static IPromise<TValue> Create<TValue>(TValue value) where TValue : class => 
        new Promise<TValue>(value);
}

public class Promise<T> : IPromise<T> where T : class
{
    public T Value { get; } 
    public Promise(T value) => Value = value;
}

在NEST的流畅API实施中的某些地方需要承诺",其中值是可加的,而最终值需要在以后返回.

The Promise is needed in some places in NEST's fluent API implementation where values are additive and a final value needs to be returned at a later point.

您也可以使用对象初始化程序语法执行相同操作,而不使用Promise<T>

You can also do the same using the object initializer syntax and no Promise<T>

var createIndexResponse = client.CreateIndex(new CreateIndexRequest("assignments2")
{
    Mappings = getIndexResponse.Indices["assignments"].Mappings
});

或者,是否有一个Reindex API,它将使用目标索引名称并为我创建索引以及源映射?

Alternatively, is there a Reindex API which would take the destination index name and create the index for me, together with the mappings of the source?

NEST中有两个Reindex API;自NEST 1.x以来一直存在的可观察的实现,以及

There are two Reindex APIs within NEST; an Observable implementation that has been around since NEST 1.x, and the Reindex API as available within Elasticsearch since 2.3 (known as ReindexOnServer in NEST). The former Observable implementation can create the destination index for you, although it will copy all settings, mappings and aliases. The latter Reindex API does not create the destination index as part of the operation, so it needs to be set up before starting the reindex process.

这篇关于“克隆"索引映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆