Created
September 13, 2015 14:42
-
-
Save wmeints/531f237809796f964151 to your computer and use it in GitHub Desktop.
Sample code for indexing logic in ASP.NET 5
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
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