Class Facet


  • public class Facet
    extends Stage
    Processes multiple aggregation pipelines within a single stage on the same set of input documents. Each sub-pipeline has its own field in the output document where its results are stored as an array of documents.

    The $facet stage allows you to create multi-faceted aggregations which characterize data across multiple dimensions, or facets, within a single aggregation stage. Multi-faceted aggregations provide multiple filters and categorizations to guide data browsing and analysis. Retailers commonly use faceting to narrow search results by creating filters on product price, manufacturer, size, etc.

    Input documents are passed to the $facet stage only once. $facet enables various aggregations on the same set of input documents, without needing to retrieve the input documents multiple times.

    • Constructor Detail

      • Facet

        protected Facet()
    • Method Detail

      • facet

        public static Facet facet()
        Creates a new facet stage
        Returns:
        the new stage
        Since:
        2.2
      • of

        @Deprecated(forRemoval=true)
        public static Facet of()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new facet stage
        Returns:
        the new stage
      • field

        public Facet field​(String name,
                           Stage... stages)
        Adds a field to the facet
        Parameters:
        name - the field name
        stages - the pipeline defining the field
        Returns:
        this
      • getFields

        public Map<String,​List<Stage>> getFields()
        Returns:
        the fields
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.