kaquel.query – ElasticSearch Query DSL objects

See Query DSL for more information.

class kaquel.query.Query

Bases: BaseModel, ABC

Any query.

abstract render() dict

Render as a Python dictionary.

Returns:

Rendered query.

class kaquel.query.BooleanQuery(*, must: list[Query] = None, filter: list[Query] = None, should: list[Query] = None, must_not: list[Query] = None, minimum_should_match: int | None = None)

Bases: Query

Boolean query.

See Boolean query for more information.

must: Annotated[list[Query], Field(default_factory=list)]

Clauses that must appear in matching documents.

filter: Annotated[list[Query], Field(default_factory=list)]

Clauses that must appear in matching documents.

should: Annotated[list[Query], Field(default_factory=list)]

Clauses that should appear in the matching document.

must_not: Annotated[list[Query], Field(default_factory=list)]

Clauses that must not appear in the matching document.

minimum_should_match: int | None

Number or percentage of “should” clauses the document must match.

class kaquel.query.ExistsQuery(*, field: str)

Bases: Query

Exists query.

See Exists query for more information.

field: Annotated[str, StringConstraints(min_length=1)]

Name of the field to check the existence of.

class kaquel.query.MatchAllQuery

Bases: Query

Match all query.

See Match all query for more information.

class kaquel.query.MatchPhraseQuery(*, field: str, query: str | bool | int | float | date)

Bases: Query

Match phrase query.

See Match phrase query for more information.

field: Annotated[str, StringConstraints(min_length=1)]

Name of the field on which to make the query.

query: str | bool | int | float | date

Query.

class kaquel.query.MatchQuery(*, field: str, query: str | bool | int | float | date)

Bases: Query

Match query.

See Match query for more information.

field: Annotated[str, StringConstraints(min_length=1)]

Name of the field on which to make the query.

query: str | bool | int | float | date

Query.

class kaquel.query.MultiMatchQueryType(value)

Bases: str, Enum

Multi-match query type.

See multi_match query types for more information.

BEST_FIELDS = 'best_fields'

Find documents which match any field, but use the best field’s score.

MOST_FIELDS = 'most_fields'

Find documents which match any field, and combines each score.

CROSS_FIELDS = 'cross_fields'

Treat fields with the same analyzer as if they were one field.

PHRASE = 'phrase'

Run a match_phrase query on each field.

PHRASE_PREFIX = 'phrase_prefix'

Run a match_phrase_prefix query on each field.

BOOL_PREFIX = 'bool_prefix'

Run a match_bool_prefix query on each field.

class kaquel.query.MultiMatchQuery(*, type: MultiMatchQueryType = MultiMatchQueryType.BEST_FIELDS, query: str, fields: list[str] | None = None, lenient: bool = False)

Bases: Query

Multi-match query.

See Multi-match query and Query string query for more information.

type: MultiMatchQueryType

Multi-match query type.

query: str

Query string.

fields: list[Annotated[str, StringConstraints(min_length=1)]] | None

Fields to be queried, with optional wildcards.

lenient: bool

Whether to ignore format-based errors or not.

class kaquel.query.NestedScoreMode(value)

Bases: str, Enum

Mode in which a nested query affects the root document’s score.

AVG = 'avg'

Use the mean relevance score of all matching child objects.

MAX = 'max'

Use the highest relevance score of all matching child objects.

MIN = 'min'

Use the lowest relevance score of all matching child objects.

NONE = 'none'

Do not use the relevance score of matching child objects.

SUM = 'sum'

Add together the relevance scores of all matching child objects.

class kaquel.query.NestedQuery(*, path: str, query: Query, score_mode: NestedScoreMode = NestedScoreMode.AVG)

Bases: Query

Nested query.

See Nested query for more information.

path: Annotated[str, StringConstraints(min_length=1)]

Path to the nested object to search.

query: Query

Nested query.

score_mode: NestedScoreMode

Score mode.

class kaquel.query.QueryStringQuery(*, query: str)

Bases: Query

Query string query.

See Query string query for more information.

query: Annotated[str, StringConstraints(min_length=1)]

Query to parse and use for search.

See Query string syntax for more information.

class kaquel.query.RangeQuery(*, field: str, gt: str | int | float | date | None = None, gte: str | int | float | date | None = None, lt: str | int | float | date | None = None, lte: str | int | float | date | None = None)

Bases: Query

Range query.

See Range query for more information.

field: Annotated[str, StringConstraints(min_length=1)]

Name of the field on which to make the query.

gt: str | int | float | date | None

Value the field should be greater than.

gte: str | int | float | date | None

Value the field should be greater or equal than.

lt: str | int | float | date | None

Value the field should be less than.

lte: str | int | float | date | None

Value the field should be less or equal than.