Exemplo n.º 1
0
        //[TestMethod]
        public void TestBoolQuery()
        {
            var conn = new ElasticSearchSharp.ElasticSearchConnection();
            var collection = new ElasticSearchSharp.ElasticSearchCollection<TestObject>(conn);

            ElasticSearchQuery query = new ElasticSearchQuery();
            var boolQuery = new BoolQuery
            {
                Must = new MatchAllQuery(),
                MustNot = new TextQuery()
                 {
                     Fields = new Dictionary<string, string>(){
                             {"Text", "hi"}
                         }
                 }

            };

            query.Query = boolQuery;

            var items = collection.Find(query);
            Assert.IsTrue(items.Any());
            foreach (var item in items)
            {
                Assert.IsNotNull(item);
            }
        }
Exemplo n.º 2
0
        public void TestMatchAllQuery()
        {
            var conn = new ElasticSearchSharp.ElasticSearchConnection();
            var collection = new ElasticSearchSharp.ElasticSearchCollection<TestObject>(conn);

            ElasticSearchQuery query = new ElasticSearchQuery();
            query.Query = new MatchAllQuery();

            var items = collection.Find(query);
            Assert.IsTrue(items.Any());
            foreach (var item in items)
            {
                Assert.IsNotNull(item);
            }
        }
Exemplo n.º 3
0
        public void TestIdsQuery()
        {
            var conn = new ElasticSearchSharp.ElasticSearchConnection();
            var collection = new ElasticSearchSharp.ElasticSearchCollection<TestObject>(conn);

            ElasticSearchQuery query = new ElasticSearchQuery();

            query.Query = new IdsQuery() { Ids = new List<string>(new [] {"vlad", "john"}) };

            var items = collection.Find(query);
            Assert.IsTrue(items.Any());
            foreach (var item in items)
            {
                Assert.IsNotNull(item);
            }
        }
Exemplo n.º 4
0
        //[TestMethod]
        public void TestTextQuery()
        {
            var conn = new ElasticSearchSharp.ElasticSearchConnection();
            var collection = new ElasticSearchSharp.ElasticSearchCollection<TestObject>(conn);

            collection.Save("hello", new TestObject() { Name = "hello", Text = "Hello" });
            collection.Save("world", new TestObject() { Name = "world", Text = "world" });

            ElasticSearchQuery query = new ElasticSearchQuery();

            query.Query = new TextQuery()
            {
                Operator = BooleanOperator.And,
                Type = TextQueryType.Phrase,
                Fields = new Dictionary<string, string>
                {
                    {"Text", "hello"},
                    {"Name", "hello"}
                 }
            };

            var items = collection.Find(query);
            Assert.IsTrue(items.Any());
            foreach (var item in items)
            {
                Assert.IsNotNull(item);
            }
        }