Created
          June 12, 2014 18:33 
        
      - 
      
 - 
        
Save ThomasArdal/1f69720da208f1863ae7 to your computer and use it in GitHub Desktop.  
    Elasticsearch migration c# example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace ConsoleApplication1 | |
| { | |
| public class Customer | |
| { | |
| public int Zipcode { get; set; } | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using Nest; | |
| namespace ConsoleApplication1 | |
| { | |
| public class Program | |
| { | |
| public static void Main(string[] args) | |
| { | |
| var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/")); | |
| connectionSettings.SetDefaultIndex("customers"); | |
| var elasticClient = new ElasticClient(connectionSettings); | |
| elasticClient.CreateIndex("customers-v1"); | |
| elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v1"))); | |
| elasticClient.Map<Customer>(d => | |
| d.Properties(p => p.Number(n => n.Name(name => name.Zipcode).Index(NonStringIndexOption.not_analyzed)))); | |
| elasticClient.Index(new Customer { Zipcode = 8000 }); | |
| 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)))))); | |
| var o = new ReindexObserver<Customer>(onError: e => { }); | |
| reindex.Subscribe(o); | |
| elasticClient.DeleteIndex(d => d.Index("customers-v1")); | |
| elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v2"))); | |
| } | |
| } | |
| } | 
@mayureshs you would do something like this:
client.ReindexOnServer(r => r
    .Source(s => s
        .Index(sourceIndex))
    .Destination(d => d
        .Index(destinationIndex)));Thank you. This worked for me
client.ReindexOnServer(r => r .Source(s => s.Index(currentIndexName) .Query<Customer>(q => q .Term(m => m .Field(f => f.EmailAddress)))) .Destination(d => d.Index(newIndexName)) .WaitForCompletion());
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
FromIndex() seems to be deprecated in v6.x and higher. Is there any update to how you would do it in higher versions ?