Using Terms filter query API via elastic .net client


I am currently trying to write a Terms Query via the Elastic.Clients.Elasticsearch 8.1.1 .NET client.

I have to apply dynamic terms query filter for filtered categories Ids. If any category id not selected then not applied this filter on the terms query.

 var response = await client.SearchAsync<EsProduct>(x => x.Index(nameof(Product).ToLowerInvariant())
                .Query(q => q
                    .Bool(b => b
                        .Must(m => m
                            .MultiMatch(mm => mm
                        .Filter(f => f
                            .Term(publishedQuery) // check published                            
                            .Terms(ts => ts
                                .Terms(new TermsQueryField(categoriesIds.Select(id => FieldValue.Long(id)).ToArray())))
                .Aggregations(a => a
                    .Range("price", r => r.Field(f => f.Price).Ranges(new AggregationRange[] { priceRange1, priceRange2, priceRange3 })))

With this i can't able to get proper filtered products.
Also, i can't able to create aggregation with field type keyword. Any suggestion for this.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.