其他分享
首页 > 其他分享> > NEST search查询

NEST search查询

作者:互联网

        /// <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;
        }

  

标签:search,Console,NEST,megacorp,查询,Field,Query,response
来源: https://www.cnblogs.com/chenyishi/p/11542124.html