Пример #1
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);
            }
        }