Content.query aggregations by query (not field)

Enonic version: 6.7.2
OS: Ubuntu 14.04.5 LTS

Hello everyone,

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.

Is it possible?


1 Like

Aggregations works on the results of a query. Could you give an example of what you would like to do?

Simple!

var result = contentLib.query({ start: offset, count: limit, query: "_parentPath LIKE '/content" + site._path + "/news/*'", aggregations: { myfacetquery: { terms: { query: "data.myfield1 = 'some value' AND data.myfield2 = 'some thing else'", minDocCount: 1 } } }, contentTypes: [ app.name + ':article' ] });

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'
        ]
    });
1 Like

Thanks for your reply rmy!

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…

Hello again.

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).

I create a feature-request, lets have a look at it: Filtered aggregation

1 Like