Interface SearchAggregationFactory

All Known Subinterfaces:
ElasticsearchSearchAggregationFactory, ExtendedSearchAggregationFactory<S,PDF>, LuceneSearchAggregationFactory
All Known Implementing Classes:
AbstractSearchAggregationFactory

public interface SearchAggregationFactory
A factory for search aggregations.

Field paths

By default, field paths passed to this DSL are interpreted as absolute, i.e. relative to the index root.

However, a new, "relative" factory can be created with withRoot(String): the new factory interprets paths as relative to the object field passed as argument to the method.

This can be useful when calling reusable methods that can apply the same aggregation on different object fields that have same structure (same sub-fields).

Such a factory can also transform relative paths into absolute paths using toAbsolutePath(String); this can be useful for native aggregations in particular.

Author:
Emmanuel Bernard emmanuel@hibernate.org
  • Method Details

    • range

      Perform aggregation in range buckets.

      Given a field and one or more ranges of values, this aggregation creates one bucket per range, and puts in each bucket every document for which the given field has a value that falls into the corresponding range.

      For each bucket, the document count is computed, or more complex metrics or sub-aggregations for backends that support it.

      Returns:
      The next step.
    • terms

      Perform aggregation in term buckets.

      Given a field, this aggregation creates one bucket per term of that field in the index, and puts in each bucket every document for which the given field matches the corresponding term.

      For each bucket, the document count is computed, or more complex metrics or sub-aggregations for backends that support it.

      Returns:
      The next step.
    • extension

      <T> T extension(SearchAggregationFactoryExtension<T> extension)
      Extend the current factory with the given extension, resulting in an extended factory offering different types of aggregations.
      Type Parameters:
      T - The type of factory provided by the extension.
      Parameters:
      extension - The extension to the aggregation DSL.
      Returns:
      The extended factory.
      Throws:
      SearchException - If the extension cannot be applied (wrong underlying backend, ...).
    • withRoot

      @Incubating SearchAggregationFactory withRoot(String objectFieldPath)
      Create a new aggregation factory whose root for all paths passed to the DSL will be the given object field.

      See here for more information.

      Parameters:
      objectFieldPath - The path from the current root to an object field that will become the new root.
      Returns:
      A new aggregation factory using the given object field as root.
    • toAbsolutePath

      @Incubating String toAbsolutePath(String relativeFieldPath)
      Parameters:
      relativeFieldPath - The path to a field, relative to the root of this factory.
      Returns:
      The absolute path of the field, for use in native aggregations for example. Note the path is returned even if the field doesn't exist.