【问题标题】:Nest - ReindexingNest - 重新索引
【发布时间】:2016-07-30 05:31:37
【问题描述】:

Elasticsearch 在 Elasticsearch 2.3.0 中发布了他们新的 Reindex API,当前版本的 NEST (2.1.1) 是否使用了这个 API?如果没有,是否有计划这样做? 我知道当前版本有一个 reindex 方法,但它会强制您创建新索引。对于我的用例,索引已经存在。

我们将不胜感激任何反馈/见解。谢谢!

【问题讨论】:

    标签: elasticsearch nest reindex elasticsearch-net


    【解决方案1】:

    这类问题最好在github issues for NEST 上提出,因为项目的提交者将能够给出最佳答案:)

    A commit went in on 6 April to map the new Reindex API 在 Elasticsearch 2.3.0 中可用,以及 Task Management APIUpdate By Query 等其他功能。这进入了NEST 2.3.0

    NEST 2.x 已经包含一个用于重新索引的助手,它使用扫描/滚动并返回一个IObservable<IReindexResponse<T>>,可用于观察进度

    public class Document {}
    
    var observable = client.Reindex<Document>("from-index", "to-index", r => r
        // settings to use when creating to-index
        .CreateIndex(c => c
            .Settings(s => s
                .NumberOfShards(5)
                .NumberOfReplicas(2)
            )
        )
        // query to optionally limit documents re-indexed from from-index to to-index
        .Query(q => q.MatchAll())
        // the number of documents to reindex in each request.
        // NOTE: The number of documents in each request will actually be
        //     NUMBER * NUMBER OF SHARDS IN from-index
        // since reindex uses scan/scroll
        .Size(100)
    );
    
    ExceptionDispatchInfo e = null;
    var waitHandle = new ManualResetEvent(false);
    
    var observer = new ReindexObserver<Document>(
        onNext: reindexResponse =>
        {
            // do something with notification. Maybe log total progress
        },
        onError: exception =>
        {
            e = ExceptionDispatchInfo.Capture(exception);
            waitHandle.Set();
        },
        completed: () =>
        {
            // Maybe log completion, refresh the index, etc..
            waitHandle.Set();
        }
    );
    
    observable.Subscribe(observer);  
    
    // wait for the handle to be signalled
    waitHandle.Wait();
    
    // throw the exception if one was captured
    e?.Throw();
    

    查看ReIndex API tests 了解一些想法。

    新的 Reindex API 在客户端被命名为 client.ReIndexOnServer() 以区别于现有的 observable 实现。

    【讨论】:

      猜你喜欢
      • 2014-11-12
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 2021-08-15
      相关资源
      最近更新 更多