Beispiel #1
0
 public void Setup()
 {
     _sut = new ElasticBand(new DefaultHttpClientFactory(), new ElasticQueryBuilder());
     _sut.SetElasticsearchUrl("https://localhost:9200");
     _sut.SetElasticsearchAuthentication("B0pGRnABUbqCwsoaMxi0:gexHoph8SnK_HpTuLkOgtw");
     _sut.GetClient().DeleteAsync(_index).Wait();
 }
Beispiel #2
0
        public async Task ElasticBand_methods_should_index_get_query_and_delete_documents_in_elasticsearch_for_type_TestObject2()
        {
            // Decide the index name and instantiate an ElasticBand...
            var index       = "testindex2";
            var elasticBand = new ElasticBand(new DefaultHttpClientFactory(), new ElasticQueryBuilder());

            elasticBand.SetElasticsearchUrl("https://localhost:9200");
            elasticBand.SetElasticsearchAuthentication("B0pGRnABUbqCwsoaMxi0:gexHoph8SnK_HpTuLkOgtw");

            elasticBand.GetClient().DeleteAsync(index).Wait();

            // Create some objects to index
            var object1 = new TestObject2 {
                Name = "Andrew", Birthday = new DateTime(2019, 2, 7)
            };
            var object2 = new TestObject2 {
                Name = "James", Birthday = new DateTime(2019, 7, 27)
            };
            var object3 = new TestObject2 {
                Name = "Drew", Birthday = new DateTime(2019, 1, 9)
            };

            // Index the objects, optionally pass in an id, if omitted a new Guid will be generated...
            var indexResponse1 = await elasticBand.Index <TestObject2>(index, object1, "id1");

            var indexResponse2 = await elasticBand.Index <TestObject2>(index, object2, "id2");

            var indexResponse3 = await elasticBand.Index <TestObject2>(index, object3, "id3");

            // Speedy lookup if you know an id...
            var getResponse1 = await elasticBand.GetDocumentByID <TestObject2>(index, "id2");

            // Update a property and re-index...
            getResponse1.Data.Name = "Jamie";
            await elasticBand.Index <TestObject2>(index, getResponse1.Data, "id2");

            await Task.Delay(1000); // Give ES a chance to internally update the indicies

            // Query in various ways...
            var queryResult1 = await elasticBand.Query <TestObject2>(index, "Jamie");

            var queryResult2 = await elasticBand.Query <TestObject2>(index, "name:Drew");

            var queryResult3 = await elasticBand.Query <TestObject2>(index, "birthday>2019-03-01");

            var queryResult4 = await elasticBand.Query <TestObject2>(index, "birthday<2019-03-01T09:05:00");

            var queryResult5 = await elasticBand.Query <TestObject2>(index, "*rew");

            // Delete...
            await elasticBand.Delete(index, "id2");

            Assert.That(queryResult1.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult2.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult3.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult4.Data.Count, Is.EqualTo(2));
            Assert.That(queryResult5.Data.Count, Is.EqualTo(2));
        }