private static void UploadDocuments(ISearchIndexClient indexClient)
{
var hotels = new Hotel[]
{
new Hotel()
{
HotelId = "1",
BaseRate = 199.0,
Description = "Best hotel in town",
DescriptionFr = "Meilleur hôtel en ville",
HotelName = "Fancy Stay",
Category = "Luxury",
Tags = new[] { "pool", "view", "wifi", "concierge" },
ParkingIncluded = false,
SmokingAllowed = false,
LastRenovationDate = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.Zero),
Rating = 5,
Location = GeographyPoint.Create(47.678581, -122.131577)
},
new Hotel()
{
HotelId = "2",
BaseRate = 79.99,
Description = "Cheapest hotel in town",
DescriptionFr = "Hôtel le moins cher en ville",
HotelName = "Roach Motel",
Category = "Budget",
Tags = new[] { "motel", "budget" },
ParkingIncluded = true,
SmokingAllowed = true,
LastRenovationDate = new DateTimeOffset(1982, 4, 28, 0, 0, 0, TimeSpan.Zero),
Rating = 1,
Location = GeographyPoint.Create(49.678581, -122.131577)
},
new Hotel()
{
HotelId = "3",
BaseRate = 129.99,
Description = "Close to town hall and the river"
}
};
var batch = IndexBatch.Upload(hotels);
try
{
indexClient.Documents.Index(batch);
}
catch (IndexBatchException e)
{
// Sometimes when your Search service is under load, indexing will fail for some of the documents in
// the batch. Depending on your application, you can take compensating actions like delaying and
// retrying. For this simple demo, we just log the failed document keys and continue.
Console.WriteLine(
"Failed to index some of the documents: {0}",
String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
}
Console.WriteLine("Waiting for documents to be indexed...\n");
Thread.Sleep(2000);
}