/** * ==== Custom indexing client * * Since Elasticsearch will automatically reroute ingest requests to ingest nodes, you don't have to specify or configure any routing * information. However, if you're doing heavy ingestion and have dedicated ingest nodes, it makes sense to send index requests to * these nodes directly, to avoid any extra hops in the cluster. * * The simplest way to achieve this is to create a dedicated "indexing" client instance, and use it for indexing requests. */ public void CustomClient() { var pool = new StaticNodePool(new [] //<1> list of ingest nodes { new Uri("http://ingestnode1:9200"), new Uri("http://ingestnode2:9200"), new Uri("http://ingestnode3:9200") }); var settings = new ElasticsearchClientSettings(pool); var indexingClient = new ElasticsearchClient(settings); }
public async Task BadBulkRequestFeedsToOnError() { var index = CreateIndexName(); var documents = await CreateIndexAndReturnDocuments(index); var seenPages = 0; var badUris = new[] { new Uri("http://test.example:9201"), new Uri("http://test.example:9202") }; var pool = new StaticNodePool(badUris); var badClient = new ElasticsearchClient(new ElasticsearchClientSettings(pool)); var observableBulk = badClient.BulkAll(documents, f => f .MaxDegreeOfParallelism(8) .BackOffTime(TimeSpan.FromSeconds(10)) .BackOffRetries(2) .Size(Size) .RefreshOnCompleted() .Index(index) ); Exception ex = null; var handle = new ManualResetEvent(false); using (observableBulk.Subscribe( b => Interlocked.Increment(ref seenPages), e => { ex = e; handle.Set(); }, () => handle.Set() )) { handle.WaitOne(TimeSpan.FromSeconds(60)); seenPages.Should().Be(0); var clientException = ex.Should().NotBeNull().And.BeOfType <TransportException>().Subject; clientException.Message.Should().StartWith("BulkAll halted after attempted bulk failed over all the active nodes"); } }