I have a search page with several facets. I’m using aggregations to generate those facets, but some of those are not related to just one field. In fact they are more complex and could be generated with a query.
Ok, the query you provide in the aggregations should be in the main query.
If you have different data-sets that you would do aggregations on, you need to create separate queries with aggregations.
Its like a relational database aggregations;
Query gets the result-set
Filters are applied to the data,
aggregations are calculated on that result-set.
Its possible to support things like filtered aggregations, but I dont see how that would help you here, this is more relevant when doing nested aggregations that you need to calculate different Metrics upon.
So for the above:
var result = contentLib.query({
start: offset,
count: limit,
query: "_parentPath LIKE '/content" + site._path + "/news/*'" AND
"data.myfield1 = 'some value' AND data.myfield2 = 'some thing else'",
aggregations: {
myfacetquery: {
terms: {
"field": "data.someField",
minDocCount: 1
}
}
},
contentTypes: [
app.name + ':article'
]
});
I understand the aggregation purpose, and what I want to do is like a sub-query (a query inside my results), not filter my main query.
I’m bringing this point here because I use to work with Apache Solr, and there we have the concept of facet field and facet query. It helps a lot when you have complex content tree and want to facet your main query with a sub-query expression.
I saw nested aggregations but options are strict into pre-defined parameters, different from query string.
Just wondering if it’s possible, or maybe something to look at…
Yes I see. Maybe the filtered aggregation would help you out here, for this particular scenario, to limit the number of hits, then use that for another bucket-aggregation. It will not be a fullblown query-part the of course (e.g fulltext capabilities).