Skip to content

Instantly share code, notes, and snippets.

@wmeints
Created September 13, 2015 14:42
Show Gist options
  • Save wmeints/531f237809796f964151 to your computer and use it in GitHub Desktop.
Save wmeints/531f237809796f964151 to your computer and use it in GitHub Desktop.
Sample code for indexing logic in ASP.NET 5
using System;
using System.Threading.Tasks;
using Weblog.Models;
using Nest;
using Polly;
namespace Weblog.Services
{
public class PostIndexer: IPostIndexer
{
private static Policy CircuitBreaker = Policy
.Handle<Exception>()
.CircuitBreakerAsync(3, TimeSpan.FromSeconds(60));
private ElasticClient _client;
public PostIndexer()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
_client = new ElasticClient(settings);
}
public async Task IndexAsync(Post post)
{
// Indexes the content in ElasticSearch
// in the weblog index. Uses the post type
// mapping defined earlier.
await _client.IndexAsync(post,
(indexSelector) => indexSelector
.Index("weblog").Type("post"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment