Created
March 30, 2015 00:35
-
-
Save gbellmann/16105655737a99612557 to your computer and use it in GitHub Desktop.
This file contains 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
public void UploadDocuments(SearchIndexClient indexClient) | |
{ | |
var documents = new Pelicula[] | |
{ | |
new Pelicula | |
{ | |
PeliculaId = "tt2084970", | |
Titulo = "El código enigma", | |
Director = "Morten Tyldum", | |
Actores = new [] { "Benedict Cumberbatch", "Keira Knightley", "Matthew Goode" }, | |
Genero = "Drama", | |
Rating = 8, | |
FechaEstreno = new DateTimeOffset(2014, 12, 25, 0, 0, 0, TimeSpan.Zero), | |
}, | |
new Pelicula | |
{ | |
PeliculaId = "tt0816692", | |
Titulo = "Interestelar", | |
Director = "Christopher Nolan", | |
Actores = new [] { "Matthew McConaughey", "Anne Hathaway", "Jessica Chastain" }, | |
Genero = "Ciencia Ficción", | |
Rating = 9, | |
FechaEstreno = new DateTimeOffset(2014, 11, 7, 0, 0, 0, TimeSpan.Zero), | |
}, | |
new Pelicula | |
{ | |
PeliculaId = "tt1809398", | |
Titulo = "Inquebrantable", | |
Director = "Angelina Jolie", | |
Actores = new [] { "Jack O'Connell", "Takamasa Ishihara", "Domhnall Gleeson" }, | |
Genero = "Drama", | |
Rating = 7, | |
FechaEstreno = new DateTimeOffset(2014, 12, 25, 0, 0, 0, TimeSpan.Zero), | |
}, | |
new Pelicula | |
{ | |
PeliculaId = "tt2278388", | |
Titulo = "El gran hotel Budapest", | |
Director = "Wes Anderson", | |
Actores = new [] { "Ralph Fiennes", "F. Murray Abraham", "Mathieu Amalric" }, | |
Genero = "Comedia", | |
Rating = 8, | |
FechaEstreno = new DateTimeOffset(2014, 3, 28, 0, 0, 0, TimeSpan.Zero), | |
}, | |
new Pelicula | |
{ | |
PeliculaId = "tt2562232", | |
Titulo = "Birdman o (La inesperada virtud de la ignorancia)", | |
Director = "Alejandro González Iñárritu", | |
Actores = new [] { "Michael Keaton", "Zach Galifianakis", "Edward Norton" }, | |
Genero = "Drama", | |
Rating = 8, | |
FechaEstreno = new DateTimeOffset(2014, 11, 14, 0, 0, 0, TimeSpan.Zero), | |
}, | |
}; | |
try | |
{ | |
indexClient.Documents.Index(IndexBatch.Create(documents.Select(doc => IndexAction.Create(doc)))); | |
} | |
catch (IndexBatchException e) | |
{ | |
// Si el servicio está bajo carga, el indexado puede fallar para alguno de los documentos en el lote. | |
// Dependiendo de nuestra aplicación, deberemos tomar medidas para compensar este problema, como | |
// esperar y reintentar, para el ejemplo, simplemente los mostramos en la consola. | |
Console.WriteLine( | |
"No se pudo indexar los siguientes documentos: {0}", | |
String.Join(", ", e.IndexResponse.Results.Where(r => !r.Succeeded).Select(r => r.Key))); | |
} | |
// Esperamos que se complete el indexado (ya que es asíncrono). | |
Thread.Sleep(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment