Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to perform nested aggregation on multiple fields in Solr?
    text
    copied!<p>I am trying to perform search result aggregation (count and sum) grouping by several fields in a nested fashion.</p> <p>For example, with the schema shown at the end of this post, I'd like to be able to get the sum of "size" grouped by "category" and sub-grouped further by "subcategory" and get something like this:</p> <pre><code>&lt;category name="X"&gt; &lt;subcategory name="X_A"&gt; &lt;size sum="..." /&gt; &lt;/subcategory&gt; &lt;subcategory name="X_B"&gt; &lt;size sum="..." /&gt; &lt;/subcategory&gt; &lt;/category&gt; .... </code></pre> <p>I've been looking primarily at Solr's Stats component which, as far as I can see, doesn't allow nested aggregation.</p> <p>I'd appreciate it if anyone knows of some way to implement this, with or without the Stats component.</p> <p>Here is a cut-down version of the target schema:</p> <pre><code>&lt;types&gt; &lt;fieldType name="string" class="solr.StrField" /&gt; &lt;fieldType name="text" class="solr.TextField"&gt; &lt;analyzer&gt;&lt;tokenizer class="solr.StandardTokenizerFactory" /&gt;&lt;/analyzer&gt; &lt;/fieldType&gt; &lt;fieldType name="date" class="solr.DateField" /&gt; &lt;fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0" /&gt; &lt;/types&gt; &lt;fields&gt; &lt;field name="id" type="string" indexed="true" stored="true" /&gt; &lt;field name="category" type="text" indexed="true" stored="true" /&gt; &lt;field name="subcategory" type="text" indexed="true" stored="true" /&gt; &lt;field name="pdate" type="date" indexed="true" stored="true" /&gt; &lt;field name="size" type="int" indexed="true" stored="true" /&gt; &lt;/fields&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload