예제 #1
0
        /// <summary>
        /// Asynchronously search using dynamic as its return type.
        /// </summary>
        public static Task <IQueryResponse <dynamic> > SearchAsync(this IElasticClient client,
                                                                   SearchBuilder searchBuilder,
                                                                   string index          = null,
                                                                   string type           = null,
                                                                   string routing        = null,
                                                                   SearchType?searchType = null)
        {
            var search = new SearchDescriptor <dynamic>();

            if (!index.IsNullOrEmpty())
            {
                search.Index(index);
            }
            if (!type.IsNullOrEmpty())
            {
                search.Type(type);
            }
            if (!routing.IsNullOrEmpty())
            {
                search.Routing(routing);
            }
            if (searchType.HasValue)
            {
                search.SearchType(searchType.Value);
            }

            var path  = new PathResolver(client.Settings).GetSearchPathForDynamic(search);
            var query = searchBuilder.ToString();

            return(client.SearchRawAsync <dynamic>(query, path));
        }
예제 #2
0
        /// <summary>
        /// Search using T as the return type
        /// </summary>
        public IQueryResponse <T> Search <T>(SearchBuilder searchBuilder,
                                             string index          = null,
                                             string type           = null,
                                             string routing        = null,
                                             SearchType?searchType = null) where T : class
        {
            var search = new SearchDescriptor <T>();

            if (!index.IsNullOrEmpty())
            {
                search.Index(index);
            }
            if (!type.IsNullOrEmpty())
            {
                search.Type(type);
            }
            if (!routing.IsNullOrEmpty())
            {
                search.Routing(routing);
            }
            if (searchType.HasValue)
            {
                search.SearchType(searchType.Value);
            }

            var query = searchBuilder.ToString();
            var path  = this.PathResolver.GetSearchPathForTyped(search);
            ConnectionStatus status = this.Connection.PostSync(path, query);
            var r = this.ToParsedResponse <QueryResponse <T> >(status);

            return(r);
        }