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 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 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 IndexThanDeleteDocumentByObject() { var newIndex = IntegrationSetup.CreateNewIndexWithData(this.Client); var 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(newDocument, i => i.Refresh().Index(newIndex)); //assert //grab document back from the index and make sure it is the same document var foundDocument = this.Client.Source <ElasticsearchProject>(newDocument.Id, newIndex); //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.Client.Delete <ElasticsearchProject>(f => f.IdFrom(newDocument).Refresh().Index(newIndex)); //assert //make sure getting by id returns nothing foundDocument = this.Client.Source <ElasticsearchProject>(newDocument.Id, newIndex); Assert.Null(foundDocument); }
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 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 IndexUsingCreateFlagOnNoRawResponseClient() { // 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.ClientNoRawResponse.Index <ElasticsearchProject>(doc, i => i.OpType(OpType.Create)); indexResult.IsValid.Should().BeTrue(); // Grab the indexed document. var foundDoc = this.ClientNoRawResponse.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.ClientNoRawResponse.Index <ElasticsearchProject>(doc, i => i.OpType(OpType.Create)); // Make sure the index request failed with HTTP status 409 since document with same id already exists. Assert.False(response.Created); Assert.AreEqual(409, response.ConnectionStatus.HttpStatusCode); }
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); }
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 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.ResponseRaw.Utf8String()); }
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.Result); }
public async void TestIndex() { var newProject = new ElasticsearchProject { Name = "COBOLES", //COBOL ES client ? }; var t = await this.Client.IndexAsync <ElasticsearchProject>(newProject); Assert.True(t.IsValid); }
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 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 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 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 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 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 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 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 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 UpdateUsingPartialWithNull() { var originalProject = new ElasticsearchProject { Id = 1, Name = "NEST", Country = "UK" }; var partialUpdate = new PartialElasticsearchProjectWithNull { Country = null }; var s = new UpdateDescriptor <ElasticsearchProject, PartialElasticsearchProjectWithNull>() .IdFrom(originalProject) //only used to infer the id .Doc(partialUpdate); //the actual partial update statement; this.JsonEquals(s, MethodBase.GetCurrentMethod()); }
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 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 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 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 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); }