public void NotAnalyzedReturnsOneItem() { var index = ElasticsearchConfiguration.NewUniqueIndexName(); var x = this._client.CreateIndex(index, s => s .AddMapping <ElasticsearchProject>(m => m.MapFromAttributes()) ); Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString()); var typeMappingResponse = this._client.GetMapping(gm => gm.Index(index).Type("elasticsearchprojects")); var typeMapping = typeMappingResponse.Mapping; var mapping = typeMapping.Properties["country"] as StringMapping; Assert.NotNull(mapping); Assert.AreEqual(FieldIndexOption.not_analyzed, mapping.Index); var indexResult = this._client.Index(new ElasticsearchProject { Country = "The Royal Kingdom Of The Netherlands" }, i => i.Index(index).Refresh()); Assert.IsTrue(indexResult.IsValid); var result = this._client.Search <ElasticsearchProject>(s => s .Index(index) .FacetTerm(ft => ft.OnField(f => f.Country)) .MatchAll() ); var facets = result.FacetItems <TermItem>(f => f.Country); Assert.AreEqual(1, facets.Count()); Assert.AreEqual("The Royal Kingdom Of The Netherlands", facets.FirstOrDefault().Term); }
public void Setup() { _indexName = ElasticsearchConfiguration.NewUniqueIndexName(); _repositoryName = ElasticsearchConfiguration.NewUniqueIndexName(); _snapshotName = ElasticsearchConfiguration.NewUniqueIndexName(); var descriptor = new BulkDescriptor(); _indexedElements = new List <ElasticsearchProject>(); for (int i = 0; i < 100; i++) { var elementToIndex = new ElasticsearchProject() { Id = i, Name = "Coboles", Content = "COBOL elasticsearch client" }; descriptor = descriptor.Index <ElasticsearchProject>(d => d.Index(_indexName).Document(elementToIndex)); _indexedElements.Add(elementToIndex); } var bulkResponse = this.Client.Bulk(d => descriptor); this.Client.CreateRepository(_repositoryName, r => r .FileSystem(@"local\\path", o => o .Compress() .ConcurrentStreams(10))); }
public void AnalyzedReturnsMoreItems() { var index = ElasticsearchConfiguration.NewUniqueIndexName(); var x = this._client.CreateIndex(index, s => s .AddMapping <ElasticsearchProject>(m => m .MapFromAttributes() .Properties(pp => pp .String(pps => pps.Name(p => p.Country).Index(FieldIndexOption.analyzed)) ) ) ); Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString()); var indexResult = this._client.Index( new ElasticsearchProject { Country = "The Royal Kingdom Of The Netherlands" }, i => i.Index(index).Refresh() ); Assert.IsTrue(indexResult.IsValid); var result = this._client.Search <ElasticsearchProject>(s => s .Index(index) .FacetTerm(ft => ft.OnField(f => f.Country)) .MatchAll() ); var facets = result.FacetItems <TermItem>(f => f.Country); Assert.AreEqual(5, facets.Count()); facets.Select(f => f.Term).Should().Contain("royal"); }
public void CreateARepositoryThenGetIt() { var repository = ElasticsearchConfiguration.NewUniqueIndexName(); var createReposResult = this.Client.CreateRepository(repository, r => r .FileSystem(@"local\\path", o => o .Compress() .ConcurrentStreams(10) ) ); createReposResult.IsValid.Should().BeTrue(); createReposResult.Acknowledged.Should().BeTrue(); var t = this.Client.GetRepository(new GetRepositoryRequest(repository)); t.IsValid.Should().BeTrue(); t.Repositories.Should().NotBeEmpty(); var repos = t.Repositories.First(); repos.Key.Should().Be(repository); repos.Value.Should().NotBeNull(); repos.Value.Type.Should().Be("fs"); repos.Value.Settings.Should().NotBeEmpty() .And.HaveCount(3) .And.ContainKey("compress") .And.ContainKey("concurrent_streams") .And.ContainKey("location"); var deleteReposResult = this.Client.DeleteRepository(repository); deleteReposResult.IsValid.Should().BeTrue(); deleteReposResult.Acknowledged.Should().BeTrue(); }
public void CreateAndDeleteRepository_ThenSnapshotWithoutWait() { var repositoryName = ElasticsearchConfiguration.NewUniqueIndexName(); var createReposResult = this.Client.CreateRepository(repositoryName, r => r .FileSystem(@"local\\path", o => o .Compress() .ConcurrentStreams(10) ) ); createReposResult.IsValid.Should().BeTrue(); createReposResult.Acknowledged.Should().BeTrue(); var backupName = ElasticsearchConfiguration.NewUniqueIndexName(); var snapshotResponse = this.Client.Snapshot(repositoryName, backupName, selector: f => f .Index(ElasticsearchConfiguration.NewUniqueIndexName()) .IgnoreUnavailable() .Partial()); snapshotResponse.IsValid.Should().BeTrue(); snapshotResponse.Accepted.Should().BeTrue(); snapshotResponse.Snapshot.Should().BeNull(); var deleteSnapshotReponse = this.Client.DeleteSnapshot(repositoryName, backupName); deleteSnapshotReponse.IsValid.Should().BeTrue(); var deleteReposResult = this.Client.DeleteRepository(repositoryName); deleteReposResult.IsValid.Should().BeTrue(); deleteReposResult.Acknowledged.Should().BeTrue(); }
public ElasticsearchSeeder( SeederConfiguration seederConfiguration, ElasticsearchConfiguration elasticsearchConfiguration) { _seederConfiguration = seederConfiguration; _elasticsearchConfiguration = elasticsearchConfiguration; }
public async void ConnectionPool_ThrowOnServerExceptions_ThrowsElasticsearchServerException_Async() { var uris = new [] { ElasticsearchConfiguration.CreateBaseUri(9200), ElasticsearchConfiguration.CreateBaseUri(9200), ElasticsearchConfiguration.CreateBaseUri(9200), }; var connectionPool = new StaticConnectionPool(uris); var client = new ElasticClient(new ConnectionSettings(connectionPool) .ThrowOnElasticsearchServerExceptions() .SetTimeout(1000) ); try { var index = ElasticsearchConfiguration.NewUniqueIndexName(); var create = await client.CreateIndexAsync(i => i.Index(index)); var close = await client.CloseIndexAsync(i => i.Index(index)); var result = await client.SearchAsync <ElasticsearchProject>(s => s.Index(index)); } catch (ElasticsearchServerException) { Assert.Pass("ElasticearchServerException caught"); } catch (Exception e) { Assert.Fail("Did not expect exception of type {0} to be caught", e.GetType().Name); } }
public void CreateIndexShouldNotThrowNullReference() { var settings = new IndexSettings(); settings.NumberOfReplicas = 1; settings.NumberOfShards = 5; settings.Settings.Add("index.refresh_interval", "10s"); settings.Settings.Add("merge.policy.merge_factor", "10"); settings.Settings.Add("search.slowlog.threshold.fetch.warn", "1s"); settings.Analysis.Analyzers.Add(new KeyValuePair <string, AnalyzerBase>("keyword", new KeywordAnalyzer())); settings.Analysis.Analyzers.Add(new KeyValuePair <string, AnalyzerBase>("simple", new SimpleAnalyzer())); settings.Mappings.Add(new RootObjectMapping { Name = "my_root_object", Properties = new Dictionary <PropertyNameMarker, IElasticType> { { "my_field", new StringMapping() { Name = "my_string_field " } } } }); Assert.DoesNotThrow(() => { var idxRsp = this.Client.CreateIndex(ElasticsearchConfiguration.NewUniqueIndexName(), i => i.InitializeUsing(settings)); Assert.IsTrue(idxRsp.IsValid, idxRsp.ConnectionStatus.ToString()); }); }
public void PutSingleAlias() { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse = this.Client.CreateIndex(indexName); createIndexResponse.IsValid.Should().BeTrue(); var result = this.Client.PutAlias(a => a .Index(indexName) .Name(aliasName) .Filter <ElasticsearchProject>(f => f .Term(p => p.Name, "nest") ) ); result.IsValid.Should().BeTrue(); var aliases = this.Client.GetAliasesPointingToIndex(indexName); aliases.Should().NotBeNull().And.HaveCount(1); var alias = aliases.First(); alias.Name.ShouldAllBeEquivalentTo(aliasName); alias.Filter.Should().NotBeNull(); alias.Filter.Term.Field.Should().Be("name"); alias.Filter.Term.Value.Should().Be("nest"); }
private static Task Main(string[] args) { SetupLogger(); return(Parser .Default .ParseArguments <Options>(args) .WithParsedAsync(async options => { ValidateArguments(options); Log.Logger.Information($"Data file path: {options.IndexDataFilePath}"); if (options.CreateIndexIfNotExists) { Log.Logger.Information($"Index creation body content: {options.IndexCreationBodyFilePath}"); } var seederConfiguration = new SeederConfiguration { CreateIndexIfNotExists = options.CreateIndexIfNotExists, DataFilePath = options.IndexDataFilePath, CreateIndexRequestBodyContentFilePath = options.IndexCreationBodyFilePath }; ElasticsearchConfiguration elasticConfiguration = GetElasticsearchConfiguration(); var seeder = new ElasticsearchSeeder(seederConfiguration, elasticConfiguration); await seeder.SeedAsync(); })); }
public void ReindexMinimal() { var toIndex = ElasticsearchConfiguration.NewUniqueIndexName(); var observable = this.Client.Reindex <object>(r => r .FromIndex(ElasticsearchConfiguration.DefaultIndex) .ToIndex(toIndex) ); var observer = new ReindexObserver <object>( onError: (e) => Assert.Fail(e.Message), completed: () => { var refresh = this.Client.Refresh(r => r.Indices(toIndex, ElasticsearchConfiguration.DefaultIndex)); var originalIndexCount = this.Client.Count(c => c .Index(ElasticsearchConfiguration.DefaultIndex) .Query(q => q.MatchAll()) ); var newIndexCount = this.Client.Count(c => c .Index(toIndex) .Query(q => q.MatchAll()) ); Assert.Greater(newIndexCount.Count, 0); Assert.AreEqual(originalIndexCount.Count, newIndexCount.Count); } ); observable.Subscribe(observer); }
public async void ConnectionPool_DoesNotThrowOnServerExceptions_ThrowsMaxRetryException_OnDeadNodes_Async() { var uris = new [] { ElasticsearchConfiguration.CreateBaseUri(9201), ElasticsearchConfiguration.CreateBaseUri(9202), ElasticsearchConfiguration.CreateBaseUri(9203), }; var connectionPool = new StaticConnectionPool(uris); var client = new ElasticClient(new ConnectionSettings(connectionPool) .SetTimeout(1000) ); try { var result = await client.SearchAsync <ElasticsearchProject>(s => s.MatchAll()); result.IsValid.Should().BeFalse(); } catch (MaxRetryException) { Assert.Pass("MaxRetryException caught"); } catch (Exception e) { Assert.Fail("Did not expect exception of type {0} to be caught", e.GetType().Name); } }
public async void SniffOnStartShouldOnlyHit9200_WithoutPing_Async() { var seeds = new[] { ElasticsearchConfiguration.CreateBaseUri(9202), ElasticsearchConfiguration.CreateBaseUri(9201), ElasticsearchConfiguration.CreateBaseUri(9200) }; var sniffingConnectionPool = new SniffingConnectionPool(seeds, randomizeOnStartup: false); var connectionSettings = new ConnectionSettings(sniffingConnectionPool) .SniffOnStartup(); var client = new ElasticClient(connectionSettings); var rootNode = await client.RootNodeInfoAsync(); var metrics = rootNode.ConnectionStatus.Metrics; //When the connectionpool is used for the first time the sniff call should already //know only 9200 is on and live, no need to ping metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); for (var i = 0; i < 3; i++) { rootNode = await client.RootNodeInfoAsync(); metrics = rootNode.ConnectionStatus.Metrics; metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); } }
public void AliasWithFilterPointingToIndex() { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse = this.Client.CreateIndex(indexName, c => c .NumberOfReplicas(0) .NumberOfShards(1) ); createIndexResponse.IsValid.Should().BeTrue(); var aliasResponse = this.Client.Alias(a => a .Add(aa => aa .Alias(aliasName) .IndexRouting("1") .Filter <dynamic>(f => f.Term("foo", "bar") ) ) ); aliasResponse.IsValid.Should().BeTrue(); var aliases = this.Client.GetAliasesPointingToIndex(indexName); aliases.Should().NotBeNull().And.HaveCount(1); var alias = aliases.First(); var filter = alias.Filter; filter.Should().NotBeNull(); var term = filter.Term; term.Should().NotBeNull(); term.Field.Should().Be("foo"); term.Value.Should().Be("bar"); }
public void ConnectionException_WithClientThatDoesNotThrow_StillThrows_Async() { var uri = ElasticsearchConfiguration.CreateBaseUri(9492); var client = new ElasticClient(new ConnectionSettings(uri).SetTimeout(500)); Assert.Throws <WebException>(async() => await client.RootNodeInfoAsync()); }
public void EmptyResponseShouldNotThrowError() { var result = this.Client.Connection.HeadSync(ElasticsearchConfiguration.CreateBaseUri(9200)); result.Success.Should().BeTrue(); result.OriginalException.Should().BeNull(); }
public void WhenPostExceedsHttpLimit_DoNotRetry_UsingConnectionPooling() { var pool = new StaticConnectionPool(new [] { new Uri("http://localhost:9200"), new Uri("http://127.0.0.1:9200"), }); var settings = new ConnectionSettings(pool); var client = new ElasticClient(settings); var index = ElasticsearchConfiguration.NewUniqueIndexName(); var projects = NestTestData.Data; var people = NestTestData.People; var boolTerms = NestTestData.BoolTerms; var bulk = client.Bulk(b => b .FixedPath(index) .IndexMany(projects) .IndexMany(people) .IndexMany(boolTerms) ); bulk.IsValid.Should().BeFalse(); bulk.ConnectionStatus.NumberOfRetries.Should().Be(0); }
public ReturnTypeTests() { var settings = ElasticsearchConfiguration.Settings() .ExposeRawResponse(false); _clientThatDoesNotExpose = new ElasticClient(settings); }
public void FluentMappingReturnsResults() { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); this.Client.CreateIndex(indexName, settings => settings .Settings(s => s.Add("search.slowlog.threshold.fetch.warn", "1s")) .Analysis(x => { var descriptor = x.Analyzers(i => i.Add("autocomplete", new CustomAnalyzer { Tokenizer = new WhitespaceTokenizer().Type, Filter = new[] { new LowercaseTokenFilter().Type, "engram" } })); descriptor.TokenFilters(i => i.Add("engram", new EdgeNGramTokenFilter { MinGram = 3, MaxGram = 10 } )); return(descriptor); }) .AddMapping <TechnicalProduct>(m => MapTechnicalProduct(m, indexName))); var index = this.Client.GetIndexSettings(i => i.Index(indexName)); }
public void PercolateTypedDocWithQuery() { var c = this._client; var name = "eclecticsearch" + ElasticsearchConfiguration.NewUniqueIndexName(); var re = c.UnregisterPercolator(name, ur => ur.Index <ElasticsearchProject>()); var r = c.RegisterPercolator <ElasticsearchProject>(name, p => p .AddMetadata(md => md.Add("color", "blue")) .Query(q => q .Term(f => f.Country, "netherlands") ) ); Assert.True(r.IsValid); Assert.True(r.Created); c.Refresh(); var obj = new ElasticsearchProject() { Name = "NEST", Country = "netherlands", LOC = 100000, //Too many :( }; var percolateResponse = this._client.Percolate(obj, p => p.Query(q => q.Match(m => m.OnField("color").Query("blue")))); Assert.True(percolateResponse.IsValid); Assert.NotNull(percolateResponse.Matches); Assert.True(percolateResponse.Matches.Select(m => m.Id).Contains(name)); //should not match since we registered with the color blue percolateResponse = this._client.Percolate(obj, p => p.Query(q => q.Term("color", "green"))); Assert.True(percolateResponse.IsValid); Assert.NotNull(percolateResponse.Matches); Assert.False(percolateResponse.Matches.Select(m => m.Id).Contains(name)); re = c.UnregisterPercolator(name, ur => ur.Index <ElasticsearchProject>()); }
public void DeleteSingleAlias() { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse = this.Client.CreateIndex(indexName); createIndexResponse.IsValid.Should().BeTrue(); var putAliasResponse = this.Client.PutAlias(a => a .Index(indexName) .Name(aliasName) ); putAliasResponse.IsValid.Should().BeTrue(); var aliases = this.Client.GetAliasesPointingToIndex(indexName); aliases.Should().NotBeNull().And.HaveCount(1); var deleteAliasResponse = this.Client.DeleteAlias(new DeleteAliasRequest(indexName, aliasName)); deleteAliasResponse.IsValid.Should().BeTrue(); aliases = this.Client.GetAliasesPointingToIndex(indexName); aliases.Should().NotBeNull().And.HaveCount(0); }
public void CreateIndexWithWarmer() { var index = ElasticsearchConfiguration.NewUniqueIndexName(); var result = this.Client.CreateIndex(index, c => c .NumberOfReplicas(0) .NumberOfShards(1) .AddWarmer(wd => wd .Type <ElasticsearchProject>() .WarmerName("warmer_createindexwithwarmer") .Search <ElasticsearchProject>(s => s .Query(q => q .Term(p => p.Name, "strange-value") ) ) ) ); result.Should().NotBeNull(); result.IsValid.Should().BeTrue(); result.ConnectionStatus.Should().NotBeNull(); var warmerResult = this.Client.GetWarmer("warmer_createindexwithwarmer", w => w .Name("warmer_createindexwithwarmer") ); warmerResult.IsValid.Should().BeTrue(); warmerResult.Indices.Should().NotBeNull(); warmerResult.Indices.Should().ContainKey(index); warmerResult.Indices[index].Should().ContainKey("warmer_createindexwithwarmer"); var warmerMapping = warmerResult.Indices[index]["warmer_createindexwithwarmer"]; warmerMapping.Name.Should().Be("warmer_createindexwithwarmer"); //warmerMapping.Source.Should().Contain("\"strange-value\""); }
public void DeserializeOfStreamDoesNotHoldACopyOfTheResponse() { var uri = ElasticsearchConfiguration.CreateBaseUri(); var settings = new ConnectionSettings(uri, ElasticsearchConfiguration.DefaultIndex); IElasticClient client = new ElasticClient(settings); var results = client.Search <ElasticsearchProject>(s => s.MatchAll()); }
public void WebException_WithThrowingClient_ThrowsMappedException() { var uri = ElasticsearchConfiguration.CreateBaseUri(); var client = new ElasticClient(new ConnectionSettings(uri).ThrowOnElasticsearchServerExceptions()); var e = Assert.Throws <ElasticsearchServerException>(() => client.Search <ElasticsearchProject>(s => s.QueryRaw(@"{ ""badjson"" : {} }"))); e.ExceptionType.Should().Contain("SearchPhaseExecutionException"); }
public void ConnectionException_WithThrowingClient() { var uri = ElasticsearchConfiguration.CreateBaseUri(9494); var client = new ElasticClient(new ConnectionSettings(uri) .SetTimeout(500) .ThrowOnElasticsearchServerExceptions()); var e = Assert.Throws <WebException>(() => client.RootNodeInfo()); }
public void CreateAndValidateAndDeleteRepository_ThenSnapshotWithWait() { var repositoryName = ElasticsearchConfiguration.NewUniqueIndexName(); var createReposResult = this.Client.CreateRepository(repositoryName, r => r .FileSystem(@"local\\path", o => o .Compress() .ConcurrentStreams(10) ) ); createReposResult.IsValid.Should().BeTrue(); createReposResult.Acknowledged.Should().BeTrue(); // Repository verification added in ES 1.4 if (ElasticsearchConfiguration.CurrentVersion > new Version("1.3.9")) { var validateResponse = this.Client.VerifyRepository(new VerifyRepositoryRequest(repositoryName)); validateResponse.IsValid.Should().BeTrue(); validateResponse.Nodes.Should().NotBeEmpty(); var kv = validateResponse.Nodes.First(); kv.Key.Should().NotBeNullOrWhiteSpace(); kv.Value.Should().NotBeNull(); kv.Value.Name.Should().NotBeNullOrWhiteSpace(); } var backupName = ElasticsearchConfiguration.NewUniqueIndexName(); var snapshotResponse = this.Client.Snapshot(repositoryName, backupName, selector: f => f .WaitForCompletion(true) .Index(ElasticsearchConfiguration.NewUniqueIndexName()) .IgnoreUnavailable() .Partial()); snapshotResponse.IsValid.Should().BeTrue(); snapshotResponse.Accepted.Should().BeTrue(); snapshotResponse.Snapshot.Should().NotBeNull(); snapshotResponse.Snapshot.EndTimeInMilliseconds.Should().BeGreaterThan(0); snapshotResponse.Snapshot.StartTime.Should().BeAfter(DateTime.UtcNow.AddDays(-1)); var getSnapshotResponse = this.Client.GetSnapshot(repositoryName, backupName); getSnapshotResponse.IsValid.Should().BeTrue(); getSnapshotResponse.Snapshots.Should().NotBeEmpty(); var snapShot = getSnapshotResponse.Snapshots.First(); snapShot.StartTime.Should().BeAfter(DateTime.UtcNow.AddDays(-1)); var getAllSnapshotResponse = this.Client.GetSnapshot(repositoryName, "_all"); getAllSnapshotResponse.IsValid.Should().BeTrue(); getAllSnapshotResponse.Snapshots.Should().NotBeEmpty(); getAllSnapshotResponse.Snapshots.Count().Should().BeGreaterOrEqualTo(1); var deleteReposResult = this.Client.DeleteRepository(repositoryName); deleteReposResult.IsValid.Should().BeTrue(); deleteReposResult.Acknowledged.Should().BeTrue(); }
public async void FailoverShouldOnlyPingDeadNodes_Async() { var seeds = new[] { ElasticsearchConfiguration.CreateBaseUri(9202), ElasticsearchConfiguration.CreateBaseUri(9201), ElasticsearchConfiguration.CreateBaseUri(9200) }; var sniffingConnectionPool = new SniffingConnectionPool(seeds, randomizeOnStartup: false); var connectionSettings = new ConnectionSettings(sniffingConnectionPool); var client = new ElasticClient(connectionSettings); var rootNode = await client.RootNodeInfoAsync(); var metrics = rootNode.ConnectionStatus.Metrics; //ping 9202 + 9201 + 9200 and call 9200 metrics.Requests.Count.Should().Be(4); metrics.Requests[0].Node.Port.Should().Be(9202); metrics.Requests[0].RequestType.Should().Be(RequestType.Ping); metrics.Requests[0].EllapsedMilliseconds.Should().BeLessOrEqualTo(300); metrics.Requests[1].Node.Port.Should().Be(9201); metrics.Requests[1].RequestType.Should().Be(RequestType.Ping); metrics.Requests[1].EllapsedMilliseconds.Should().BeLessOrEqualTo(300); metrics.Requests[2].Node.Port.Should().Be(9200); metrics.Requests[2].RequestType.Should().Be(RequestType.Ping); metrics.Requests[2].EllapsedMilliseconds.Should().BeLessOrEqualTo(300); metrics.Requests[3].Node.Port.Should().Be(9200); metrics.Requests[3].RequestType.Should().Be(RequestType.ElasticsearchCall); metrics.Requests[3].EllapsedMilliseconds.Should().BeLessOrEqualTo(300); rootNode = await client.RootNodeInfoAsync(); metrics = rootNode.ConnectionStatus.Metrics; metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); rootNode = await client.RootNodeInfoAsync(); metrics = rootNode.ConnectionStatus.Metrics; metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); rootNode = await client.RootNodeInfoAsync(); metrics = rootNode.ConnectionStatus.Metrics; metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); rootNode = await client.RootNodeInfoAsync(); metrics = rootNode.ConnectionStatus.Metrics; metrics.Requests.Count.Should().Be(1); metrics.Requests[0].Node.Port.Should().Be(9200); metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall); }
public void GetDifferentMappingsFromMultipleIndices() { var indices = new[] { ElasticsearchConfiguration.NewUniqueIndexName(), ElasticsearchConfiguration.NewUniqueIndexName() }; var x = this.Client.CreateIndex(indices.First(), s => s .AddMapping <ElasticsearchProject>(m => m.MapFromAttributes()) .AddMapping <Person>(m => m.MapFromAttributes()) ); Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString()); x = this.Client.CreateIndex(indices.Last(), s => s .AddMapping <ElasticsearchProject>(m => m.MapFromAttributes()) .AddMapping <MockData.Domain.CustomGeoLocation>(m => m.MapFromAttributes()) ); Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString()); var response = this.Client.GetMapping(new GetMappingRequest(string.Join(",", indices), "*")); response.Should().NotBeNull(); response.Mappings.Should().NotBeEmpty() .And.HaveCount(2); foreach (var indexMapping in response.Mappings) { var indexName = indexMapping.Key; indices.Should().Contain(indexName); var mappings = indexMapping.Value; mappings.Should().NotBeEmpty().And.HaveCount(2); mappings.Should().Contain(m => m.TypeName == "elasticsearchprojects") .And.Contain(m => m.TypeName == (indexName == indices.First() ? "person" : "customgeolocation")); foreach (var mapping in mappings) { switch (mapping.TypeName) { case "elasticsearchprojects": TestElasticsearchProjectMapping(mapping.Mapping); break; case "person": TestPersonMapping(mapping.Mapping); break; case "customgeolocation": break; default: Assert.Fail("Unexpected mapping found {0}", mapping.TypeName); break; } } } }
public void Calling_Refresh_UsingHttpClientConnection_DoesNotThrow() { var settings = ElasticsearchConfiguration.Settings() .EnableCompressedResponses(true); var connection = new HttpClientConnection(settings); var client = new ElasticClient(settings, connection: connection); Assert.DoesNotThrow(() => client.Refresh()); Assert.DoesNotThrow(() => client.Get <ElasticsearchProject>(NestTestData.Data.First().Id)); Assert.DoesNotThrow(() => client.Ping()); }
public void IndicesPointingToAlias() { var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); var indexName1 = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse1 = this.Client.CreateIndex(indexName1); createIndexResponse1.IsValid.Should().BeTrue(); var aliasResponse1 = this.Client.Alias(a => a .Add(aa => aa .Index(indexName1) .Alias(aliasName) .IndexRouting("1") ) ); aliasResponse1.IsValid.Should().BeTrue(); var indexName2 = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse2 = this.Client.CreateIndex(indexName2); createIndexResponse2.IsValid.Should().BeTrue(); var aliasResponse2 = this.Client.Alias(a => a .Add(aa => aa .Index(indexName2) .Alias(aliasName) .IndexRouting("1") ) ); aliasResponse2.IsValid.Should().BeTrue(); var indexName3 = ElasticsearchConfiguration.NewUniqueIndexName(); var createIndexResponse3 = this.Client.CreateIndex(indexName3); createIndexResponse3.IsValid.Should().BeTrue(); var aliasResponse3 = this.Client.Alias(a => a .Add(aa => aa .Index(indexName3) .Alias(aliasName) .IndexRouting("1") ) ); aliasResponse3.IsValid.Should().BeTrue(); var indices = this.Client.GetIndicesPointingToAlias(aliasName); indices.Should().NotBeNull().And.HaveCount(3); indices.ShouldAllBeEquivalentTo(new[] { indexName1, indexName2, indexName3 }); }