Class NestedObjectAggregation

  • All Implemented Interfaces:
    IAggregation, ISubAggregationAwareAggregation

    @StableMinor(version="14.0",
                 sinceVersion="11.2")
    public class NestedObjectAggregation
    extends AbstractSubAggregationAwareAggregation
    This aggregation should be used mainly when some aggregations must be performed over fields inside a nested object field.
    In this case, the aggregations should be added as sub-aggregations of a nested object aggregation.
    For example, suppose we have a person document type with the following fields:
    • name (text)
    • address (nested object)
      • street (keyword)
      • number (keyword)

    And there are 3 documents in this document type:
        {"name": "Nara Jones"}
        {"name": "Albert Russef", "address": [{"street": "Av Rio Branco", "number": "23"}, {"street": "Av Francisco Bicalho"}]}
        {"name": "Josef Camus", "address": [{"street": "Av Presidente Vargas"}]}

    If a filter aggregation must be created with a filter to restrict the documents to those with the field address.number, and this filter aggregation has a terms aggregation as sub aggregation, the terms aggregation result will have the buckets Av Rio Branco and Av Francisco Bicalho, because, since there's no nested aggregation, both of them will be considered in filter aggregation. This may or may not be desired.
    If this is not the expected behavior, the filter aggregation should be wrapped inside a nested object aggregation. When this query is performed, the terms aggregation would result in a single bucket: Av Rio Branco. This result is because with the nested object aggregation, both filter and terms aggregation will be applied in the same nested objects.

    This aggregation produces a INestedObjectAggregationResult.
    Since:
    11.2.0
    Version:
    $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
    • Field Detail

      • id

        protected final String id
    • Constructor Detail

      • NestedObjectAggregation

        public NestedObjectAggregation​(String id,
                                       CompositeDocumentTypeField path)
        Create a new instance.
        Parameters:
        id - the aggregation identifier.
        path - the path of nested field.
        Since:
        11.2.0
    • Method Detail

      • getPath

        public CompositeDocumentTypeField getPath()
        Returns the path of nested field.
        Returns:
        the path of nested field.
        Since:
        11.2.0
      • getId

        public String getId()
        Description copied from interface: IAggregation
        Returns the aggregation identifier.
        Specified by:
        getId in interface IAggregation
        Returns:
        the aggregation identifier.