/// <summary>
        /// GET /megacorp/employee/_search
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryDoc()
        {
            var response = client.Search<employee>();
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

        /// <summary>
        /// GET /megacorp/employee/_search
        /// queryMatch
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryMatchDoc()
        {
            var response = client.Search<employee>(s =>
                s.Query(
                    q => q.Match(m => m.Field(f => f.last_name).Query("明狮"))
                    ));
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

        /// <summary>
        /// GET /megacorp/employee/_search
        /// queryBool
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryBoolDoc()
        {
            var response = client.Search<employee>(s =>
                s.Query(
                    q => q.Bool(
                        b => b.Must(m => m.Match(mm => mm.Field(f => f.last_name).Query("小明")))
                            .Filter(f => f.Range(r => r.Field(ff => ff.age).GreaterThan(20)))
                        )));
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

        /// <summary>
        /// GET /megacorp/employee/_search
        /// queryMatchPhrase
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryMatchParseDoc()
        {
            var response = client.Search<employee>(s =>
                s.Query(
                    q => q.MatchPhrase(m => m.Field(f => f.last_name).Query("小明"))));
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

        /// <summary>
        /// GET /megacorp/employee/_search
        /// queryHighlight
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryHighLightDoc()
        {
            var response = client.Search<employee>(s =>
                s.Query(
                    q => q.MatchPhrase(m => m.Field(f => f.last_name).Query("狮")))
                    .Highlight(h => h.Fields(ff => ff.Field(fff => fff.last_name))));
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

        /// <summary>
        /// GET /megacorp/employee/_search
        /// queryAggregations
        /// </summary>
        /// <returns></returns>
        public ISearchResponse<employee> QueryAggsDoc()
        {
            var response = client.Search<employee>(s => s.Aggregations(a => a.Terms("ages", t => t.Field(f => f.age))));
            Console.WriteLine(JsonConvert.SerializeObject(response));
            return response;
        }

  

posted on 2019-09-18 14:47  chester·chen  阅读(1012)  评论(0编辑  收藏  举报