예제 #1
0
        public SearchResult <Customer> GetCustomer(CustomerSearchRequest customerSearchRequest)
        {
            var filters = new List <Func <QueryContainerDescriptor <Customer>, QueryContainer> >();

            if (customerSearchRequest.filters?.Count > 0)
            {
                foreach (Filter filter in customerSearchRequest.filters)
                {
                    filters.Add(fq => fq.Term(t => t.Field(filter.fieldName).Value(filter.fieldValue)));
                }
            }


            AggregationBase agg =
                new TermsAggregation("school.suburb")
            {
                Field = Nest.Infer.Field <Customer>(p => p.school.suburb)
            } &&
            new TermsAggregation("school.suburb")
            {
                Field = Nest.Infer.Field <Customer>(p => p.school.state)
            };

            var response = EsCoreOperation.SearchClient.Search <Customer>(NewMethod2(customerSearchRequest, filters));


            var fileter = new List <BrandLink.Extensions.ElasticSearch.Operations.Model.Request.Filter>();

            foreach (Filter filter in customerSearchRequest.filters)
            {
                fileter.Add(new BrandLink.Extensions.ElasticSearch.Operations.Model.Request.Filter()
                {
                    FieldName  = filter.fieldName,
                    FieldValue = filter.fieldValue
                });
            }

            SearchParams searchRequest = new SearchParams()
            {
                SearchTerm = customerSearchRequest.searchTerm,
                Filters    = fileter
            };

            var responseNew = SearchConfiguration.CustomerSet.Query(searchRequest);

            var responseNew1 = SearchConfiguration.CustomerSet.Query(() => NewMethod3(customerSearchRequest, filters));

            var searchResult = new SearchResult()
            {
                Total    = response.Total,
                Page     = customerSearchRequest.pageIndex,
                PageSize = customerSearchRequest.pageSize,
                Results  = (List <Customer>)response.Documents
            };

            searchResult.aggregations = BuildAggregations(response.Aggregations);


            return(responseNew);
        }
예제 #2
0
 private static Func <SearchDescriptor <Customer>, ISearchRequest> NewMethod2(CustomerSearchRequest customerSearchRequest, List <Func <QueryContainerDescriptor <Customer>, QueryContainer> > filters)
 {
     return(s => s.Index("customer").
            Query(q =>
                  q.Bool(b =>
                         b.Must(mu =>
                                mu.MultiMatch(m => m.Fields(f => NewMethod1(f)).Query(customerSearchRequest.searchTerm))
                                ).Filter(filters)
                         )
                  ).Aggregations(a => NewMethod()).Skip(customerSearchRequest.pageIndex).Take(20));
 }