I want to dynamically create sub aggregations on Nest search query from a List or Dictionary. The below query with pre-defined terms is working fine. But i want to form the query on run time from a list or dictionary.
client.Search(s => s
.Index("masterdata")
.Type("masterdatatype")
.Aggregations(agr => agr.Terms("Date", tr => tr.Field("MonthandYear").Size(int.MaxValue).Order(TermsOrder.TermAscending)
.Aggregations(a => a.Terms("DimensionValue", te => te.Field(dimensionName ).Size(int.MaxValue)
.Aggregations(ag => ag.Sum("SumofMeasure", t => t.Field(measureName)))))))
.Query(a => a.Terms(t => t.Field(filterName).Terms(filterValues)))
);
Hi,
Below is the working code which was written on compile time itself. In the
below example the date would be first aggregated by field MonthandYear and
then followed by sub aggregations on two other fields dimensionname and
measurename.
Now consider i have to write this query on run time. I will get the three
(may be more or less) fields in a list or string[] or querystring and i
have to form the same aggregation query on run time.I used
termsaggregationcontainer object to build my aggregation but i am not able
to append aggregations to existing fields on a loop.
Please let me know if i am still unclear. I will try to write some sample
code that i tried earlier.
client.Search<object>(s => s
.Index("masterdata")
.Type("masterdatatype")
.Aggregations(agr => agr
.Terms("Date", tr => tr
.Field("MonthandYear")
.Size(int.MaxValue)
.Order(TermsOrder.TermAscending)
.Aggregations(a => a
.Terms("DimensionValue", te => te
.Field(dimensionName)
.Size(int.MaxValue)
.Aggregations(ag => ag
.Sum("SumofMeasure", t => t
.Field(measureName)
)
)
)
)
)
)
.Query(a => a
.Terms(t => t
.Field(filterName)
.Terms(filterValues)
)
)
);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.