Reindexing using NEST V5.4 - ElasticSearch

后端 未结 1 464
无人及你
无人及你 2021-01-17 06:31

I\'m quite new to ElasticSearch. I\'m trying to reindex a index in order to rename it. I\'m using NEST API v5.4. I saw this example:

var reindex =
    elast         


        
相关标签:
1条回答
  • 2021-01-17 07:25

    After search for 2 long days I found out the solution to reindex a index. In order to solve future problems, I'll provide my solution.

    Nest Version - 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()));
    

    the ReIndex method returns a cold IObservable on which you have to call .Subscribe() to kick off everything.

    So, you need to add it to your code:

    var o = new ReindexObserver(
                onError: (e) => { //do something },
                onCompleted: () => { //do something });
    reindex.Subscribe(o);
    

    Useful links to check this are:

    Documentation

    Issue 2660 on GitHub

    Issue 2771 on GitHub

    0 讨论(0)
提交回复
热议问题