You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The QueryStage is a stage used for performing a search query on an index or alias. It allows you to specify various parameters such as the fields to be used for matching terms, phrases, spans, date ranges, and ranges. You can also customize the query using PyQPL (Query Parser Language) and define custom operators. The QueryStage supports pagination, sorting, highlighting, filters, aggregations, and fetching specific fields.

PropertyDescriptionDefaultTypeRequiredQPL Config?
typeStage class name-stringYesNo
enableEnable stage for executiontruebooleanNoNo
nameName for this specific stage"search"stringNoNo
save_to_intermediateIf true, the result of the stage will be stored in the intermediate instead of the final sectionfalsebooleanNoNo
expand_resultIndicates if the result of this stage should be expanded into the final data dictionary instead of being appended as usualfalsebooleanNoNo
ui_onlySection specific for UI configuration that affects the process of the stageQueryNo
No
halt_on_exceptionIndicates if the pipeline should be interrupted in case of an exceptiontruebooleanNoNo
indexName of the index or alias in which to perform the query-string or array of stringsYesNo
engine_nameName of the engine to use for this query. If none is provided, the default engine will be usedstringNo
No
queryJSON Query DSL as a string representation or a dictionarystring or objectNo
No
sizeNumber of hits to return per requestintegerNo
No
sortSort configuration for the query resultsarray or objectNo
No
page_size_defaultDefault page size for pagination25integerNoNo
operatorThe default operator for query string query: AND or OR"or"stringNoNo
highlightName of the key in which the highlights will be stored in the intermediate"highlight"stringNoNo
filtersName of the key in which the filters will be stored in the intermediate"filters"stringNoNo
aggregationsName of the key in which the aggregations will be stored in the intermediate"aggregations"stringNoNo
aggregations_filtersName of the key in which the aggregation filters will be stored in the intermediate"aggregations_filters"stringNoNo
fetch_fieldsList of fields to fetcharray of stringsNo

exclude_fieldsList of fields to excludearray of stringsNo

qpl_enableEnable QPL to parse the "q" parameter into an engine query with pyQPLfalsebooleanNoYes
implicit_operatorDefault operator to use when the relationship between two operands is ambiguous"or"stringNoYes
fieldsFields to be used for matching terms, phrases, spans, etc.array, object, or stringYes
Yes
date_fieldsFields to be used for date rangesarray, object, or stringNo
Yes
range_fieldsFields to be used for rangesarray, object, or stringNo
Yes
date_formatDate format used to convert date values in the querystringNo
Yes
slop_nearSlop value used for the NEAR operator10numberNoYes
slop_beforeSlop value used for the BEFORE operator2numberNoYes
slop_adjSlop value used for the ADJ operator0numberNoYes
slop_span_notSlop value used for the SPAN NOT operator0numberNoYes
timezoneCoordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query to UTCstringNo
Yes
wildcardUse wildcard operatorsfalsebooleanNoYes
grammarFile path or raw string representing the grammar for parsing text into QPLstringNo
Yes
custom_operatorsDictionary of custom operators with their names as keys and corresponding logic classes as valuesobjectNo
Yes

synonyms_call

Function returning requested synonyms for the specified string


Callable(accepts: string, returns: list of string, or None )NoYes

QueryStageUIConfig 

The QueryStageUIConfig is a configuration object that provides UI-specific settings for the QueryStage.

QueryStageUIConfig Properties

PropertyDescriptionDefaultType
page_sizeConfiguration for page size settings in the UIQueryNo
sortConfiguration for sort settings in the UIQueryNo

PageSizeConfig Properties 

PropertyDescriptionDefaultType
defaultDefault page size value25integer
optionsAvailable page size options[25, 50, 100]array of integers

SortConfig Properties 

PropertyDescriptionTypeRequired
defaultDefault sort entrySortEntryYes
optionsAvailable sort optionsarray of QueryYes

SortEntry Properties 

PropertyDescriptionTypeRequired
fieldName of the field to be used for sortingstringYes
display_nameDisplay name for this sort entry (only applicable for user interface)stringNo
orderSort order to be usedQuery or objectYes

SortOrder Enum 

Enum ValueDescription
"asc"Ascending sort order
"desc"Descending sort order

Example Configuration

synonyms = {
            'cancer': ['cancer', 'malignancy', '363346000', 'cancers', 'malignancies', '"malignant growth"',
                       '"malignant neoplasm"', '"malignant neoplasms"', '"malignant neoplastic disease"',
                       '"malignant tumor"', '"malignant tumors"', '"neoplasm malignant"', '"neoplasm/cancer"',
                       '"tumor, malignant"'],
            'headache': ['headache', '25064002', 'cephalalgia', 'cephalgia', 'cephalgias', '"cranial pain"',
                         '"have headaches"', '"head ache"', '"head pain"', '"head pain cephalgia"', '"head pains"',
                         'headaches', '"mild global headache"', '"mild headache"', '"pain head"', '"pain in head"',
                         '"pain, head"']
        }

_query_stage = QueryStage(
    engine_name=DEFAULT_ENGINE_NAME,
    enable=True,
    qpl_enable=True,
    name=SEARCH_STAGE_NAME,
    index='movies',
    synonyms_call= lambda x: self.synonyms.get(x, None), # Simple synonym implementation
    wildcard=False,
    fields=['title', 'overview', 'url', 'status', 'metadata', 'metadata.production_companies',
            'metadata.cast',
            'metadata.directors'],
    range_fields=['metadata.budget'],
    date_fields=['release_date'],
    fetch_fields=['title', 'adult', 'overview', 'url', 'release_date', 'status', 'video', 'metadata',
                  'metadata.production_companies', 'metadata.cast', 'metadata.directors'],
    exclude_fields=None,
    implicit_operator='or',
    page_size_default=25,
    sort=SortEntry(
        field='_score',
        order=SortOrder.DESC
    ),
    aggregations=_aggregation_stage.name,
    aggregations_filters=_aggregation_stage.filters_name,
    highlight=_highlight_stage.name,
    filters=_filter_stage.name,
    ui_only=QueryStageUIConfig(
        sort=SortConfig(
            default=SortEntry(
                field='_score',
                display_name='Score',
                order=SortOrder.DESC
            ),
            options=[
                SortEntry(
                    field='_score',
                    display_name='Score',
                    order=SortOrder.DESC
                ),
                SortEntry(
                    field='release_date',
                    display_name='Release Date',
                    order=SortOrder.ASC
                ),
                SortEntry(
                    field='metadata.budget',
                    display_name='Budget',
                    order=SortOrder.DESC
                )
            ]
        ),
        page_size=PageSizeConfig(
            default=25,
            options=[25, 50, 100]
        )
    )
)
  • No labels