Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Aggregation Stage

will generate the engine

is responsible for generating engine-specific aggregations based on the

configuration provided, specifically with the

provided configuration. It allows you to define a list of DynamicAgg objects in the aggs configuration parameter,

and store them

which specifies the aggregations to be performed. The generated aggregations will be stored in the intermediate section under the specified stage name.

This

In addition to generating aggregations, this stage can also

generate the

create filters

from

based on the selected aggregations

, which will look in the key aggs

. During the process, it looks for the aggs key in the intermediate dictionary

in the process function, the

and generates filters based on the selected aggregations, which should be a list of SelectionAgg or a JSON representation of this. The generated filters will be stored in the intermediate section under the name provided in

 

the filters_name property.

Additionally

Furthermore,

the aggregation stage can also

the Aggregation Stage has the ability to process the resulting aggregations from

a

an engine search

,

and transform them

into a UI friendly format

into a format suitable for the user interface (UI).

Properties

PropertyDescriptionDefaultTypeRequired
aggsAggregations to be performed within this stage[]array of DynamicAggNo
typeStage class name-stringYes (but only while working with the JSON Format)
enableEnable stage for executiontruebooleanNo
nameName of the key in which the aggregations will be stored in intermediate"aggregations"stringNo
save_to_intermediateIf true, the result of the stage will be stored in the intermediate instead of the final sectionfalsebooleanNo
expand_resultIndicates if the result of this stage should be expanded into the final data dictionary instead of being appended as usualfalsebooleanNo
ui_onlySection specific for UI configuration. This configuration will be retrieved when necessary and should affect the process of the stageobjectNo
halt_on_exceptionIndicates if, in case of an exception, the pipeline should be interruptedfalsebooleanNo
filters_nameName of the key in which the aggregation filters will be stored in intermediate. Generated from a list of SelectionAgg stored in the aggs parameter in intermediate"aggregation_filters"stringNo
engine_nameName of the engine to use for this query. If none is provided, the default engine will be usedstringNo
search_responseName of the key in the final result where the query results will be stored"search"stringNo
ui_aggregationsDetermines if UI aggregations are enabledtruebooleanNo

Aggregation Stage Intermediate Parameters

ParameterDescription
aggsList of SelectionAgg which will be use to generate aggregation filters
Tip

Remember that the intermediate can be fill with either other stages or the original request body that trigger the pipeline, making this essentially REST API parameters

Example Configuration

Code Block
languagepy
themeDJango
_aggregation_stage = AggregationStage(
    enable=True,
    name='aggregations',
    filters_name='aggregations_filters',
    save_to_intermediate=False,
    expand_result=False,
    engine_name=DEFAULT_ENGINE_NAME,
    search_response=SEARCH_STAGE_NAME,
    ui_aggregations=True,  # This over here generates the aggregations for ui, if you don't want them, set it to False
    aggs=[
        TermAgg(
            id='genres',
            field='metadata.genres.name.keyword',
            must=True,
            max_values=100,
            multi_select=True,
            operation='or',
            order=None,
            exclude_terms=None,
            include_terms=None,
            ui_only=TermAggUI(display_name='Genres', max_display=5, expanded=True),
            aggs=[
                TopHitsAgg(
                    id='top_hits',
                    type='top_hits'
                ),
                TermAgg(
                    field='metadata.spoken_languages.name.keyword',
                    negated=False,
                    must=True,
                    id='spoken_languages',
                    ui_only=TermAggUI(display_name='Spoken Languages', max_display=5, expanded=False),
                    aggs=None,
                    max_values=None,
                    multi_select=False,
                    operation='or',
                    order=None,
                    exclude_terms=None,
                    include_terms=None
                )]
        ),
        BoolAgg(
            id='adult',
            field='adult',
            negated=False,
            must=True,
            ui_only=BoolAggUI(display_name='Adult', display_True='True', display_False='False')
        ),
        DateHistogramAgg(
            field='release_date',
            negated=False,
            must=True,
            id='release_date_h',
            ui_only=DateHistogramAggUI(display_name='Release Date'),
            calendar_interval=['1y', '1q', '1M', '1d'],
            format=['yyyy', '\'Q\'q', 'MMMM', 'E dd'],
            time_zone=['-06:00'],
            min_doc_count=[100, 1],
            offset=None,
            order=None
        ),
        HistogramAgg(
            id='budget',
            field='metadata.budget',
            negated=False,
            must=True,
            interval=[10000000, 1000000],
            min_doc_count=[100, 10, 1],
            order=None,
            offset=None,
            ui_only=HistogramAggUI(display_name='Budget')
        ),
        SliderAgg(
            id='budget_slider',
            field='metadata.budget',
            negated=False,
            must=True,
            ui_only=SliderAggUI(display_name='Budget', translate=None, min=None, max=None, show_ticks=True),
        ),
        DateRangeAgg(
            field='release_date',
            negated=False,
            must=True,
            id='release_date_dr',
            ui_only=DateRangeAggUI(
                display_name='Release Range',
                hide_count=False,
                translate=None
            ),
            format='MM-yyyy',
            ranges=[
                DateRange(
                    key='minus_10',
                    start='now-10y',
                    start_display=None,
                    end=None,
                    end_display=None
                ),
                DateRange(
                    key=None,
                    start='01-1960',
                    start_display=None,
                    end='01-1970',
                    end_display=None
                ),
                DateRange(
                    key=None,
                    start=None,
                    start_display=None,
                    end='now-10M/M',
                    end_display=None
                )
            ]
        ),
        RangeAgg(
            field='metadata.budget',
            negated=False,
            must=True,
            id='budget_r',
            multi_select=False,
            ui_only=RangeAggUI(
                display_name='Budget Range',
                hide_count=False,
                translate=None
            ),
            ranges=[
                Range(
                    key='< 10,000,000',
                    start=None,
                    end='10000000'
                ),
                Range(
                    key='> 10,000,000',
                    start='10000000',
                    end=None
                ),
                Range(
                    key='50 to 100 millions',
                    start='50000000',
                    end='100000000'
                )
            ],

        )
    ]
)

Selected Aggregations

The Aggregation stage can process selected aggregations, these required to be of type SelectionAgg, or a JSON representation of it.

Code Block
languagejs
titleExample of selected aggregations in intermediate
{
  "aggs": [
    {
      "id": "genres",
      "values": [
        "Drama"
      ],
      "negated": [],
      "level": 0
    },
    {
      "id": "adult",
      "values": [
        false
      ],
      "negated": [],
      "level": 0
    }
  ]
}