public void Initialize() { _client.IsValid.Should().BeTrue(); _LookFor = NestTestData.Session.Single <ElasticSearchProject>().Get(); _LookFor.Name = "one two three four"; var status = this._client.Index(_LookFor, new IndexParameters { Refresh = true }).ConnectionStatus; Assert.True(status.Success, status.Result); }
public void IndexOpTypeCreate() { var o = new ElasticSearchProject { Id = 1, Name = "Test" }; var result = this._client.Index(o, new IndexParameters { OpType = OpType.Create }); var status = result.ConnectionStatus; StringAssert.Contains("op_type=create", status.RequestUrl); }
public void IndexSupportsVersioning() { var o = new ElasticSearchProject { Id = 1, Name = "Test" }; var result = this._client.Index(o, new IndexParameters { Version = "1" }); var status = result.ConnectionStatus; StringAssert.Contains("version=1", status.RequestUrl); }
public void TestIndex() { var newProject = new ElasticSearchProject { Name = "COBOLES", //COBOL ES client ? }; var t = this.ConnectedClient.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"); }
/// <summary> /// Create document for test. /// </summary> protected override void ResetIndexes() { base.ResetIndexes(); var client = this.ConnectedClient; if (client.IsValid) { _LookFor = NestTestData.Session.Single <ElasticSearchProject>().Get(); _LookFor.Name = "one two three four"; var status = this.ConnectedClient.Index(_LookFor).ConnectionStatus; Assert.True(status.Success, status.Result); Assert.True(this.ConnectedClient.Flush <ElasticSearchProject>().OK, "Flush"); } }
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>() .Object(originalProject) //only used to infer the id .Document(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, new IndexParameters { Refresh = true }).ConnectionStatus; Assert.True(status.Success, status.Result); }
/// <summary> /// Create document for test. /// </summary> protected override void ResetIndexes() { base.ResetIndexes(); var client = this.ConnectedClient; if (client.IsValid) { _LookFor = NestTestData.Session.Single <ElasticSearchProject>().Get(); _MissingField = f => f.Name; _ExistsField = f => f.Id; // missing _LookFor.Name = null; var status = this.ConnectedClient.Index(_LookFor).ConnectionStatus; Assert.True(status.Success, status.Result); Assert.True(this.ConnectedClient.Flush <ElasticSearchProject>().OK, "Flush"); } }
public void IndexThenDeleteUsingRefresh() { //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.ConnectedClient.Index(newDocument, new IndexParameters { Refresh = true }); //assert //grab document back from the index and make sure it is the same document var foundDocument = this.ConnectedClient.Get <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 this.ConnectedClient.Delete(newDocument, new DeleteParameters() { Refresh = true }); //assert //make sure getting by id returns nothing foundDocument = this.ConnectedClient.Get <ElasticSearchProject>(newDocument.Id); Assert.Null(foundDocument); }
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); }
[Test, Ignore] //figure out a better way to test this. public void TestIndexTimeout() { var timeout = 1; var s = new ConnectionSettings(Test.Default.Host, Test.Default.Port, timeout) .SetDefaultIndex(Test.Default.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 DoFilterTest(Func <FilterDescriptor <ElasticSearchProject>, Nest.BaseFilter> filter, ElasticSearchProject project, bool queryMustHaveResults) { var filterId = Filter <ElasticSearchProject> .Term(e => e.Id, project.Id); var results = this._client.Search <ElasticSearchProject>( s => s.Filter(ff => ff.And( f => f.Term(e => e.Id, project.Id), filter )) ); Assert.True(results.IsValid, results.ConnectionStatus.Result); Assert.True(results.ConnectionStatus.Success, results.ConnectionStatus.Result); Assert.AreEqual(queryMustHaveResults ? 1 : 0, results.Total); }