Пример #1
0
        public List <TEntity> SearchByQuery(Nest.SearchRequest <TEntity> query)
        {
            // var json = elastic.client.RequestResponseSerializer.SerializeToString(query);

            var searchResponse = elastic.client.Search <TEntity>(query);

            return(searchResponse.Hits.Select(h => {
                h.Source.Id = h.Id;
                return h.Source;
            })
                   .ToList());
        }
Пример #2
0
            public async Task <Pagination <CompanyInformationDto> > Handle(SearchRequest2 request, CancellationToken cancellationToken)
            {
                //Object Initializer syntax
                int page = request.Page, pageSize = request.PageSize;

                var searchRequest = new Nest.SearchRequest <CompanyInformationDto>
                {
                    From  = (page - 1) * pageSize,
                    Size  = pageSize,
                    Query = new BoolQuery
                    {
                        Must = new List <QueryContainer>
                        {
                            new TermsQuery
                            {
                                Field = Field <CompanyInformationDto>(f => f.ComTypeCode.Suffix("keyword")),
                                Terms = new [] { "CT", "NH" }
                            },
                            new MultiMatchQuery
                            {
                                Fields   = new [] { "ticker^3", "taxCode.keyword^3", "organName", "en_OrganName", "organShortName", "en_OrganShortName" },
                                Query    = (request.Term ?? "").Trim(),
                                Operator = Operator.And,
                                Type     = TextQueryType.BestFields
                            }
                        }
                    }
                };

                var searchResponse = await _elasticClient.SearchAsync <CompanyInformationDto>(searchRequest);

                return(new Pagination <CompanyInformationDto>
                {
                    Items = searchResponse.Documents,
                    Page = page,
                    PageSize = pageSize,
                    TotalRecords = searchResponse.Total
                });
            }
Пример #3
0
            public async Task <Pagination <CompanyInformationDto> > Handle(SearchByAgeRequest request, CancellationToken cancellationToken)
            {
                //Object Initializer syntax
                int page = request.Page, pageSize = request.PageSize;

                var searchRequest = new Nest.SearchRequest <CompanyInformationDto>
                {
                    From  = (page - 1) * pageSize,
                    Size  = pageSize,
                    Query = new DateRangeQuery
                    {
                        Field                = Field <CompanyInformationDto>(f => f.IncorporationDate),
                        LessThanOrEqualTo    = request.AgeFrom == null ? null : $"now/y-{request.AgeFrom}y/y",
                        GreaterThanOrEqualTo = request.AgeTo == null ? null : $"now/y-{request.AgeTo}y/y"
                    },
                    Sort = new List <ISort>
                    {
                        new FieldSort
                        {
                            Field = Field <CompanyInformationDto>(f => f.IncorporationDate),
                            Order = SortOrder.Ascending
                        }
                    },
                    Source = new SourceFilter
                    {
                        Includes = Fields <CompanyInformationDto>(f => f.OrganCode, f => f.OrganName, f => f.Age, f => f.IncorporationDate)
                    }
                };

                var searchResponse = await _elasticClient.SearchAsync <CompanyInformationDto>(searchRequest);

                return(new Pagination <CompanyInformationDto>
                {
                    Items = searchResponse.Documents,
                    Page = page,
                    PageSize = pageSize,
                    TotalRecords = searchResponse.Total
                });
            }