public void Initialize() { _LookFor = NestTestData.Session.Single<ElasticsearchProject>().Get(); _LookFor.Name = "one two three four"; var status = this._client.Index(_LookFor, i=>i.Refresh()).ConnectionStatus; Assert.True(status.Success, status.Result); }
public void IndexParameters() { var o = new ElasticsearchProject { Id = 1, Name = "Test" }; var result = this._client.Index(o, i=>i.Version(1)); var status = result.ConnectionStatus; StringAssert.Contains("version=1", status.RequestUrl); }
public void IndexThanDeleteDocumentById() { //arrange //create a new document to index ElasticsearchProject newDocument = new ElasticsearchProject { Country = "Mozambique", Followers = new List<Person>(), Id = DateTime.Now.Millisecond + 1500, //try to get this example out of the way of existing test data Name = "Test Document for 'IndexDocument' test" }; //act //index the new item this._client.Index<ElasticsearchProject>(newDocument, i=>i.Refresh()); //assert //grab document back from the index and make sure it is the same document var foundDocument = this._client.Source<ElasticsearchProject>(newDocument.Id); //Assert.Equal(newDocument.Country, foundDocument.Country); Assert.AreEqual(newDocument.Followers.Count, foundDocument.Followers.Count); Assert.AreEqual(newDocument.Id, foundDocument.Id); Assert.AreEqual(newDocument.Name, foundDocument.Name); //act //now remove the item that was added var response = this._client.Delete<ElasticsearchProject>(f=>f.Id(newDocument.Id).Refresh()); //assert //make sure getting by id returns nothing foundDocument = this._client.Source<ElasticsearchProject>(newDocument.Id); Assert.Null(foundDocument); }
public void PercolateDoc() { this.RegisterPercolateTest(); // I feel a little dirty. var c = this.Client; var name = "mypercolator"; var document = new ElasticsearchProject() { Id = 12, Name = "elasticsearch.pm", Country = "netherlands", LOC = 100000, //Too many :( }; var r = c.Percolate<ElasticsearchProject>(p=>p.Document(document)); Assert.True(r.IsValid); Assert.NotNull(r.Matches); Assert.True(r.Matches.Select(m=>m.Id).Contains(name)); var indexResult = c.Index(document); r = c.Percolate<ElasticsearchProject>(p=>p.Id(indexResult.Id)); Assert.True(r.IsValid); Assert.NotNull(r.Matches); Assert.True(r.Matches.Select(m=>m.Id).Contains(name)); var re = c.UnregisterPercolator<ElasticsearchProject>(name); }
public void PercolateTypedDoc() { this.RegisterPercolateTest(); // I feel a little dirty. var c = this._client; var name = "eclecticsearch"; var r = c.RegisterPercolator<ElasticsearchProject>(name, p => p .Query(q => q .Term(f => f.Country, "netherlands") ) ); Assert.True(r.IsValid); Assert.True(r.OK); var obj = new ElasticsearchProject() { Name = "NEST", Country = "netherlands", LOC = 100000, //Too many :( }; var percolateResponse = this._client.Percolate(obj); Assert.True(percolateResponse.IsValid); Assert.True(percolateResponse.OK); Assert.NotNull(percolateResponse.Matches); Assert.True(percolateResponse.Matches.Contains(name)); var re = c.UnregisterPercolator(name, ur=>ur.Index<ElasticsearchProject>()); }
public void IndexOpTypeDefault() { var o = new ElasticsearchProject { Id = 1, Name = "Test" }; var result = this._client.Index(o); var status = result.ConnectionStatus; StringAssert.DoesNotContain("op_type=create", status.RequestUrl); }
public void IndexUsingCreateFlag() { // Document to be indexed. var doc = new ElasticsearchProject { Country = "Mozambique", Followers = new List<Person>(), Id = idGen.Next(), Name = "Test Document for 'IndexDocument' Create Flag" }; // Index the document var indexResult = this._client.Index<ElasticsearchProject>(doc, i => i.OpType(OpTypeOptions.Create)); indexResult.IsValid.Should().BeTrue(); // Grab the indexed document. var foundDoc = this._client.Source<ElasticsearchProject>(doc.Id); // Check that the document was successfully indexed. Assert.NotNull(foundDoc); Assert.AreEqual(doc.Country, foundDoc.Country); Assert.AreEqual(doc.Followers.Count, foundDoc.Followers.Count); Assert.AreEqual(doc.Id, foundDoc.Id); Assert.AreEqual(doc.Name, foundDoc.Name); // Now try to index the document again while using the Create Flag var response = this._client.Index<ElasticsearchProject>(doc, i => i.OpType(OpTypeOptions.Create)); // Make sure the index request failed with HTTP status 409 since document with same id already exists. Assert.False(response.OK); Assert.AreEqual(System.Net.HttpStatusCode.Conflict, response.ConnectionStatus.Error.HttpStatusCode); }
public void TestIndexTimeout() { var timeout = 1; var s = new ConnectionSettings(Test.Default.Uri, ElasticsearchConfiguration.DefaultIndex) .SetMaximumAsyncConnections(Test.Default.MaximumAsyncConnections) .UsePrettyResponses(); var client = new ElasticClient(s); var newProject = new ElasticsearchProject { Name = "COBOLES", //COBOL ES client ? }; var t = client.IndexAsync<ElasticsearchProject>(newProject); t.Wait(1000); var r = t.Result; Assert.True(r.IsValid); Assert.IsNotNullOrEmpty(r.Id); var cs = r.ConnectionStatus; Assert.False(cs.Success); Assert.NotNull(cs.Error); Assert.NotNull(cs.Error.OriginalException); Trace.WriteLine(cs.Error.OriginalException); Assert.IsNotNullOrEmpty(cs.Error.ExceptionMessage); Assert.IsTrue(cs.Error.OriginalException is WebException); var we = cs.Error.OriginalException as WebException; Assert.IsTrue(cs.Error.ExceptionMessage.Contains("The request was canceled")); Assert.IsTrue(we.Status == WebExceptionStatus.RequestCanceled); Assert.True(t.IsCompleted, "task did not complete"); Assert.False(t.IsFaulted, "task was faulted, wich means the exception did not cleanly pass to ConnectionStatus"); }
public void SnapshotRestore() { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); var repositoryName = ElasticsearchConfiguration.NewUniqueIndexName(); var elasticsearchProject = new ElasticsearchProject() { Id = 1337, Name = "Coboles", Content = "COBOL elasticsearch client" }; Client.Index(elasticsearchProject, i=>i.Index(indexName).Refresh(true)); 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(indexName) .WaitForCompletion(true) .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 d = ElasticsearchConfiguration.DefaultIndex; var restoreResponse = this.Client.Restore(repositoryName, backupName, r => r .WaitForCompletion(true) .RenamePattern(d + "_(.+)") .RenameReplacement(d + "_restored_$1") .Index(indexName) .IgnoreUnavailable(true)); var restoredIndexName = indexName.Replace(d + "_", d + "_restored_"); restoreResponse.IsValid.Should().BeTrue(); restoreResponse.Snapshot.Should().NotBeNull(); restoreResponse.Snapshot.Name.Should().Be(backupName); restoreResponse.Snapshot.Indices.Should().Equal(new string[] { restoredIndexName }); var indexExistsResponse = this.Client.IndexExists(f => f.Index(restoredIndexName)); indexExistsResponse.Exists.Should().BeTrue(); var coboles = this.Client.Source<ElasticsearchProject>(elasticsearchProject.Id, restoredIndexName); coboles.Should().NotBeNull(); coboles.Name.Should().Be(elasticsearchProject.Name); var deleteReposResult = this.Client.DeleteRepository(repositoryName); deleteReposResult.IsValid.Should().BeTrue(); deleteReposResult.Acknowledged.Should().BeTrue(); }
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 Initialize() { _LookFor = NestTestData.Session.Single<ElasticsearchProject>().Get(); _LookFor.Name = "mmm"; var status = this.Client.Index(_LookFor, i=>i.Refresh()).ConnectionStatus; Assert.True(status.Success, status.ResponseRaw.Utf8String()); }
public void IndexOpTypeCreate() { var o = new ElasticsearchProject { Id = 1, Name = "Test" }; var result = this._client.Index(o, i => i.OpType(OpTypeOptions.Create)); var status = result.ConnectionStatus; StringAssert.Contains("op_type=create", status.RequestUrl); }
public void IdPropertyNotMapped_IdIsInferred() { var settings = new ConnectionSettings(); var client = new ElasticClient(settings, connection: new InMemoryConnection()); var project = new ElasticsearchProject { Id = 123 }; Assert.AreEqual(project.Id.ToString(), client.Infer.Id<ElasticsearchProject>(project)); }
public void ElasticsearchNETSupportsLongs() { var o = new ElasticsearchProject { Id = 1, Name = "Test" }; var versionString = DateTime.Now.ToString("yyyyMMddHHmmssFFF"); var version = long.Parse(versionString); var result = this._client.Raw.Index("index", "type", o, i=>i.Version(version)); StringAssert.Contains("version=" + versionString, result.RequestUrl); }
public void NestSupportsLongs() { var o = new ElasticsearchProject { Id = 1, Name = "Test" }; var versionString = DateTime.Now.ToString("yyyyMMddHHmmssFFF"); var version = long.Parse(versionString); var result = this._client.Index(o, i=>i.Version(version)); var status = result.ConnectionStatus; StringAssert.Contains("version=" + versionString, status.RequestUrl); }
public PercolateRequestTests() { var doc = new ElasticsearchProject() { Id = 19, Name = "Hello" }; var request = new PercolateRequest<ElasticsearchProject>(doc) { Query = Query<ElasticsearchProject>.Term("color", "blue") }; var response = this._client.Percolate<ElasticsearchProject>(request); this._status = response.ConnectionStatus; }
public void MapNumericIdProperty() { var settings = new ConnectionSettings() .MapIdPropertyFor<ElasticsearchProject>(p => p.LongValue); var client = new ElasticClient(settings, connection: new InMemoryConnection()); var project = new ElasticsearchProject { LongValue = 123 }; Assert.AreEqual(project.LongValue.ToString(), client.Infer.Id<ElasticsearchProject>(project)); }
public void MapStringIdProperty() { var settings = new ConnectionSettings() .MapIdPropertyFor<ElasticsearchProject>(p => p.Name); var client = new ElasticClient(settings, connection: new InMemoryConnection()); var project = new ElasticsearchProject { Name = "foo" }; Assert.AreEqual(project.Name, client.Infer.Id<ElasticsearchProject>(project)); }
public void UpdateUsingPartial() { var originalProject = new ElasticsearchProject { Id = 1, Name = "NeST", Country = "UK" }; var partialUpdate = new PartialElasticSearchProject { Name = "NEST", Country = "Netherlands" }; var s = new UpdateDescriptor<ElasticsearchProject, PartialElasticSearchProject>() .IdFrom(originalProject) //only used to infer the id .Doc(partialUpdate); //the actual partial update statement; this.JsonEquals(s, MethodInfo.GetCurrentMethod()); }
public void Initialize() { _LookFor = NestTestData.Session.Single<ElasticsearchProject>().Get(); _MissingField = f => f.Name; _ExistsField = f => f.Id; // missing _LookFor.Name = null; var status = this.Client.Index(_LookFor, i=>i.Refresh()).ConnectionStatus; Assert.True(status.Success, status.ResponseRaw.Utf8String()); }
public void TestIndex() { var newProject = new ElasticsearchProject { Name = "COBOLES", //COBOL ES client ? }; var t = this._client.IndexAsync<ElasticsearchProject>(newProject); t.Wait(); Assert.True(t.Result.IsValid); Assert.True(t.IsCompleted, "task did not complete"); Assert.True(t.IsCompleted, "task did not complete"); }
public UpdateRequestTests() { var project = new ElasticsearchProject { Id = 1 }; var request = new UpdateRequest<ElasticsearchProject, object>(project) { Doc = new { Name = "NEST" }, DocAsUpsert = true }; var response = this._client.Update(request); _status = response.ConnectionStatus; }
public IndexRequestTests() { var newProject = new ElasticsearchProject { Id = 15, Name = "Some awesome new elasticsearch project" }; var request = new IndexRequest<ElasticsearchProject>(newProject) { Replication = Replication.Async }; //TODO Index(request) does not work as expected var response = this._client.Index<ElasticsearchProject>(request); this._status = response.ConnectionStatus; }
public void MapIdPropertiesForMultipleTypes() { var settings = new ConnectionSettings() .MapIdPropertyFor<ElasticsearchProject>(p => p.LongValue) .MapIdPropertyFor<Person>(p => p.Id) .MapIdPropertyFor<Product>(p => p.Name); var client = new ElasticClient(settings, connection: new InMemoryConnection()); var project = new ElasticsearchProject { LongValue = 1 }; Assert.AreEqual(project.LongValue.ToString(), client.Infer.Id<ElasticsearchProject>(project)); var person = new Person { Id = 2 }; Assert.AreEqual(person.Id.ToString(), client.Infer.Id<Person>(person)); var product = new Product { Name = "foo" }; Assert.AreEqual(product.Name, client.Infer.Id<Product>(product)); }
public BulkRequestTests() { var newProject = new ElasticsearchProject { Id = 4, Name = "new-project" }; var request = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Operations = new List<IBulkOperation> { { new BulkIndexOperation<ElasticsearchProject>(newProject) { Id= "2"}}, { new BulkDeleteOperation<ElasticsearchProject>(6) }, { new BulkCreateOperation<ElasticsearchProject>(newProject) { Id = "6" } }, { new BulkUpdateOperation<ElasticsearchProject, object>(newProject, new { name = "new-project2"}) { Id = "3" } }, } }; var response = this._client.Bulk(request); this._status = response.ConnectionStatus; }
public void TestSuggest() { var tempIndex = ElasticsearchConfiguration.NewUniqueIndexName(); var elasticsearchProject = new ElasticsearchProject { Id = 1337, Name = "Coboles", Content = "COBOL elasticsearch client" }; var indexResponse = this._client.Index(elasticsearchProject, i=>i.Refresh().Index(tempIndex)); indexResponse.IsValid.Should().BeTrue(); var existsResponse = this._client.DocumentExists<ElasticsearchProject>(d => d.Object(elasticsearchProject).Index(tempIndex)); existsResponse.IsValid.Should().BeTrue(); existsResponse.Exists.Should().BeTrue(); existsResponse.ConnectionStatus.RequestMethod.Should().Be("HEAD"); var doesNotExistsResponse = this._client.DocumentExists<ElasticsearchProject>(d => d.Object(elasticsearchProject).Index(tempIndex + "-random")); doesNotExistsResponse.IsValid.Should().BeTrue(); doesNotExistsResponse.Exists.Should().BeFalse(); }
public void IndexDefaultValue() { var newProject = new ElasticsearchProject { Id = 2000, Name = "TempProject", LOC = 0, LongValue = 0, DoubleValue = 0, FloatValue = 0, FloatValues = new[] { 0f }, BoolValue = false }; var response = this._client.Index(newProject); var connectionStatus = response.ConnectionStatus; StringAssert.Contains(@"""id"": 2000", connectionStatus.Request); StringAssert.Contains(@"""loc"": 0", connectionStatus.Request); StringAssert.Contains(@"""longValue"": 0", connectionStatus.Request); StringAssert.Contains(@"""floatValue"": 0.0", connectionStatus.Request); StringAssert.Contains(@"""doubleValue"": 0.0", connectionStatus.Request); StringAssert.Contains(@"""boolValue"": false", connectionStatus.Request); }
public void IndexThanDeleteDocumentById() { var newIndex = IntegrationSetup.CreateNewIndexWithData(this.Client); var newDocument = new ElasticsearchProject { Country = "Mozambique", Followers = new List<Person>(), Id = DateTime.Now.Millisecond + 1500, Name = "Test Document for 'IndexDocument' test" }; this.Client.Index<ElasticsearchProject>(newDocument, i=>i.Index(newIndex).Refresh()); var foundDocument = this.Client.Source<ElasticsearchProject>(newDocument.Id, newIndex); Assert.AreEqual(newDocument.Followers.Count, foundDocument.Followers.Count); Assert.AreEqual(newDocument.Id, foundDocument.Id); Assert.AreEqual(newDocument.Name, foundDocument.Name); var response = this.Client.Delete<ElasticsearchProject>(f=>f.Id(newDocument.Id).Index(newIndex).Refresh()); foundDocument = this.Client.Source<ElasticsearchProject>(newDocument.Id, newIndex); Assert.Null(foundDocument); }
public void PercolateTypedDocWithQuery() { var c = this.Client; var name = "eclecticsearch" + ElasticsearchConfiguration.NewUniqueIndexName(); var re = c.UnregisterPercolator<ElasticsearchProject>(name); 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<ElasticsearchProject>(p => p .Document(obj) .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<ElasticsearchProject>(p => p .Query(q => q.Term("color", "green")) .Document(obj) ); Assert.True(percolateResponse.IsValid); Assert.NotNull(percolateResponse.Matches); Assert.False(percolateResponse.Matches.Select(m=>m.Id).Contains(name)); var countPercolateReponse = this.Client.PercolateCount(obj,p => p .Query(q=>q.Match(m=>m.OnField("color").Query("blue"))) ); countPercolateReponse.IsValid.Should().BeTrue(); countPercolateReponse.Total.Should().Be(1); re = c.UnregisterPercolator<ElasticsearchProject>(name); }
public void PercolateTypedDoc() { this.RegisterPercolateTest(); // I feel a little dirty. var c = this.Client; var name = "eclecticsearch"; var r = c.RegisterPercolator<ElasticsearchProject>(name, p => p .Query(q => q .Term(f => f.Country, "netherlands") ) ); Assert.True(r.IsValid); Assert.True(r.Created); var obj = new ElasticsearchProject() { Name = "NEST", Country = "netherlands", LOC = 100000, //Too many :( }; var percolateResponse = this.Client.Percolate<ElasticsearchProject>(p=>p .Document(obj) .TrackScores(false) ); Assert.True(percolateResponse.IsValid); Assert.NotNull(percolateResponse.Matches); Assert.True(percolateResponse.Matches.Select(m=>m.Id).Contains(name)); var re = c.UnregisterPercolator<ElasticsearchProject>(name); }