Versions Compared

Key

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

The Create Query Stage is a crucial component in SearchAPI that enables you to perform powerful generate search queries on an index or alias. It provides a wide range of options and parameters to customize and fine-tune your search. This stage is engine agnostic out of the box but for some specific project you may modify this stage to create your own queries and send them over the intermediate to be modified or used in further stages.

With the Create Query Stage, you can specify the fields to be used for matching terms, phrases, spans, date ranges, and ranges. This allows you to define precisely how your search results are retrieved and filtered based on your specific requirements.

One of the key features of the Create Query Stage is the ability to leverage PYQPL (Query Parser Language) to create complex and advanced queries. PyQPL provides a flexible syntax that allows you to construct intricate search conditions, combine multiple search criteria, and define custom operators for precise control over your search results.


The Create Query Stage also supports various additional functionalities to enhance your search experience. These include pagination, sorting, highlighting (to emphasize search terms in the results), filters (to narrow down search results based on specific criteria), aggregations (to obtain statistical insights from search results), and the ability to fetch specific fields to optimize performance and reduce data transfer.

Table of Contents
maxLevel3

Properties

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
halt_on_exceptionIndicates if the pipeline should be interrupted in case of an exceptiontruebooleanNoNo
engine_nameName of the engine to use for this query. If none is provided, the default engine will be used-stringNoNo
filtersName of the key in which the filters will be stored in the intermediate"filters"stringNoNo
qpl_enableEnable QPL to parse the "q" parameter into an engine query with pyQPLfalsebooleanNoYes
fieldsFields to be used for matching terms, phrases, spans, etc.-array, object, or stringNoYes

vector_field_name

Name of the field where we should look for the vector in elasticsearch.-stringYesNo

query_type

The type of query to be used when searching for results in elasticsearch. These are SCORE_SCRIPT, BOOLEAN or INNER_HITS (has child).VectorQueryType.SCORE_SCRIPTEnumYesNo

child_type_for_inner_hits

Type of the child when using InnerHits Query-stringYesNo

min_score

Min_score field for SCORE_SCRIPT and INNER_HITS queries0.65floatYesNo


Create Query Stage Intermediate Parameters

The Query Stage offers a range of parameters that can be passed via the intermediate input to customize your search request or modify the configuration of the current stage. These parameters provide flexibility and control over the search process.


ParameterDescription
qA string query for performing a search. Can be transformed into engine-specific queries using PyQPL (Query Parser Language).
queryEngine-specific queries for the search.
knnEngine-specific queries specifically for k-nearest neighbor (KNN) searches.
filtersCalculated filters for search. This with knn parameter get stored on the same variable as a tuple, this is the second parameter of the tuple.
sizeNumber of results to return from the search request. Overrides the size specified in the configuration.
from/startIndicates the starting point for retrieving search results. Can be used interchangeably with the page parameter.
pageIt can be an alternative to from/start. It calculates the start based on the size parameter
fetch_fieldsList of fields to fetch for each search result. Overrides the fields specified in the configuration.
exclude_fieldsList of fields to exclude from the search results. Overrides the fields specified in the configuration.
scrollScroll ID used to retrieve large numbers of results from a single search request, similar to a cursor in a traditional database.
operatorThe default operator for query string queries: AND or OR. Overrides the default operator specified in the configuration.
vectorCalculated vectors use to create the knn query.
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
_query_stage = CreateQueryStage(
    enable=True,
    save_to_intermediate=True,
    expand_result=False,
    halt_on_exception=False,
    name=QUERY_STAGE_NAME,
    engine_name='Elasticsearch',
    filters='filters',
    qpl_enable=True,
    vector_field_name='sentence_vector',
    query_type=VectorQueryType.SCORE_SCRIPT,
    child_type_for_inner_hits='sentence',
    min_score=0.7,
    type='CreateQueryStage',
)