Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Filter Stage will generate the engine specific filters based on the configuration provided, specifically with the list of DynamicFilter in the aggs configuration parameter,

The Filter stage  is used to generate engine-specific filters and store them in a SearchFilters object in the

 

intermediate

 under the stage name.Additionally, this stage can also generate the filters from the selected aggregations, which will look in the key aggs in the intermediate dictionary in the process function, the generated filters will be stored in the intermediate under the name provided in  filters_name

section of the response. This stage allows you to configure filters from various sources:

  • Config: Filters can be defined in the filters configuration parameter as a list of DynamicFilters or a JSON representation.
  • Filters from Request Body or Intermediate: Filters can be defined in the filters key of the request body or the intermediate as a list of DynamicFilters or a JSON representation.
  • Filter by IDs from Request Body or Intermediate: Filters can be defined in the filter_ids key of the request body or the intermediate as a list of IDs, which will generate a filter by IDs.
  • Filters in Keys from Intermediate: Filters can be retrieved from any key defined in filter_keys. For each key in the list, the stage will look for a list of DynamicFilters or a JSON representation.
  • Filter by User ID: If the add_user_filter configuration parameter is set to true, the stage will retrieve the user information from the request, search for the value in the field defined in user_value, and create a filter for the field defined in user_filter_field.

Properties

PropertyDescriptionDefaultTypeRequired
filtersFilters to be applied within this stage-array of DynamicFilter
Yes (minItems: 1
No, but if added minimum 1 item)
typeStage class name-stringYes
(but only while working with the JSON Format)
enableEnable stage for executiontruebooleanNo
nameName for this specific stage
. Used in the intermediate and final parameters
"filters"stringNo
save_to_intermediateIf true, the result of the stage will be stored in the intermediate instead of the final section
. This makes the response of the stage unavailable for the final result
falsebooleanNo
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
that affects the process of the stageobjectNo
halt_on_exceptionIndicates if the pipeline should be interrupted in case of an exceptionfalsebooleanNo
engine_nameName of the engine to use for this query. If none is provided, the default engine will be usedstringNo
add_user_filterIf enabled, the stage will add a filter using the credentials in the request, using the user_value and user_filter_field propertiesfalsebooleanNo
user_valueField in the request's credentials to be used as the filter value-stringNo
user_filter_fieldField for the filter in which the user_value must appear
for the filter
stringNo
filter_keysList of keys where filters are stored for compilation into a single filter entry[]array of stringsNo
filter_by_id_fieldField in which the filter by ID will work on"_id"stringNo



Filter Stage Request Body & Intermediate Parameters

ParameterDescription
filtersFilters to be applied within this stage. Should be provided as an array of DynamicFilters objects or a JSON representation of the filters.
filter_idsA list of IDs used for filtering. When provided, it generates a filter based on the specified IDs.
filter_keysA list of keys where filters are stored for compilation into a single filter entry. For each key, the Filter stage retrieves a list of DynamicFilters or a JSON representation of the 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
_filter_stage = FilterStage(
    enable=True,
    name='filters',
    engine_name=DEFAULT_ENGINE_NAME,
    save_to_intermediate=False,
    expand_result=False,
    filters=[
        TermFilter(field='adult', negated=False, must=True, value=False, multi_select=False)
    ],
    add_user_filter=True,
    user_value='id',
    user_filter_field='owner',
    filter_keys=['somefilters_a', 'filters_b'],
    filter_by_id_field='doc_id'
 )