NEST search查询

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

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

        /// 
        /// GET /megacorp/employee/_search
        /// queryBool
        /// 
        /// 
        public ISearchResponse QueryBoolDoc()
        {
            var response = client.Search(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;
        }

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

        /// 
        /// GET /megacorp/employee/_search
        /// queryHighlight
        /// 
        /// 
        public ISearchResponse QueryHighLightDoc()
        {
            var response = client.Search(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;
        }

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

  

你可能感兴趣的:(NEST search查询)