Hi
I am trying to build small app with facets, I am using NEST to get aggregations.
When I execute the aggregations query using cURL iam getting expected results:
my cURL is
POST product/_search
{
"aggs": {
"group_by_brand": {
"terms": { "field": "brand.keyword" }
}
}
}
"aggregations" : {
"group_by_brand" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "hokey",
"doc_count" : 4
},
{
"key" : "ubest",
"doc_count" : 4
},
{
"key" : "beert",
"doc_count" : 2
}
]
}
However, I am unable to retrieve the results using NEST.
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings( node).DefaultIndex("product");
var client = new ElasticClient(settings);
//create a terms query
var query = new TermsQuery
{
IsVerbatim = true, Field = "brand", Terms = new string[] { "25" },
};
var fields = new TestProduct();
string[] Fields = new[]
{
nameof(fields.brand),
//nameof(fields.color)
};
var aggregations = new Dictionary<string, IAggregationContainer>();
foreach (string sField in Fields)
{
var termsAggregation = new TermsAggregation(sField)
{
Field = sField, //"brand.keyword" ,
Missing ="N/A"
};
aggregations.Add(sField, new AggregationContainer { Terms = termsAggregation });
}
//create the search request
var searchRequest = new SearchRequest
{
Query = query,
From = 0,
Size = 100,
Aggregations = aggregations
};
var result = client.SearchAsync<AggregationDTO>(searchRequest).Result;
I am getting Valid Nest response but however aggregations values are null.
Can some one advise me, what I am missing.
Thank you in advance.