示例#1
0
        async public void GetErrorElasticClient_InvalidResponse(int returnCode, bool expectedValid)
        {
            IElasticClient client  = ElasticTools.GetErrorElasticClient(returnCode);
            Indices        index   = Indices.Index(new string[] { "someIndex" });
            SearchRequest  request = new SearchRequest(index)
            {
                Query = new TermQuery {
                    Field = "someField", Value = "someValue"
                }
            };

            ISearchResponse <TestType> response = await client.SearchAsync <TestType>(request);

            Assert.Equal(expectedValid, response.IsValid);
        }
        public void GetInMemoryElasticClient()
        {
            IElasticClient client   = ElasticTools.GetInMemoryElasticClient("test-response.json");
            var            response = client.SearchTemplate <TestType>(sd => sd
                                                                       .Index("AliasName")
                                                                       .Params(pd => pd
                                                                               .Add("searchstring", "search_term")
                                                                               .Add("my_size", 10)
                                                                               )
                                                                       );

            Assert.True(response.IsValid);
            Assert.Equal(222, response.Total);
            Assert.Equal(20, response.Documents.Count);
            Assert.All(response.Documents, doc => Assert.NotNull(doc));
            Assert.All(response.Documents, doc => Assert.IsType <TestType>(doc));
        }