Example #1
0
 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 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);
 }
Example #3
0
        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");
        }
Example #4
0
        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, new IndexParameters { Refresh = true });

            //assert
            //grab document back from the index and make sure it is the same document
            var foundDocument = this._client.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
            var response = this._client.DeleteById<ElasticSearchProject>(newDocument.Id, new DeleteParameters { Refresh = true });

            //assert
            //make sure getting by id returns nothing
            foundDocument = this._client.Get<ElasticSearchProject>(newDocument.Id);
            Assert.Null(foundDocument);
        }
Example #5
0
 public void IndexOpTypeNone()
 {
     var o = new ElasticSearchProject { Id = 1, Name = "Test" };
     var result = this._client.Index(o, new IndexParameters { OpType = OpType.None });
     var status = result.ConnectionStatus;
     StringAssert.DoesNotContain("op_type=create", status.RequestUrl);
 }
Example #6
0
        public void IndexUsingCreateFlag()
        {
            // Document to be indexed.
            ElasticSearchProject doc = new ElasticSearchProject
            {
                Country = "Mozambique",
                Followers = new List<Person>(),
                Id = idGen.Next(),
                Name = "Test Document for 'IndexDocument' Create Flag"
            };

            // Index the document
            this._client.Index<ElasticSearchProject>(doc, new IndexParameters { OpType = OpType.Create });

            // Grab the indexed document.
            var foundDoc = this._client.Get<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._client.Index<ElasticSearchProject>(doc, new IndexParameters { OpType = OpType.Create });

            // Make sure the index request failed with HTTP status 409 since document with same id already exists.
            Assert.False(response.OK);
            Assert.AreEqual(System.Net.HttpStatusCode.Conflict, response.ConnectionStatus.Error.HttpStatusCode);
        }
Example #7
0
        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.OK);
            var obj = new ElasticSearchProject()
            {
                Name = "NEST",
                Country = "netherlands",
                LOC = 100000, //Too many :(
            };
            var percolateResponse = this._client.Percolate(obj);
            Assert.True(percolateResponse.IsValid);
            Assert.True(percolateResponse.OK);
            Assert.NotNull(percolateResponse.Matches);
            Assert.True(percolateResponse.Matches.Contains(name));

            var re = c.UnregisterPercolator(name, ur=>ur.Index<ElasticSearchProject>());
        }
 public void Initialize()
 {
     _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, i => i.OpType(OpTypeOptions.Create));
     var status = result.ConnectionStatus;
     StringAssert.Contains("op_type=create", status.RequestUrl);
 }
Example #10
0
        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());
        }
Example #11
0
 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");
 }
Example #12
0
        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);
        }
Example #13
0
        /// <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 = "mmm";
                var status = this.ConnectedClient.Index(_LookFor).ConnectionStatus;
                Assert.True(status.Success, status.Result);

                Assert.True(this.ConnectedClient.Flush<ElasticSearchProject>().OK, "Flush");
            }
        }
Example #14
0
        public void DoFilterTest(Func<FilterDescriptor<ElasticSearchProject>, Nest.BaseFilter> filter, ElasticSearchProject project, bool queryMustHaveResults)
        {
            var filterId = Filter<ElasticSearchProject>.Term(e => e.Id, project.Id.ToString());

            var results = this._client.Search<ElasticSearchProject>(
                s => s.Filter(ff => ff.And(
                        f => f.Term(e => e.Id, project.Id.ToString()),
                        filter
                    ))
                );

            Assert.True(results.IsValid, results.ConnectionStatus.Result);
            Assert.True(results.ConnectionStatus.Success, results.ConnectionStatus.Result);
            Assert.AreEqual(queryMustHaveResults ? 1 : 0, results.Total);
        }
Example #15
0
        /// <summary>
        /// Create document for test.
        /// </summary>
        protected override void ResetIndexes()
        {
            base.ResetIndexes();
            var client = this._client;
            if (client.IsValid)
            {
                _LookFor = NestTestData.Session.Single<ElasticSearchProject>().Get();
                _MissingField = f => f.Name;
                _ExistsField = f => f.Id;

                // missing
                _LookFor.Name = null;

                var status = this._client.Index(_LookFor).ConnectionStatus;
                Assert.True(status.Success, status.Result);

                Assert.True(this._client.Flush<ElasticSearchProject>().OK, "Flush");
            }
        }
Example #16
0
 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.ConnectedClient.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);
 }
Example #17
0
        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.OK);
            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.True(percolateResponse.OK);
            Assert.NotNull(percolateResponse.Matches);
            Assert.True(percolateResponse.Matches.Contains(name), percolateResponse.Matches.Count().ToString());

            //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.True(percolateResponse.OK);
            Assert.NotNull(percolateResponse.Matches);
            Assert.False(percolateResponse.Matches.Contains(name));

            re = c.UnregisterPercolator(name, ur=>ur.Index<ElasticSearchProject>());
        }