elasticsearch - 使用NEST V5.4重新索引-ElasticSearch

标签 elasticsearch indexing nest reindex

我是ElasticSearch的新手。我正在尝试为索引重新索引以便对其重命名。我正在使用NEST API v5.4。
我看到了这个例子:

var reindex =
    elasticClient.Reindex<Customer>(r =>
        r.FromIndex("customers-v1")
            .ToIndex("customers-v2")
            .Query(q => q.MatchAll())
            .Scroll("10s")
            .CreateIndex(i =>
                i.AddMapping<Customer>(m =>
                    m.Properties(p =>
                        p.String(n => n.Name(name => name.Zipcode).Index(FieldIndexOption.not_analyzed))))));

来源:http://thomasardal.com/elasticsearch-migrations-with-c-and-nest/

但是,我无法使用NEST 5.4重现此内容。我认为这是2.4版。
我检查了ElasticSearch的重大变化,并尝试使用此方法重新建立索引:

来源:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-breaking-changes.html
public method Nest.ReindexDescriptor..ctor Declaration changed (Breaking)
2.x: public .ctor(IndexName from, IndexName to) 5.x: public .ctor()

var reindex = new client.Reindex(oldIndexName, newIndexName);

但这也没有用。
我也搜索文档,但是我没有在C#上找到任何代码,只是JSON
来源:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)

有人可以给我一个例子,如何在C#上使用NEST 5.4重新编制索引吗?

提前致谢! :slight_smile:

最佳答案

搜索2天后,我找到了重新索引索引的解决方案。为了解决将来的问题,我将提供解决方案。

Nest版本-5.4

var reindex = client.Reindex<object>(r => r
              .BackPressureFactor(10)
              // ScrollAll - Scroll all the documents of the index and store it for 1minute 
              .ScrollAll("1m", 2, s => s
                  .Search(ss => ss
                      .Index(oldIndexName)
                          .AllTypes())
                      // there needs to be some degree of parallelism for this to work
                      .MaxDegreeOfParallelism(4))
              .CreateIndex(c => c
                  // New index here
                  .Index(newIndexName)
                  .Settings(
                      // settings goes here)
                  .Mappings(
                      // mappings goes here))
              .BulkAll(b => b
                  // New index here!
                  .Index(newIndexName)
                  .Size(100)
                  .MaxDegreeOfParallelism(2)
                  .RefreshOnCompleted()));

ReIndex方法将返回一个冷的 IObservable ,您必须在其上调用 .Subscribe()以启动所有操作。

因此,您需要将其添加到代码中:
var o = new ReindexObserver(
            onError: (e) => { //do something },
            onCompleted: () => { //do something });
reindex.Subscribe(o);

进行检查的有用链接是:

Documentation

Issue 2660 on GitHub

Issue 2771 on GitHub

关于elasticsearch - 使用NEST V5.4重新索引-ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266969/

相关文章:

Mysql 在选择非索引字段时不使用索引

.net - 禁用 SqlBulkCopy 错误的索引

javascript - 创建一个新的索引数组

elasticsearch - 如何获得别名的索引名?

elasticsearch - 简单请求(A或B)和(C或D)

elasticsearch - 万一主节点发生故障,Elasticsearch如何切换到另一个节点?

elasticsearch - Docker swarm集群和elasticsearch,使用约束将服务绑定(bind)到特定节点

php - Elasticsearch - 上一个/下一个功能

c# - 使用高级Nest Client和AutoMap进行PUT映射

elasticsearch - FieldIndexOption不适用于嵌套对象