首页 > 解决方案 > NEST (ElasticSearch) Terms Aggregation does not acknowledge the Query

问题描述

I have a search request as below:

            var response = client.Search<ProductElastic>(s => s

                .Query(q => q
                        .Bool(b => b
                            .Should(mu => mu
                                .Match(m => m
                                    .Field(f => f.title)
                                    .Boost(1.5)
                                    .Query(inputfilter.q)
                                ), mu => mu
                                .Match(m => m
                                    .Field(f => f.content)
                                    .Query(inputfilter.q)
                                )
                            )

                        )
                    )

                 .Aggregations(a => a
                        .Terms("doctype_i", he => he
                            .Field(g => g.doctype_i)
                        )
                        .Terms("category_i", e => e
                            .Field(ge => ge.category_i)
                            .Size(100)
                        )
                    )

            );

inputfilter.q holds the search term. When inputfilter.q is null it returns all the results and my aggregation bucket numbers are accurately represented. When inputfilter.q is defined (ex. searching for "test") it refines the results set, however, my aggregation buckets still give me the full numbers as before, as if nothing was searched for. For the record, doctype_i and category_i are integer type fields in Elastic.

How do I make my .Aggregations acknowledge the .Query so the aggregation buckets reflect numbers based on the results set?

标签: elasticsearch-aggregation

解决方案


推荐阅读