【问题标题】:Reindexing using NEST V5.4 - ElasticSearch使用 NEST V5.4 重新索引 - ElasticSearch
【发布时间】:2017-12-29 05:39:10
【问题描述】:

我对 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:

【问题讨论】:

    标签: elasticsearch indexing nest reindex


    【解决方案1】:

    搜索了 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

    【讨论】:

    • 很高兴你最终找到了 NatsuDragonEye!如果您需要阻止 .Wait(TimeSpan, onNext; (x)=&gt;) 助手,我们还会公开它们。
    • 如果 ElasticSearch 可以在 NEST API 上添加有关此主题的更多信息,那就太好了。
    猜你喜欢
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多