From 524bd9c31d4d297052220f28af2da43b78a778f5 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 28 Aug 2024 17:23:43 +0100 Subject: [PATCH 01/27] Autogenerate Query classes --- elasticsearch_dsl/interfaces.py | 433 +++++++ elasticsearch_dsl/query.py | 1983 ++++++++++++++++++++++++++--- elasticsearch_dsl/utils.py | 9 + noxfile.py | 3 +- setup.py | 1 + utils/generator.py | 311 +++++ utils/templates/dsl_classes.tpl | 204 +++ utils/templates/interfaces.py.tpl | 22 + utils/templates/query.py.tpl | 145 +++ 9 files changed, 2937 insertions(+), 174 deletions(-) create mode 100644 elasticsearch_dsl/interfaces.py create mode 100644 utils/generator.py create mode 100644 utils/templates/dsl_classes.tpl create mode 100644 utils/templates/interfaces.py.tpl create mode 100644 utils/templates/query.py.tpl diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py new file mode 100644 index 00000000..a92d3239 --- /dev/null +++ b/elasticsearch_dsl/interfaces.py @@ -0,0 +1,433 @@ +from typing import TYPE_CHECKING, Any, List, Literal, Mapping, TypedDict, Union +from elasticsearch_dsl.search_base import InstrumentedField +from elasticsearch_dsl.utils import AttrDict + +if TYPE_CHECKING: + from elasticsearch_dsl import analysis, function, wrappers + +PipeSeparatedFlags = str + + +class QueryBase(TypedDict): + boost: float + _name: str + + +class FuzzyQuery(QueryBase): + max_expansions: int + prefix_length: int + rewrite: str + transpositions: bool + fuzziness: Union[str, int] + value: Union[str, float, bool] + + +class SpanTermQuery(QueryBase): + value: str + + +class CommonTermsQuery(QueryBase): + analyzer: str + cutoff_frequency: float + high_freq_operator: Literal["and", "or"] + low_freq_operator: Literal["and", "or"] + minimum_should_match: Union[int, str] + query: str + + +class RankFeatureFunction(TypedDict): + pass + + +class RankFeatureFunctionSaturation(RankFeatureFunction): + pivot: float + + +class MatchPhraseQuery(QueryBase): + analyzer: str + query: str + slop: int + zero_terms_query: Literal["all", "none"] + + +class FunctionScoreContainer(TypedDict): + exp: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] + gauss: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] + linear: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] + field_value_factor: "function.FieldValueFactorScoreFunction" + random_score: "function.RandomScoreFunction" + script_score: "function.ScriptScoreFunction" + filter: Query + weight: float + + +class InnerHits(TypedDict): + name: str + size: int + from: int + collapse: "i.FieldCollapse" + docvalue_fields: List["i.FieldAndFormat"] + explain: bool + highlight: "i.Highlight" + ignore_unmapped: bool + script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] + seq_no_primary_term: bool + fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] + sort: Union[Union[Union[str, "InstrumentedField"], "i.SortOptions"], List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]]] + _source: Union[bool, "i.SourceFilter"] + stored_fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] + track_scores: bool + version: bool + + +class WildcardQuery(QueryBase): + case_insensitive: bool + rewrite: str + value: str + wildcard: str + + +class RegexpQuery(QueryBase): + case_insensitive: bool + flags: str + max_determinized_states: int + rewrite: str + value: str + + +class LikeDocument(TypedDict): + doc: Any + fields: List[Union[str, "InstrumentedField"]] + _id: str + _index: str + per_field_analyzer: Mapping[Union[str, "InstrumentedField"], str] + routing: str + version: int + version_type: Literal["internal", "external", "external_gte", "force"] + + +class TermsSetQuery(QueryBase): + minimum_should_match_field: Union[str, "InstrumentedField"] + minimum_should_match_script: "i.Script" + terms: List[str] + + +class SpanQuery(TypedDict): + span_containing: "i.SpanContainingQuery" + span_field_masking: "i.SpanFieldMaskingQuery" + span_first: "i.SpanFirstQuery" + span_gap: Mapping[Union[str, "InstrumentedField"], int] + span_multi: "i.SpanMultiTermQuery" + span_near: "i.SpanNearQuery" + span_not: "i.SpanNotQuery" + span_or: "i.SpanOrQuery" + span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] + span_within: "i.SpanWithinQuery" + + +class PrefixQuery(QueryBase): + rewrite: str + value: str + case_insensitive: bool + + +class TokenPruningConfig(TypedDict): + tokens_freq_ratio_threshold: int + tokens_weight_threshold: float + only_score_pruned_tokens: bool + + +class RankFeatureFunctionLinear(RankFeatureFunction): + pass + + +class TextExpansionQuery(QueryBase): + model_id: str + model_text: str + pruning_config: "i.TokenPruningConfig" + + +class MatchBoolPrefixQuery(QueryBase): + analyzer: str + fuzziness: Union[str, int] + fuzzy_rewrite: str + fuzzy_transpositions: bool + max_expansions: int + minimum_should_match: Union[int, str] + operator: Literal["and", "or"] + prefix_length: int + query: str + + +class Script(TypedDict): + source: str + id: str + params: Mapping[str, Any] + lang: Literal["painless", "expression", "mustache", "java"] + options: Mapping[str, str] + + +class PinnedDoc(TypedDict): + _id: str + _index: str + + +class QueryVectorBuilder(TypedDict): + text_embedding: "i.TextEmbedding" + + +class RankFeatureFunctionSigmoid(RankFeatureFunction): + pivot: float + exponent: float + + +class IntervalsQuery(QueryBase): + all_of: "i.IntervalsAllOf" + any_of: "i.IntervalsAnyOf" + fuzzy: "i.IntervalsFuzzy" + match: "i.IntervalsMatch" + prefix: "i.IntervalsPrefix" + wildcard: "i.IntervalsWildcard" + + +class RankFeatureFunctionLogarithm(RankFeatureFunction): + scaling_factor: float + + +class TermQuery(QueryBase): + value: Union[int, float, str, bool, None, Any] + case_insensitive: bool + + +class MatchQuery(QueryBase): + analyzer: str + auto_generate_synonyms_phrase_query: bool + cutoff_frequency: float + fuzziness: Union[str, int] + fuzzy_rewrite: str + fuzzy_transpositions: bool + lenient: bool + max_expansions: int + minimum_should_match: Union[int, str] + operator: Literal["and", "or"] + prefix_length: int + query: Union[str, float, bool] + zero_terms_query: Literal["all", "none"] + + +class WeightedTokensQuery(QueryBase): + tokens: Mapping[str, float] + pruning_config: "i.TokenPruningConfig" + + +class MatchPhrasePrefixQuery(QueryBase): + analyzer: str + max_expansions: int + query: str + slop: int + zero_terms_query: Literal["all", "none"] + + +class ScriptField(TypedDict): + script: "i.Script" + ignore_failure: bool + + +class SourceFilter(TypedDict): + excludes: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] + includes: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] + + +class FieldAndFormat(TypedDict): + field: Union[str, "InstrumentedField"] + format: str + include_unmapped: bool + + +class HighlightBase(TypedDict): + type: Literal["plain", "fvh", "unified"] + boundary_chars: str + boundary_max_scan: int + boundary_scanner: Literal["chars", "sentence", "word"] + boundary_scanner_locale: str + force_source: bool + fragmenter: Literal["simple", "span"] + fragment_size: int + highlight_filter: bool + highlight_query: Query + max_fragment_length: int + max_analyzed_offset: int + no_match_size: int + number_of_fragments: int + options: Mapping[str, Any] + order: Literal["score"] + phrase_limit: int + post_tags: List[str] + pre_tags: List[str] + require_field_match: bool + tags_schema: Literal["styled"] + + +class Highlight(HighlightBase): + encoder: Literal["default", "html"] + fields: Mapping[Union[str, "InstrumentedField"], "i.HighlightField"] + + +class FieldCollapse(TypedDict): + field: Union[str, "InstrumentedField"] + inner_hits: Union["i.InnerHits", List["i.InnerHits"]] + max_concurrent_group_searches: int + collapse: "i.FieldCollapse" + + +class SortOptions(TypedDict): + _score: "i.ScoreSort" + _doc: "i.ScoreSort" + _geo_distance: "i.GeoDistanceSort" + _script: "i.ScriptSort" + + +class SpanMultiTermQuery(QueryBase): + match: Query + + +class SpanNotQuery(QueryBase): + dist: int + exclude: "i.SpanQuery" + include: "i.SpanQuery" + post: int + pre: int + + +class SpanWithinQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" + + +class SpanFirstQuery(QueryBase): + end: int + match: "i.SpanQuery" + + +class SpanOrQuery(QueryBase): + clauses: List["i.SpanQuery"] + + +class SpanNearQuery(QueryBase): + clauses: List["i.SpanQuery"] + in_order: bool + slop: int + + +class SpanFieldMaskingQuery(QueryBase): + field: Union[str, "InstrumentedField"] + query: "i.SpanQuery" + + +class SpanContainingQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" + + +class TextEmbedding(TypedDict): + model_id: str + model_text: str + + +class IntervalsWildcard(TypedDict): + analyzer: str + pattern: str + use_field: Union[str, "InstrumentedField"] + + +class IntervalsAnyOf(TypedDict): + intervals: List["i.IntervalsContainer"] + filter: "i.IntervalsFilter" + + +class IntervalsFuzzy(TypedDict): + analyzer: str + fuzziness: Union[str, int] + prefix_length: int + term: str + transpositions: bool + use_field: Union[str, "InstrumentedField"] + + +class IntervalsPrefix(TypedDict): + analyzer: str + prefix: str + use_field: Union[str, "InstrumentedField"] + + +class IntervalsMatch(TypedDict): + analyzer: str + max_gaps: int + ordered: bool + query: str + use_field: Union[str, "InstrumentedField"] + filter: "i.IntervalsFilter" + + +class IntervalsAllOf(TypedDict): + intervals: List["i.IntervalsContainer"] + max_gaps: int + ordered: bool + filter: "i.IntervalsFilter" + + +class HighlightField(HighlightBase): + fragment_offset: int + matched_fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] + analyzer: Union["analysis.CustomAnalyzer", "analysis.FingerprintAnalyzer", "analysis.KeywordAnalyzer", "analysis.LanguageAnalyzer", "analysis.NoriAnalyzer", "analysis.PatternAnalyzer", "analysis.SimpleAnalyzer", "analysis.StandardAnalyzer", "analysis.StopAnalyzer", "analysis.WhitespaceAnalyzer", "analysis.IcuAnalyzer", "analysis.KuromojiAnalyzer", "analysis.SnowballAnalyzer", "analysis.DutchAnalyzer"] + + +class GeoDistanceSort(TypedDict): + mode: Literal["min", "max", "sum", "avg", "median"] + distance_type: Literal["arc", "plane"] + ignore_unmapped: bool + order: Literal["asc", "desc"] + unit: Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"] + nested: "i.NestedSortValue" + + +class ScriptSort(TypedDict): + order: Literal["asc", "desc"] + script: "i.Script" + type: Literal["string", "number", "version"] + mode: Literal["min", "max", "sum", "avg", "median"] + nested: "i.NestedSortValue" + + +class ScoreSort(TypedDict): + order: Literal["asc", "desc"] + + +class IntervalsFilter(TypedDict): + after: "i.IntervalsContainer" + before: "i.IntervalsContainer" + contained_by: "i.IntervalsContainer" + containing: "i.IntervalsContainer" + not_contained_by: "i.IntervalsContainer" + not_containing: "i.IntervalsContainer" + not_overlapping: "i.IntervalsContainer" + overlapping: "i.IntervalsContainer" + script: "i.Script" + + +class IntervalsContainer(TypedDict): + all_of: "i.IntervalsAllOf" + any_of: "i.IntervalsAnyOf" + fuzzy: "i.IntervalsFuzzy" + match: "i.IntervalsMatch" + prefix: "i.IntervalsPrefix" + wildcard: "i.IntervalsWildcard" + + +class NestedSortValue(TypedDict): + filter: Query + max_children: int + nested: "i.NestedSortValue" + path: Union[str, "InstrumentedField"] + + diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 652b3d57..162b793a 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -19,10 +19,12 @@ from copy import deepcopy from itertools import chain from typing import ( + TYPE_CHECKING, Any, Callable, ClassVar, List, + Literal, Mapping, MutableMapping, Optional, @@ -37,7 +39,12 @@ # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import DslBase +from .utils import DslBase, NOT_SET + +if TYPE_CHECKING: + from .document_base import InstrumentedField + from .utils import NotSet + from elasticsearch_dsl import interfaces as i _T = TypeVar("_T") _M = TypeVar("_M", bound=Mapping[str, Any]) @@ -135,52 +142,49 @@ def __and__(self, other: "Query") -> "Query": return Bool(must=[self, other]) -class MatchAll(Query): - name = "match_all" - - def __add__(self, other: "Query") -> "Query": - return other._clone() - - __and__ = __rand__ = __radd__ = __add__ - - def __or__(self, other: "Query") -> "MatchAll": - return self - - __ror__ = __or__ - - def __invert__(self) -> "MatchNone": - return MatchNone() - - -EMPTY_QUERY = MatchAll() - - -class MatchNone(Query): - name = "match_none" - - def __add__(self, other: "Query") -> "MatchNone": - return self - - __and__ = __rand__ = __radd__ = __add__ - - def __or__(self, other: "Query") -> "Query": - return other._clone() - - __ror__ = __or__ - - def __invert__(self) -> MatchAll: - return MatchAll() - - class Bool(Query): + """ + matches documents matching boolean combinations of other queries. + + :arg filter: The clause (query) must appear in matching documents. + However, unlike `must`, the score of the query will be ignored. + :arg minimum_should_match: Specifies the number or percentage of + `should` clauses returned documents must match. + :arg must: The clause (query) must appear in matching documents and + will contribute to the score. + :arg must_not: The clause (query) must not appear in the matching + documents. Because scoring is ignored, a score of `0` is returned + for all documents. + :arg should: The clause (query) should appear in the matching + document. + """ name = "bool" _param_defs = { - "must": {"type": "query", "multi": True}, - "should": {"type": "query", "multi": True}, - "must_not": {"type": "query", "multi": True}, - "filter": {"type": "query", "multi": True}, + "filter": {'type': 'query', 'multi': True}, + "must": {'type': 'query', 'multi': True}, + "must_not": {'type': 'query', 'multi': True}, + "should": {'type': 'query', 'multi': True}, } + def __init__( + self, + *, + filter: Union[Query, List[Query], "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + must: Union[Query, List[Query], "NotSet"] = NOT_SET, + must_not: Union[Query, List[Query], "NotSet"] = NOT_SET, + should: Union[Query, List[Query], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + filter=filter, + minimum_should_match=minimum_should_match, + must=must, + must_not=must_not, + should=should, + **kwargs + ) + def __add__(self, other: Query) -> "Bool": q = self._clone() if isinstance(other, Bool): @@ -288,268 +292,1797 @@ def __and__(self, other: Query) -> Query: return q __rand__ = __and__ + - -class FunctionScore(Query): - name = "function_score" +class Boosting(Query): + """ + Returns documents matching a `positive` query while reducing the + relevance score of documents that also match a `negative` query. + + :arg negative: Query used to decrease the relevance score of matching + documents. + :arg positive: Any returned documents must match this query. + :arg negative_boost: Floating point number between 0 and 1.0 used to + decrease the relevance scores of documents matching the `negative` + query. + """ + name = "boosting" _param_defs = { - "query": {"type": "query"}, - "filter": {"type": "query"}, - "functions": {"type": "score_function", "multi": True}, + "negative": {'type': 'query'}, + "positive": {'type': 'query'}, } - def __init__(self, **kwargs: Any): - if "functions" in kwargs: - pass - else: - fns = kwargs["functions"] = [] - for name in ScoreFunction._classes: - if name in kwargs: - fns.append({name: kwargs.pop(name)}) - super().__init__(**kwargs) + def __init__( + self, + *, + negative: Query, + positive: Query, + negative_boost: float, + **kwargs: Any + ): + super().__init__( + negative=negative, + positive=positive, + negative_boost=negative_boost, + **kwargs + ) -# compound queries -class Boosting(Query): - name = "boosting" - _param_defs = {"positive": {"type": "query"}, "negative": {"type": "query"}} +class Common(Query): + """ + No documentation available. + + :arg field: Field to use + :arg value: Field value + """ + name = "common" + + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.CommonTermsQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + + +class CombinedFields(Query): + """ + The `combined_fields` query supports searching multiple text fields as + if their contents had been indexed into one combined field. + + :arg query: Text to search for in the provided `fields`. The + `combined_fields` query analyzes the provided text before + performing a search. + :arg fields: List of fields to search. Field wildcard patterns are + allowed. Only `text` fields are supported, and they must all have + the same search `analyzer`. + :arg auto_generate_synonyms_phrase_query: If true, match phrase + queries are automatically created for multi-term synonyms. + :arg operator: Boolean logic used to interpret text in the query + value. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg zero_terms_query: Indicates whether no documents are returned if + the analyzer removes all tokens, such as when using a `stop` + filter. + """ + name = "combined_fields" + + def __init__( + self, + *, + query: str, + fields: List[Union[str, "InstrumentedField"]], + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + operator: Union[Literal["or", "and"], "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["none", "all"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + fields=fields, + auto_generate_synonyms_phrase_query=auto_generate_synonyms_phrase_query, + operator=operator, + minimum_should_match=minimum_should_match, + zero_terms_query=zero_terms_query, + **kwargs + ) class ConstantScore(Query): + """ + Wraps a filter query and returns every matching document with a + relevance score equal to the `boost` parameter value. + + :arg filter: Filter query you wish to run. Any returned documents must + match this query. Filter queries do not calculate relevance + scores. To speed up performance, Elasticsearch automatically + caches frequently used filter queries. + """ name = "constant_score" - _param_defs = {"query": {"type": "query"}, "filter": {"type": "query"}} + _param_defs = { + "filter": {'type': 'query'}, + } + + def __init__( + self, + *, + filter: Query, + **kwargs: Any + ): + super().__init__( + filter=filter, + **kwargs + ) class DisMax(Query): + """ + Returns documents matching one or more wrapped queries, called query + clauses or clauses. If a returned document matches multiple query + clauses, the `dis_max` query assigns the document the highest + relevance score from any matching clause, plus a tie breaking + increment for any additional matching subqueries. + + :arg queries: One or more query clauses. Returned documents must match + one or more of these queries. If a document matches multiple + queries, Elasticsearch uses the highest relevance score. + :arg tie_breaker: Floating point number between 0 and 1.0 used to + increase the relevance scores of documents matching multiple query + clauses. + """ name = "dis_max" - _param_defs = {"queries": {"type": "query", "multi": True}} + def __init__( + self, + *, + queries: List[Query], + tie_breaker: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + queries=queries, + tie_breaker=tie_breaker, + **kwargs + ) -class Filtered(Query): - name = "filtered" - _param_defs = {"query": {"type": "query"}, "filter": {"type": "query"}} +class DistanceFeature(Query): + """ + Boosts the relevance score of documents closer to a provided origin + date or point. For example, you can use this query to give more weight + to documents closer to a certain date or location. + """ + name = "distance_feature" -class Indices(Query): - name = "indices" - _param_defs = {"query": {"type": "query"}, "no_match_query": {"type": "query"}} + def __init__( + self, + **kwargs: Any + ): + super().__init__( + **kwargs + ) -class Percolate(Query): - name = "percolate" +class Exists(Query): + """ + Returns documents that contain an indexed value for a field. + :arg field: Name of the field you wish to search. + """ + name = "exists" -# relationship queries -class Nested(Query): - name = "nested" - _param_defs = {"query": {"type": "query"}} + def __init__( + self, + *, + field: Union[str, "InstrumentedField"], + **kwargs: Any + ): + super().__init__( + field=field, + **kwargs + ) -class HasChild(Query): - name = "has_child" - _param_defs = {"query": {"type": "query"}} +class FunctionScore(Query): + """ + The `function_score` enables you to modify the score of documents that + are retrieved by a query. + + :arg boost_mode: Defines how he newly computed score is combined with + the score of the query + :arg functions: One or more functions that compute a new score for + each document returned by the query. + :arg max_boost: Restricts the new score to not exceed the provided + limit. + :arg min_score: Excludes documents that do not meet the provided score + threshold. + :arg query: A query that determines the documents for which a new + score is computed. + :arg score_mode: Specifies how the computed scores are combined + """ + name = "function_score" + _param_defs = { + "query": {'type': 'query'}, + } + def __init__( + self, + *, + boost_mode: Union[Literal["multiply", "replace", "sum", "avg", "max", "min"], "NotSet"] = NOT_SET, + functions: Union[List["i.FunctionScoreContainer"], "NotSet"] = NOT_SET, + max_boost: Union[float, "NotSet"] = NOT_SET, + min_score: Union[float, "NotSet"] = NOT_SET, + query: Union[Query, "NotSet"] = NOT_SET, + score_mode: Union[Literal["multiply", "sum", "avg", "first", "max", "min"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + if functions is None: + functions = [] + for name in ScoreFunction._classes: + if name in kwargs: + functions.append({name: kwargs.pop(name)}) + super().__init__( + boost_mode=boost_mode, + functions=functions, + max_boost=max_boost, + min_score=min_score, + query=query, + score_mode=score_mode, + **kwargs + ) -class HasParent(Query): - name = "has_parent" - _param_defs = {"query": {"type": "query"}} +class Fuzzy(Query): + """ + Returns documents that contain terms similar to the search term, as + measured by a Levenshtein edit distance. -class TopChildren(Query): - name = "top_children" - _param_defs = {"query": {"type": "query"}} + :arg field: Field to use + :arg value: Field value + """ + name = "fuzzy" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.FuzzyQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -# compound span queries -class SpanFirst(Query): - name = "span_first" - _param_defs = {"match": {"type": "query"}} +class GeoBoundingBox(Query): + """ + Matches geo_point and geo_shape values that intersect a bounding box. + + :arg type: None + :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points + with invalid latitude or longitude. Set to `COERCE` to also try to + infer correct latitude or longitude. + :arg ignore_unmapped: Set to `true` to ignore an unmapped field and + not match any documents for this query. Set to `false` to throw an + exception if the field is not mapped. + """ + name = "geo_bounding_box" -class SpanMulti(Query): - name = "span_multi" - _param_defs = {"match": {"type": "query"}} + def __init__( + self, + *, + type: Union[Literal["memory", "indexed"], "NotSet"] = NOT_SET, + validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + type=type, + validation_method=validation_method, + ignore_unmapped=ignore_unmapped, + **kwargs + ) -class SpanNear(Query): - name = "span_near" - _param_defs = {"clauses": {"type": "query", "multi": True}} +class GeoDistance(Query): + """ + Matches `geo_point` and `geo_shape` values within a given distance of + a geopoint. + + :arg distance: The radius of the circle centred on the specified + location. Points which fall into this circle are considered to be + matches. + :arg distance_type: How to compute the distance. Set to `plane` for a + faster calculation that's inaccurate on long distances and close + to the poles. + :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points + with invalid latitude or longitude. Set to `COERCE` to also try to + infer correct latitude or longitude. + :arg ignore_unmapped: Set to `true` to ignore an unmapped field and + not match any documents for this query. Set to `false` to throw an + exception if the field is not mapped. + """ + name = "geo_distance" + def __init__( + self, + *, + distance: str, + distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, + validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + distance=distance, + distance_type=distance_type, + validation_method=validation_method, + ignore_unmapped=ignore_unmapped, + **kwargs + ) -class SpanNot(Query): - name = "span_not" - _param_defs = {"exclude": {"type": "query"}, "include": {"type": "query"}} +class GeoPolygon(Query): + """ + No documentation available. -class SpanOr(Query): - name = "span_or" - _param_defs = {"clauses": {"type": "query", "multi": True}} + :arg validation_method: None + :arg ignore_unmapped: None + """ + name = "geo_polygon" + def __init__( + self, + *, + validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + validation_method=validation_method, + ignore_unmapped=ignore_unmapped, + **kwargs + ) -class FieldMaskingSpan(Query): - name = "field_masking_span" - _param_defs = {"query": {"type": "query"}} +class GeoShape(Query): + """ + Filter documents indexed using either the `geo_shape` or the + `geo_point` type. + + :arg ignore_unmapped: Set to `true` to ignore an unmapped field and + not match any documents for this query. Set to `false` to throw an + exception if the field is not mapped. + """ + name = "geo_shape" -class SpanContaining(Query): - name = "span_containing" - _param_defs = {"little": {"type": "query"}, "big": {"type": "query"}} + def __init__( + self, + *, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + ignore_unmapped=ignore_unmapped, + **kwargs + ) -# Original implementation contained -# a typo: remove in v8.0. -SpanContainining = SpanContaining +class HasChild(Query): + """ + Returns parent documents whose joined child documents match a provided + query. + + :arg query: Query you wish to run on child documents of the `type` + field. If a child document matches the search, the query returns + the parent document. + :arg type: Name of the child relationship mapped for the `join` field. + :arg ignore_unmapped: Indicates whether to ignore an unmapped `type` + and not return any documents instead of an error. + :arg inner_hits: If defined, each search hit will contain inner hits. + :arg max_children: Maximum number of child documents that match the + query allowed for a returned parent document. If the parent + document exceeds this limit, it is excluded from the search + results. + :arg min_children: Minimum number of child documents that match the + query required to match the query for a returned parent document. + If the parent document does not meet this limit, it is excluded + from the search results. + :arg score_mode: Indicates how scores for matching child documents + affect the root parent document’s relevance score. + """ + name = "has_child" + _param_defs = { + "query": {'type': 'query'}, + } + def __init__( + self, + *, + query: Query, + type: str, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + max_children: Union[int, "NotSet"] = NOT_SET, + min_children: Union[int, "NotSet"] = NOT_SET, + score_mode: Union[Literal["none", "avg", "sum", "max", "min"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + type=type, + ignore_unmapped=ignore_unmapped, + inner_hits=inner_hits, + max_children=max_children, + min_children=min_children, + score_mode=score_mode, + **kwargs + ) -class SpanWithin(Query): - name = "span_within" - _param_defs = {"little": {"type": "query"}, "big": {"type": "query"}} +class HasParent(Query): + """ + Returns child documents whose joined parent document matches a + provided query. + + :arg parent_type: Name of the parent relationship mapped for the + `join` field. + :arg query: Query you wish to run on parent documents of the + `parent_type` field. If a parent document matches the search, the + query returns its child documents. + :arg ignore_unmapped: Indicates whether to ignore an unmapped + `parent_type` and not return any documents instead of an error. + You can use this parameter to query multiple indices that may not + contain the `parent_type`. + :arg inner_hits: If defined, each search hit will contain inner hits. + :arg score: Indicates whether the relevance score of a matching parent + document is aggregated into its child documents. + """ + name = "has_parent" + _param_defs = { + "query": {'type': 'query'}, + } -# core queries -class CombinedFields(Query): - name = "combined_fields" + def __init__( + self, + *, + parent_type: str, + query: Query, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + score: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + parent_type=parent_type, + query=query, + ignore_unmapped=ignore_unmapped, + inner_hits=inner_hits, + score=score, + **kwargs + ) -class Common(Query): - name = "common" +class Ids(Query): + """ + Returns documents based on their IDs. This query uses document IDs + stored in the `_id` field. + :arg values: An array of document IDs. + """ + name = "ids" -class Fuzzy(Query): - name = "fuzzy" + def __init__( + self, + *, + values: Union[str, List[str], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + values=values, + **kwargs + ) -class FuzzyLikeThis(Query): - name = "fuzzy_like_this" +class Intervals(Query): + """ + Returns documents based on the order and proximity of matching terms. + :arg field: Field to use + :arg value: Field value + """ + name = "intervals" -class FuzzyLikeThisField(Query): - name = "fuzzy_like_this_field" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.IntervalsQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class RankFeature(Query): - name = "rank_feature" +class Knn(Query): + """ + Finds the k nearest vectors to a query vector, as measured by a + similarity metric. knn query finds nearest vectors through approximate + search on indexed dense_vectors. + + :arg field: The name of the vector field to search against + :arg query_vector: The query vector + :arg query_vector_builder: The query vector builder. You must provide + a query_vector_builder or query_vector, but not both. + :arg num_candidates: The number of nearest neighbor candidates to + consider per shard + :arg k: The final number of nearest neighbors to return as top hits + :arg filter: Filters for the kNN search query + :arg similarity: The minimum similarity for a vector to be considered + a match + """ + name = "knn" + _param_defs = { + "filter": {'type': 'query', 'multi': True}, + } + def __init__( + self, + *, + field: Union[str, "InstrumentedField"], + query_vector: Union[List[float], "NotSet"] = NOT_SET, + query_vector_builder: Union["i.QueryVectorBuilder", "NotSet"] = NOT_SET, + num_candidates: Union[int, "NotSet"] = NOT_SET, + k: Union[int, "NotSet"] = NOT_SET, + filter: Union[Query, List[Query], "NotSet"] = NOT_SET, + similarity: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + field=field, + query_vector=query_vector, + query_vector_builder=query_vector_builder, + num_candidates=num_candidates, + k=k, + filter=filter, + similarity=similarity, + **kwargs + ) -class DistanceFeature(Query): - name = "distance_feature" +class Match(Query): + """ + Returns documents that match a provided text, number, date or boolean + value. The provided text is analyzed before matching. -class GeoBoundingBox(Query): - name = "geo_bounding_box" + :arg field: Field to use + :arg value: Field value + """ + name = "match" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.MatchQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class GeoDistance(Query): - name = "geo_distance" +class MatchAll(Query): + """ + Matches all documents, giving them all a `_score` of 1.0. + """ + name = "match_all" -class GeoDistanceRange(Query): - name = "geo_distance_range" + def __init__( + self, + **kwargs: Any + ): + super().__init__( + **kwargs + ) + def __add__(self, other: "Query") -> "Query": + return other._clone() -class GeoPolygon(Query): - name = "geo_polygon" + __and__ = __rand__ = __radd__ = __add__ + def __or__(self, other: "Query") -> "MatchAll": + return self -class GeoShape(Query): - name = "geo_shape" + __ror__ = __or__ + def __invert__(self) -> "MatchNone": + return MatchNone() -class GeohashCell(Query): - name = "geohash_cell" +EMPTY_QUERY = MatchAll() -class Ids(Query): - name = "ids" +class MatchBoolPrefix(Query): + """ + Analyzes its input and constructs a `bool` query from the terms. Each + term except the last is used in a `term` query. The last term is used + in a prefix query. + + :arg field: Field to use + :arg value: Field value + """ + name = "match_bool_prefix" -class Intervals(Query): - name = "intervals" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.MatchBoolPrefixQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class Knn(Query): - name = "knn" +class MatchNone(Query): + """ + Matches no documents. + """ + name = "match_none" + def __init__( + self, + **kwargs: Any + ): + super().__init__( + **kwargs + ) -class Limit(Query): - name = "limit" + def __add__(self, other: "Query") -> "MatchNone": + return self + __and__ = __rand__ = __radd__ = __add__ -class Match(Query): - name = "match" + def __or__(self, other: "Query") -> "Query": + return other._clone() + + __ror__ = __or__ + + def __invert__(self) -> MatchAll: + return MatchAll() class MatchPhrase(Query): + """ + Analyzes the text and creates a phrase query out of the analyzed text. + + :arg field: Field to use + :arg value: Field value + """ name = "match_phrase" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.MatchPhraseQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + class MatchPhrasePrefix(Query): + """ + Returns documents that contain the words of a provided text, in the + same order as provided. The last term of the provided text is treated + as a prefix, matching any words that begin with that term. + + :arg field: Field to use + :arg value: Field value + """ name = "match_phrase_prefix" - -class MatchBoolPrefix(Query): - name = "match_bool_prefix" - - -class Exists(Query): - name = "exists" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.MatchPhrasePrefixQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) class MoreLikeThis(Query): + """ + Returns documents that are "like" a given set of documents. + + :arg like: Specifies free form text and/or a single or multiple + documents for which you want to find similar documents. + :arg analyzer: The analyzer that is used to analyze the free form + text. Defaults to the analyzer associated with the first field in + fields. + :arg boost_terms: Each term in the formed query could be further + boosted by their tf-idf score. This sets the boost factor to use + when using this feature. Defaults to deactivated (0). + :arg fail_on_unsupported_field: Controls whether the query should fail + (throw an exception) if any of the specified fields are not of the + supported types (`text` or `keyword`). + :arg fields: A list of fields to fetch and analyze the text from. + Defaults to the `index.query.default_field` index setting, which + has a default value of `*`. + :arg include: Specifies whether the input documents should also be + included in the search results returned. + :arg max_doc_freq: The maximum document frequency above which the + terms are ignored from the input document. + :arg max_query_terms: The maximum number of query terms that can be + selected. + :arg max_word_length: The maximum word length above which the terms + are ignored. Defaults to unbounded (`0`). + :arg min_doc_freq: The minimum document frequency below which the + terms are ignored from the input document. + :arg minimum_should_match: After the disjunctive query has been + formed, this parameter controls the number of terms that must + match. + :arg min_term_freq: The minimum term frequency below which the terms + are ignored from the input document. + :arg min_word_length: The minimum word length below which the terms + are ignored. + :arg routing: None + :arg stop_words: An array of stop words. Any word in this set is + ignored. + :arg unlike: Used in combination with `like` to exclude documents that + match a set of terms. + :arg version: None + :arg version_type: None + """ name = "more_like_this" - -class MoreLikeThisField(Query): - name = "more_like_this_field" + def __init__( + self, + *, + like: Union[Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]]], + analyzer: Union[str, "NotSet"] = NOT_SET, + boost_terms: Union[float, "NotSet"] = NOT_SET, + fail_on_unsupported_field: Union[bool, "NotSet"] = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + include: Union[bool, "NotSet"] = NOT_SET, + max_doc_freq: Union[int, "NotSet"] = NOT_SET, + max_query_terms: Union[int, "NotSet"] = NOT_SET, + max_word_length: Union[int, "NotSet"] = NOT_SET, + min_doc_freq: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + min_term_freq: Union[int, "NotSet"] = NOT_SET, + min_word_length: Union[int, "NotSet"] = NOT_SET, + routing: Union[str, "NotSet"] = NOT_SET, + stop_words: Union[str, List[str], "NotSet"] = NOT_SET, + unlike: Union[Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], "NotSet"] = NOT_SET, + version: Union[int, "NotSet"] = NOT_SET, + version_type: Union[Literal["internal", "external", "external_gte", "force"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + like=like, + analyzer=analyzer, + boost_terms=boost_terms, + fail_on_unsupported_field=fail_on_unsupported_field, + fields=fields, + include=include, + max_doc_freq=max_doc_freq, + max_query_terms=max_query_terms, + max_word_length=max_word_length, + min_doc_freq=min_doc_freq, + minimum_should_match=minimum_should_match, + min_term_freq=min_term_freq, + min_word_length=min_word_length, + routing=routing, + stop_words=stop_words, + unlike=unlike, + version=version, + version_type=version_type, + **kwargs + ) class MultiMatch(Query): + """ + Enables you to search for a provided text, number, date or boolean + value across multiple fields. The provided text is analyzed before + matching. + + :arg query: Text, number, boolean value or date you wish to find in + the provided field. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg auto_generate_synonyms_phrase_query: If `true`, match phrase + queries are automatically created for multi-term synonyms. + :arg cutoff_frequency: None + :arg fields: The fields to be queried. Defaults to the + `index.query.default_field` index settings, which in turn defaults + to `*`. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg fuzzy_rewrite: Method used to rewrite the query. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). Can be applied to the term subqueries constructed for all + terms but the final term. + :arg lenient: If `true`, format-based errors, such as providing a text + query value for a numeric field, are ignored. + :arg max_expansions: Maximum number of terms to which the query will + expand. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg operator: Boolean logic used to interpret text in the query + value. + :arg prefix_length: Number of beginning characters left unchanged for + fuzzy matching. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg tie_breaker: Determines how scores for each per-term blended + query and scores across groups are combined. + :arg type: How `the` multi_match query is executed internally. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. + """ name = "multi_match" + def __init__( + self, + *, + query: str, + analyzer: Union[str, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + tie_breaker: Union[float, "NotSet"] = NOT_SET, + type: Union[Literal["best_fields", "most_fields", "cross_fields", "phrase", "phrase_prefix", "bool_prefix"], "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + analyzer=analyzer, + auto_generate_synonyms_phrase_query=auto_generate_synonyms_phrase_query, + cutoff_frequency=cutoff_frequency, + fields=fields, + fuzziness=fuzziness, + fuzzy_rewrite=fuzzy_rewrite, + fuzzy_transpositions=fuzzy_transpositions, + lenient=lenient, + max_expansions=max_expansions, + minimum_should_match=minimum_should_match, + operator=operator, + prefix_length=prefix_length, + slop=slop, + tie_breaker=tie_breaker, + type=type, + zero_terms_query=zero_terms_query, + **kwargs + ) + + +class Nested(Query): + """ + Wraps another query to search nested fields. If an object matches the + search, the nested query returns the root parent document. + + :arg path: Path to the nested object you wish to search. + :arg query: Query you wish to run on nested objects in the path. + :arg ignore_unmapped: Indicates whether to ignore an unmapped path and + not return any documents instead of an error. + :arg inner_hits: If defined, each search hit will contain inner hits. + :arg score_mode: How scores for matching child objects affect the root + parent document’s relevance score. + """ + name = "nested" + _param_defs = { + "query": {'type': 'query'}, + } + + def __init__( + self, + *, + path: Union[str, "InstrumentedField"], + query: Query, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + score_mode: Union[Literal["none", "avg", "sum", "max", "min"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + path=path, + query=query, + ignore_unmapped=ignore_unmapped, + inner_hits=inner_hits, + score_mode=score_mode, + **kwargs + ) + + +class ParentId(Query): + """ + Returns child documents joined to a specific parent document. + + :arg id: ID of the parent document. + :arg ignore_unmapped: Indicates whether to ignore an unmapped `type` + and not return any documents instead of an error. + :arg type: Name of the child relationship mapped for the `join` field. + """ + name = "parent_id" + + def __init__( + self, + *, + id: Union[str, "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + type: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + id=id, + ignore_unmapped=ignore_unmapped, + type=type, + **kwargs + ) + + +class Percolate(Query): + """ + Matches queries stored in an index. + + :arg field: Field that holds the indexed queries. The field must use + the `percolator` mapping type. + :arg document: The source of the document being percolated. + :arg documents: An array of sources of the documents being percolated. + :arg id: The ID of a stored document to percolate. + :arg index: The index of a stored document to percolate. + :arg name: The suffix used for the `_percolator_document_slot` field + when multiple `percolate` queries are specified. + :arg preference: Preference used to fetch document to percolate. + :arg routing: Routing used to fetch document to percolate. + :arg version: The expected version of a stored document to percolate. + """ + name = "percolate" + + def __init__( + self, + *, + field: Union[str, "InstrumentedField"], + document: Any = NOT_SET, + documents: Union[List[Any], "NotSet"] = NOT_SET, + id: Union[str, "NotSet"] = NOT_SET, + index: Union[str, "NotSet"] = NOT_SET, + name: Union[str, "NotSet"] = NOT_SET, + preference: Union[str, "NotSet"] = NOT_SET, + routing: Union[str, "NotSet"] = NOT_SET, + version: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + field=field, + document=document, + documents=documents, + id=id, + index=index, + name=name, + preference=preference, + routing=routing, + version=version, + **kwargs + ) + + +class Pinned(Query): + """ + Promotes selected documents to rank higher than those matching a given + query. + + :arg organic: Any choice of query used to rank documents which will be + ranked below the "pinned" documents. + :arg ids: Document IDs listed in the order they are to appear in + results. Required if `docs` is not specified. + :arg docs: Documents listed in the order they are to appear in + results. Required if `ids` is not specified. + """ + name = "pinned" + _param_defs = { + "organic": {'type': 'query'}, + } + + def __init__( + self, + *, + organic: Query, + ids: Union[List[str], "NotSet"] = NOT_SET, + docs: Union[List["i.PinnedDoc"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + organic=organic, + ids=ids, + docs=docs, + **kwargs + ) + class Prefix(Query): + """ + Returns documents that contain a specific prefix in a provided field. + + :arg field: Field to use + :arg value: Field value + """ name = "prefix" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.PrefixQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + class QueryString(Query): + """ + Returns documents based on a provided query string, using a parser + with a strict syntax. + + :arg query: Query string you wish to parse and use for search. + :arg allow_leading_wildcard: If `true`, the wildcard characters `*` + and `?` are allowed as the first character of the query string. + :arg analyzer: Analyzer used to convert text in the query string into + tokens. + :arg analyze_wildcard: If `true`, the query attempts to analyze + wildcard terms in the query string. + :arg auto_generate_synonyms_phrase_query: If `true`, match phrase + queries are automatically created for multi-term synonyms. + :arg default_field: Default field to search if no field is provided in + the query string. Supports wildcards (`*`). Defaults to the + `index.query.default_field` index setting, which has a default + value of `*`. + :arg default_operator: Default boolean logic used to interpret text in + the query string if no operators are specified. + :arg enable_position_increments: If `true`, enable position increments + in queries constructed from a `query_string` search. + :arg escape: None + :arg fields: Array of fields to search. Supports wildcards (`*`). + :arg fuzziness: Maximum edit distance allowed for fuzzy matching. + :arg fuzzy_max_expansions: Maximum number of terms to which the query + expands for fuzzy matching. + :arg fuzzy_prefix_length: Number of beginning characters left + unchanged for fuzzy matching. + :arg fuzzy_rewrite: Method used to rewrite the query. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). + :arg lenient: If `true`, format-based errors, such as providing a text + value for a numeric field, are ignored. + :arg max_determinized_states: Maximum number of automaton states + required for the query. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg phrase_slop: Maximum number of positions allowed between matching + tokens for phrases. + :arg quote_analyzer: Analyzer used to convert quoted text in the query + string into tokens. For quoted text, this parameter overrides the + analyzer specified in the `analyzer` parameter. + :arg quote_field_suffix: Suffix appended to quoted text in the query + string. You can use this suffix to use a different analysis method + for exact matches. + :arg rewrite: Method used to rewrite the query. + :arg tie_breaker: How to combine the queries generated from the + individual search terms in the resulting `dis_max` query. + :arg time_zone: Coordinated Universal Time (UTC) offset or IANA time + zone used to convert date values in the query string to UTC. + :arg type: Determines how the query matches and scores documents. + """ name = "query_string" + def __init__( + self, + *, + query: str, + allow_leading_wildcard: Union[bool, "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + default_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + enable_position_increments: Union[bool, "NotSet"] = NOT_SET, + escape: Union[bool, "NotSet"] = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, + fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, + max_determinized_states: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + phrase_slop: Union[float, "NotSet"] = NOT_SET, + quote_analyzer: Union[str, "NotSet"] = NOT_SET, + quote_field_suffix: Union[str, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + tie_breaker: Union[float, "NotSet"] = NOT_SET, + time_zone: Union[str, "NotSet"] = NOT_SET, + type: Union[Literal["best_fields", "most_fields", "cross_fields", "phrase", "phrase_prefix", "bool_prefix"], "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + allow_leading_wildcard=allow_leading_wildcard, + analyzer=analyzer, + analyze_wildcard=analyze_wildcard, + auto_generate_synonyms_phrase_query=auto_generate_synonyms_phrase_query, + default_field=default_field, + default_operator=default_operator, + enable_position_increments=enable_position_increments, + escape=escape, + fields=fields, + fuzziness=fuzziness, + fuzzy_max_expansions=fuzzy_max_expansions, + fuzzy_prefix_length=fuzzy_prefix_length, + fuzzy_rewrite=fuzzy_rewrite, + fuzzy_transpositions=fuzzy_transpositions, + lenient=lenient, + max_determinized_states=max_determinized_states, + minimum_should_match=minimum_should_match, + phrase_slop=phrase_slop, + quote_analyzer=quote_analyzer, + quote_field_suffix=quote_field_suffix, + rewrite=rewrite, + tie_breaker=tie_breaker, + time_zone=time_zone, + type=type, + **kwargs + ) + class Range(Query): + """ + Returns documents that contain terms within a provided range. + + :arg field: Field to use + :arg value: Field value + """ name = "range" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["wrappers.Range", "wrappers.Range", "wrappers.Range", "wrappers.Range", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + + +class RankFeature(Query): + """ + Boosts the relevance score of documents based on the numeric value of + a `rank_feature` or `rank_features` field. + + :arg field: `rank_feature` or `rank_features` field used to boost + relevance scores. + :arg saturation: Saturation function used to boost relevance scores + based on the value of the rank feature `field`. + :arg log: Logarithmic function used to boost relevance scores based on + the value of the rank feature `field`. + :arg linear: Linear function used to boost relevance scores based on + the value of the rank feature `field`. + :arg sigmoid: Sigmoid function used to boost relevance scores based on + the value of the rank feature `field`. + """ + name = "rank_feature" + + def __init__( + self, + *, + field: Union[str, "InstrumentedField"], + saturation: Union["i.RankFeatureFunctionSaturation", "NotSet"] = NOT_SET, + log: Union["i.RankFeatureFunctionLogarithm", "NotSet"] = NOT_SET, + linear: Union["i.RankFeatureFunctionLinear", "NotSet"] = NOT_SET, + sigmoid: Union["i.RankFeatureFunctionSigmoid", "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + field=field, + saturation=saturation, + log=log, + linear=linear, + sigmoid=sigmoid, + **kwargs + ) + class Regexp(Query): + """ + Returns documents that contain terms matching a regular expression. + + :arg field: Field to use + :arg value: Field value + """ name = "regexp" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.RegexpQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class Shape(Query): - name = "shape" + +class Rule(Query): + """ + No documentation available. + + :arg ruleset_ids: None + :arg match_criteria: None + :arg organic: None + """ + name = "rule" + _param_defs = { + "organic": {'type': 'query'}, + } + + def __init__( + self, + *, + ruleset_ids: List[str], + match_criteria: Any, + organic: Query, + **kwargs: Any + ): + super().__init__( + ruleset_ids=ruleset_ids, + match_criteria=match_criteria, + organic=organic, + **kwargs + ) + + +class Script(Query): + """ + Filters documents based on a provided script. The script query is + typically used in a filter context. + + :arg script: Contains a script to run as a query. This script must + return a boolean value, `true` or `false`. + """ + name = "script" + + def __init__( + self, + *, + script: "i.Script", + **kwargs: Any + ): + super().__init__( + script=script, + **kwargs + ) + + +class ScriptScore(Query): + """ + Uses a script to provide a custom score for returned documents. + + :arg query: Query used to return documents. + :arg script: Script used to compute the score of documents returned by + the query. Important: final relevance scores from the + `script_score` query cannot be negative. + :arg min_score: Documents with a score lower than this floating point + number are excluded from the search results. + """ + name = "script_score" + _param_defs = { + "query": {'type': 'query'}, + } + + def __init__( + self, + *, + query: Query, + script: "i.Script", + min_score: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + script=script, + min_score=min_score, + **kwargs + ) class Semantic(Query): + """ + A semantic query to semantic_text field types + + :arg query: The query text + :arg field: The field to query, which must be a semantic_text field + type + """ name = "semantic" + def __init__( + self, + *, + query: str, + field: str, + **kwargs: Any + ): + super().__init__( + query=query, + field=field, + **kwargs + ) + + +class Shape(Query): + """ + Queries documents that contain fields indexed using the `shape` type. + + :arg ignore_unmapped: When set to `true` the query ignores an unmapped + field and will not match any documents. + """ + name = "shape" + + def __init__( + self, + *, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + ignore_unmapped=ignore_unmapped, + **kwargs + ) + class SimpleQueryString(Query): + """ + Returns documents based on a provided query string, using a parser + with a limited but fault-tolerant syntax. + + :arg query: Query string in the simple query string syntax you wish to + parse and use for search. + :arg analyzer: Analyzer used to convert text in the query string into + tokens. + :arg analyze_wildcard: If `true`, the query attempts to analyze + wildcard terms in the query string. + :arg auto_generate_synonyms_phrase_query: If `true`, the parser + creates a match_phrase query for each multi-position token. + :arg default_operator: Default boolean logic used to interpret text in + the query string if no operators are specified. + :arg fields: Array of fields you wish to search. Accepts wildcard + expressions. You also can boost relevance scores for matches to + particular fields using a caret (`^`) notation. Defaults to the + `index.query.default_field index` setting, which has a default + value of `*`. + :arg flags: List of enabled operators for the simple query string + syntax. + :arg fuzzy_max_expansions: Maximum number of terms to which the query + expands for fuzzy matching. + :arg fuzzy_prefix_length: Number of beginning characters left + unchanged for fuzzy matching. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). + :arg lenient: If `true`, format-based errors, such as providing a text + value for a numeric field, are ignored. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg quote_field_suffix: Suffix appended to quoted text in the query + string. + """ name = "simple_query_string" + def __init__( + self, + *, + query: str, + analyzer: Union[str, "NotSet"] = NOT_SET, + analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + flags: Union["PipeSeparatedFlags", "NotSet"] = NOT_SET, + fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, + fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + quote_field_suffix: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + query=query, + analyzer=analyzer, + analyze_wildcard=analyze_wildcard, + auto_generate_synonyms_phrase_query=auto_generate_synonyms_phrase_query, + default_operator=default_operator, + fields=fields, + flags=flags, + fuzzy_max_expansions=fuzzy_max_expansions, + fuzzy_prefix_length=fuzzy_prefix_length, + fuzzy_transpositions=fuzzy_transpositions, + lenient=lenient, + minimum_should_match=minimum_should_match, + quote_field_suffix=quote_field_suffix, + **kwargs + ) + + +class SpanContaining(Query): + """ + Returns matches which enclose another span query. + + :arg little: Can be any span query. Matching spans from `big` that + contain matches from `little` are returned. + :arg big: Can be any span query. Matching spans from `big` that + contain matches from `little` are returned. + """ + name = "span_containing" + + def __init__( + self, + *, + little: "i.SpanQuery", + big: "i.SpanQuery", + **kwargs: Any + ): + super().__init__( + little=little, + big=big, + **kwargs + ) + + +class SpanFieldMasking(Query): + """ + Wrapper to allow span queries to participate in composite single-field + span queries by _lying_ about their search field. + + :arg query: None + :arg field: None + """ + name = "span_field_masking" + + def __init__( + self, + *, + query: "i.SpanQuery", + field: Union[str, "InstrumentedField"], + **kwargs: Any + ): + super().__init__( + query=query, + field=field, + **kwargs + ) + + +class SpanFirst(Query): + """ + Matches spans near the beginning of a field. + + :arg match: Can be any other span type query. + :arg end: Controls the maximum end position permitted in a match. + """ + name = "span_first" + + def __init__( + self, + *, + match: "i.SpanQuery", + end: int, + **kwargs: Any + ): + super().__init__( + match=match, + end=end, + **kwargs + ) + + +class SpanMulti(Query): + """ + Allows you to wrap a multi term query (one of `wildcard`, `fuzzy`, + `prefix`, `range`, or `regexp` query) as a `span` query, so it can be + nested. + + :arg match: Should be a multi term query (one of `wildcard`, `fuzzy`, + `prefix`, `range`, or `regexp` query). + """ + name = "span_multi" + _param_defs = { + "match": {'type': 'query'}, + } + + def __init__( + self, + *, + match: Query, + **kwargs: Any + ): + super().__init__( + match=match, + **kwargs + ) + + +class SpanNear(Query): + """ + Matches spans which are near one another. You can specify `slop`, the + maximum number of intervening unmatched positions, as well as whether + matches are required to be in-order. + + :arg clauses: Array of one or more other span type queries. + :arg in_order: Controls whether matches are required to be in-order. + :arg slop: Controls the maximum number of intervening unmatched + positions permitted. + """ + name = "span_near" + + def __init__( + self, + *, + clauses: List["i.SpanQuery"], + in_order: Union[bool, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + clauses=clauses, + in_order=in_order, + slop=slop, + **kwargs + ) + + +class SpanNot(Query): + """ + Removes matches which overlap with another span query or which are + within x tokens before (controlled by the parameter `pre`) or y tokens + after (controlled by the parameter `post`) another span query. + + :arg exclude: Span query whose matches must not overlap those + returned. + :arg include: Span query whose matches are filtered. + :arg dist: The number of tokens from within the include span that + can’t have overlap with the exclude span. Equivalent to setting + both `pre` and `post`. + :arg post: The number of tokens after the include span that can’t have + overlap with the exclude span. + :arg pre: The number of tokens before the include span that can’t have + overlap with the exclude span. + """ + name = "span_not" + + def __init__( + self, + *, + exclude: "i.SpanQuery", + include: "i.SpanQuery", + dist: Union[int, "NotSet"] = NOT_SET, + post: Union[int, "NotSet"] = NOT_SET, + pre: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + exclude=exclude, + include=include, + dist=dist, + post=post, + pre=pre, + **kwargs + ) + + +class SpanOr(Query): + """ + Matches the union of its span clauses. + + :arg clauses: Array of one or more other span type queries. + """ + name = "span_or" + + def __init__( + self, + *, + clauses: List["i.SpanQuery"], + **kwargs: Any + ): + super().__init__( + clauses=clauses, + **kwargs + ) + class SpanTerm(Query): + """ + Matches spans containing a term. + + :arg field: Field to use + :arg value: Field value + """ name = "span_term" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.SpanTermQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class Template(Query): - name = "template" + +class SpanWithin(Query): + """ + Returns matches which are enclosed inside another span query. + + :arg little: Can be any span query. Matching spans from `little` that + are enclosed within `big` are returned. + :arg big: Can be any span query. Matching spans from `little` that are + enclosed within `big` are returned. + """ + name = "span_within" + + def __init__( + self, + *, + little: "i.SpanQuery", + big: "i.SpanQuery", + **kwargs: Any + ): + super().__init__( + little=little, + big=big, + **kwargs + ) + + +class SparseVector(Query): + """ + Using input query vectors or a natural language processing model to + convert a query into a list of token-weight pairs, queries against a + sparse vector field. + + :arg field: The name of the field that contains the token-weight pairs + to be searched against. This field must be a mapped sparse_vector + field. + :arg query_vector: Dictionary of precomputed sparse vectors and their + associated weights. Only one of inference_id or query_vector may + be supplied in a request. + :arg inference_id: The inference ID to use to convert the query text + into token-weight pairs. It must be the same inference ID that was + used to create the tokens from the input text. Only one of + inference_id and query_vector is allowed. If inference_id is + specified, query must also be specified. Only one of inference_id + or query_vector may be supplied in a request. + :arg query: The query text you want to use for search. If inference_id + is specified, query must also be specified. + :arg prune: Whether to perform pruning, omitting the non-significant + tokens from the query to improve query performance. If prune is + true but the pruning_config is not specified, pruning will occur + but default values will be used. Default: false + :arg pruning_config: Optional pruning configuration. If enabled, this + will omit non-significant tokens from the query in order to + improve query performance. This is only used if prune is set to + true. If prune is set to true but pruning_config is not specified, + default values will be used. + """ + name = "sparse_vector" + + def __init__( + self, + *, + field: Union[str, "InstrumentedField"], + query_vector: Union[Mapping[str, float], "NotSet"] = NOT_SET, + inference_id: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + prune: Union[bool, "NotSet"] = NOT_SET, + pruning_config: Union["i.TokenPruningConfig", "NotSet"] = NOT_SET, + **kwargs: Any + ): + super().__init__( + field=field, + query_vector=query_vector, + inference_id=inference_id, + query=query, + prune=prune, + pruning_config=pruning_config, + **kwargs + ) class Term(Query): + """ + Returns documents that contain an exact term in a provided field. To + return a document, the query term must exactly match the queried + field's value, including whitespace and capitalization. + + :arg field: Field to use + :arg value: Field value + """ name = "term" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.TermQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + class Terms(Query): + """ + Returns documents that contain one or more exact terms in a provided + field. To return a document, one or more terms must exactly match a + field value, including whitespace and capitalization. + """ name = "terms" + def __init__( + self, + **kwargs: Any + ): + super().__init__( + **kwargs + ) + def _setattr(self, name: str, value: Any) -> None: # here we convert any iterables that are not strings to lists if hasattr(value, "__iter__") and not isinstance(value, (str, list)): @@ -558,33 +2091,137 @@ def _setattr(self, name: str, value: Any) -> None: class TermsSet(Query): + """ + Returns documents that contain a minimum number of exact terms in a + provided field. To return a document, a required number of terms must + exactly match the field values, including whitespace and + capitalization. + + :arg field: Field to use + :arg value: Field value + """ name = "terms_set" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.TermsSetQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + class TextExpansion(Query): + """ + Uses a natural language processing model to convert the query text + into a list of token-weight pairs which are then used in a query + against a sparse vector or rank features field. + + :arg field: Field to use + :arg value: Field value + """ name = "text_expansion" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.TextExpansionQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + + +class WeightedTokens(Query): + """ + Supports returning text_expansion query results by sending in + precomputed tokens with the query. + + :arg field: Field to use + :arg value: Field value + """ + name = "weighted_tokens" + + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.WeightedTokensQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) + class Wildcard(Query): + """ + Returns documents that contain terms matching a wildcard pattern. + + :arg field: Field to use + :arg value: Field value + """ name = "wildcard" + def __init__( + self, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + value: Union["i.WildcardQuery", "NotSet"] = NOT_SET, + **kwargs: Any + ): + if field != NOT_SET: + kwargs[str(field)] = value + super().__init__( + **kwargs + ) -class Script(Query): - name = "script" +class Wrapper(Query): + """ + A query that accepts any other query as base64 encoded string. -class ScriptScore(Query): - name = "script_score" - _param_defs = {"query": {"type": "query"}} + :arg query: A base64 encoded query. The binary data format can be any + of JSON, YAML, CBOR or SMILE encodings + """ + name = "wrapper" + + def __init__( + self, + *, + query: str, + **kwargs: Any + ): + super().__init__( + query=query, + **kwargs + ) class Type(Query): - name = "type" + """ + No documentation available. + :arg value: None + """ + name = "type" -class ParentId(Query): - name = "parent_id" + def __init__( + self, + *, + value: str, + **kwargs: Any + ): + super().__init__( + value=value, + **kwargs + ) -class Wrapper(Query): - name = "wrapper" diff --git a/elasticsearch_dsl/utils.py b/elasticsearch_dsl/utils.py index d9727f1e..4c9d2c0f 100644 --- a/elasticsearch_dsl/utils.py +++ b/elasticsearch_dsl/utils.py @@ -97,6 +97,13 @@ def _recursive_to_dict(value: Any) -> Any: return value +class NotSet: + pass + + +NOT_SET = NotSet() + + class AttrList(Generic[_ValT]): def __init__( self, l: List[_ValT], obj_wrapper: Optional[Callable[[_ValT], Any]] = None @@ -328,6 +335,8 @@ def __init__(self, _expand__to_dot: Optional[bool] = None, **params: Any) -> Non _expand__to_dot = EXPAND__TO_DOT self._params: Dict[str, Any] = {} for pname, pvalue in params.items(): + if pvalue == NOT_SET: + continue # expand "__" to dots if "__" in pname and _expand__to_dot: pname = pname.replace("__", ".") diff --git a/noxfile.py b/noxfile.py index 0f941e9b..98f8263f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -57,8 +57,9 @@ def test(session): @nox.session(python="3.12") def format(session): - session.install("black~=24.0", "isort", "unasync", "setuptools") + session.install("black~=24.0", "isort", "unasync", "setuptools", ".[develop]") session.run("python", "utils/run-unasync.py") + session.run("python", "utils/generator.py", env={"PYTHONPATH": "./"}) session.run("black", "--target-version=py38", *SOURCE_FILES) session.run("isort", *SOURCE_FILES) session.run("python", "utils/license-headers.py", "fix", *SOURCE_FILES) diff --git a/setup.py b/setup.py index 98260e0e..c473e720 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ develop_requires = [ "elasticsearch[async]", "unasync", + "jinja2", "pytest", "pytest-cov", "pytest-mock", diff --git a/utils/generator.py b/utils/generator.py new file mode 100644 index 00000000..b8e2d5f3 --- /dev/null +++ b/utils/generator.py @@ -0,0 +1,311 @@ +from elasticsearch_dsl import VERSION +import json +import textwrap +from urllib.request import urlopen +from urllib.error import HTTPError +from jinja2 import Environment, PackageLoader, select_autoescape + +jinja_env = Environment( + loader=PackageLoader("utils"), + autoescape=select_autoescape(), + trim_blocks=True, + lstrip_blocks=True, +) +query_py = jinja_env.get_template("query.py.tpl") +interfaces_py = jinja_env.get_template("interfaces.py.tpl") + + +def wrapped_doc(text, width=70, initial_indent="", subsequent_indent=""): + """Formats a docstring as a list of lines of up to the request width.""" + return textwrap.wrap( + (text or "No documentation available.").replace("\n", " "), + width=width, + initial_indent=initial_indent, + subsequent_indent=subsequent_indent, + ) + + +def add_not_set(type_): + """Add NotSet to a Python type hint.""" + if type_.startswith("Union["): + type_ = f'{type_[:-1]}, "NotSet"]' + else: + type_ = f'Union[{type_}, "NotSet"]' + return type_ + + +class ElasticsearchSchema: + def __init__(self): + response = None + for branch in [f"{VERSION[0]}.{VERSION[1]}", "main"]: + url = f"https://raw.githubusercontent.com/elastic/elasticsearch-specification/{branch}/output/schema/schema.json" + try: + response = urlopen(url) + break + except HTTPError: + continue + if not response: + raise RuntimeError("Could not download Elasticsearch schema") + self.schema = json.loads(response.read()) + self.interfaces = set() + + def find_type(self, name, namespace=None): + for t in self.schema["types"]: + if t["name"]["name"] == name and ( + namespace is None or t["name"]["namespace"] == namespace + ): + return t + + def reset_interfaces(self): + self.interfaces = set() + + def get_python_type(self, schema_type): + if schema_type["kind"] == "instance_of": + type_name = schema_type["type"] + if type_name["namespace"] in ["_types", "internal", "_builtins"]: + if type_name["name"] in ["integer", "uint", "long", "ulong"]: + return "int", None + elif type_name["name"] in ["number", "float", "double"]: + return "float", None + elif type_name["name"] == "string": + return "str", None + elif type_name["name"] == "boolean": + return "bool", None + elif type_name["name"] == "binary": + return "bytes", None + elif type_name["name"] == "null": + return "None", None + elif type_name["name"] == "Field": + return 'Union[str, "InstrumentedField"]', None + else: + return self.get_python_type( + self.find_type(type_name["name"], type_name["namespace"]) + ) + elif ( + type_name["namespace"] == "_types.query_dsl" + and type_name["name"] == "QueryContainer" + ): + return "Query", {"type": "query"} + else: + type_ = self.find_type(type_name["name"], type_name["namespace"]) + if type_: + return self.get_python_type(type_) + + elif schema_type["kind"] == "type_alias": + return self.get_python_type(schema_type["type"]) + + elif schema_type["kind"] == "array_of": + type_, param = self.get_python_type(schema_type["value"]) + return f"List[{type_}]", None + + elif schema_type["kind"] == "dictionary_of": + key_type, key_param = self.get_python_type(schema_type["key"]) + value_type, value_param = self.get_python_type(schema_type["value"]) + return f"Mapping[{key_type}, {value_type}]", None + + elif schema_type["kind"] == "union_of": + if ( + len(schema_type["items"]) == 2 + and schema_type["items"][0]["kind"] == "instance_of" + and schema_type["items"][1]["kind"] == "array_of" + and schema_type["items"][0] == schema_type["items"][1]["value"] + ): + type_, param = self.get_python_type(schema_type["items"][0]) + return f"Union[{type_}, List[{type_}]]", ( + {"type": param["type"], "multi": True} if param else None + ) + elif ( + len(schema_type["items"]) == 2 + and schema_type["items"][0]["kind"] == "instance_of" + and schema_type["items"][1]["kind"] == "instance_of" + and schema_type["items"][0]["type"] + == {"name": "T", "namespace": "_spec_utils.PipeSeparatedFlags"} + ): + self.interfaces.add("PipeSeparatedFlags") + return '"PipeSeparatedFlags"', None + else: + types = [self.get_python_type(t) for t in schema_type["items"]] + return "Union[" + ", ".join([type_ for type_, _ in types]) + "]", None + + elif schema_type["kind"] == "enum": + return ( + "Literal[" + + ", ".join( + [f"\"{member['name']}\"" for member in schema_type["members"]] + ) + + "]", + None, + ) + + elif schema_type["kind"] == "interface": + if schema_type["name"]["namespace"] == "_types.query_dsl": + if schema_type["name"]["name"].endswith("RangeQuery"): + return '"wrappers.Range"', None + elif schema_type["name"]["name"].endswith("Function"): + return f"\"function.{schema_type['name']['name']}\"", None + elif schema_type["name"]["namespace"] == "_types.analysis" and schema_type[ + "name" + ]["name"].endswith("Analyzer"): + return f"\"analysis.{schema_type['name']['name']}\"", None + self.interfaces.add(schema_type["name"]["name"]) + return f"\"i.{schema_type['name']['name']}\"", None + elif schema_type["kind"] == "user_defined_value": + return "Any", None + + raise RuntimeError(f"Cannot find Python type for {schema_type}") + + +def generate_query_classes(schema, filename): + classes = [] + query_container = schema.find_type("QueryContainer", "_types.query_dsl") + for p in query_container["properties"]: + k = {"schema": p, "name": "".join([w.title() for w in p["name"].split("_")])} + k["docstring"] = wrapped_doc(p.get("description")) + kind = p["type"]["kind"] + if kind == "instance_of": + instance = schema.find_type( + p["type"]["type"]["name"], p["type"]["type"]["namespace"] + ) + if instance["kind"] == "interface": + k["kwargs"] = [] + k["params"] = [] + for arg in instance["properties"]: + type_, param = schema.get_python_type(arg["type"]) + if arg["required"] is False and type_ != "Any": + type_ = add_not_set(type_) + doc = wrapped_doc( + f":arg {arg['name']}: {arg.get('description')}", + subsequent_indent=" ", + ) + if arg["required"] is False: + k["kwargs"].append( + { + "name": arg["name"], + "type": type_, + "doc": doc, + "required": False, + } + ) + else: + i = 0 + for i in range(len(k["kwargs"])): + if k["kwargs"][i]["required"] is False: + break + k["kwargs"].insert( + i, + { + "name": arg["name"], + "type": type_, + "doc": doc, + "required": True, + }, + ) + if param is not None: + k["params"].append({"name": arg["name"], "param": param}) + + elif kind == "dictionary_of": + key_type, _ = schema.get_python_type(p["type"]["key"]) + if "InstrumentedField" in key_type: + value_type, _ = schema.get_python_type(p["type"]["value"]) + if p["type"]["singleKey"]: + k["kwargs"] = [ + { + "name": "field", + "type": add_not_set(key_type), + "doc": [":arg field: Field to use"], + "required": False, + }, + { + "name": "value", + "type": add_not_set(value_type), + "doc": [":arg value: Field value"], + "required": False, + }, + ] + k["has_field"] = True + else: + k["kwargs"] = [ + { + "name": "fields", + "type": f"Optional[Mapping[{key_type}, {value_type}]]", + "doc": [ + ":arg fields: A dictionary of fields with their values." + ], + "required": False, + }, + ] + k["has_fields"] = True + else: + raise RuntimeError(f"Cannot generate code for type {p['type']}") + + else: + raise RuntimeError(f"Cannot generate code for type {p['type']}") + classes.append(k) + + with open(filename, "wt") as f: + f.write( + query_py.render( + classes=classes, parent="Query", interfaces=sorted(schema.interfaces) + ) + ) + + +def generate_interfaces(schema, interfaces, filename): + classes = {} + for interface in interfaces: + if interface == "PipeSeparatedFlags": + continue # handled as a special case + type_ = schema.find_type(interface) + if type_["kind"] != "interface": + raise RuntimeError(f"Type {interface} is not an interface") + if "inherits" in type_ and "type" in type_["inherits"]: + parent = type_["inherits"]["type"]["name"] + base = type_ + while base and "inherits" in base and "type" in base["inherits"]: + if base["inherits"]["type"]["name"] not in interfaces: + interfaces.append(base["inherits"]["type"]["name"]) + base = schema.find_type( + base["inherits"]["type"]["name"], + base["inherits"]["type"]["namespace"], + ) + else: + parent = None + k = {"name": interface, "parent": parent, "properties": []} + schema.reset_interfaces() + for p in type_["properties"]: + type_, param = schema.get_python_type(p["type"]) + k["properties"].append({"name": p["name"], "type": type_}) + for new_interface in schema.interfaces: + if new_interface not in interfaces: + interfaces.append(new_interface) + classes[k["name"]] = k + + classes_list = [] + for n in classes: + k = classes[n] + try: + classes_list.index(k) + continue + except ValueError: + pass + classes_list.append(k) + parent = k.get("parent") + parent_index = len(classes_list) - 1 + while parent: + try: + classes_list.index(classes[parent]) + break + except ValueError: + pass + classes_list.insert(parent_index, classes[parent]) + parent = classes[parent].get("parent") + + with open(filename, "wt") as f: + f.write(interfaces_py.render(classes=classes_list)) + + +if __name__ == "__main__": + schema = ElasticsearchSchema() + generate_query_classes(schema, "elasticsearch_dsl/query.py") + interfaces = schema.interfaces + generate_interfaces(schema, list(interfaces), "elasticsearch_dsl/interfaces.py") diff --git a/utils/templates/dsl_classes.tpl b/utils/templates/dsl_classes.tpl new file mode 100644 index 00000000..c94a5455 --- /dev/null +++ b/utils/templates/dsl_classes.tpl @@ -0,0 +1,204 @@ +{% for k in classes %} +class {{ k.name }}({{ parent }}): + """ + {% for line in k.docstring %} + {{ line }} + {% endfor %} + {% if k.kwargs %} + + {% for kwarg in k.kwargs %} + {% for line in kwarg.doc %} + {{ line }} + {% endfor %} + {% endfor %} + {% endif %} + """ + name = "{{ k.schema.name }}" + {% if k.params %} + _param_defs = { + {% for param in k.params %} + "{{ param.name }}": {{ param.param }}, + {% endfor %} + } + {% endif %} + + def __init__( + self, + {% if k.kwargs and not k.has_field and not k.has_fields %} + *, + {% endif %} + {% for kwarg in k.kwargs %} + {{ kwarg.name }}: {{ kwarg.type }}{% if not kwarg.required %} = NOT_SET{% endif %}, + {% endfor %} + **kwargs: Any + ): + {% if k.name == "FunctionScore" %} + if functions is None: + functions = [] + for name in ScoreFunction._classes: + if name in kwargs: + functions.append({name: kwargs.pop(name)}) + {% elif k.has_field %} + if field != NOT_SET: + kwargs[str(field)] = value + {% elif k.has_fields %} + if fields != NOT_SET: + for field, value in field.items(): + kwargs[str(field)] = value + {% endif %} + super().__init__( + {% if not k.has_field and not k.has_fields %} + {% for kwarg in k.kwargs %} + {{ kwarg.name }}={{ kwarg.name }}, + {% endfor %} + {% endif %} + **kwargs + ) + + {% if k.name == "MatchAll" %} + def __add__(self, other: "Query") -> "Query": + return other._clone() + + __and__ = __rand__ = __radd__ = __add__ + + def __or__(self, other: "Query") -> "MatchAll": + return self + + __ror__ = __or__ + + def __invert__(self) -> "MatchNone": + return MatchNone() + + +EMPTY_QUERY = MatchAll() + + {% elif k.name == "MatchNone" %} + def __add__(self, other: "Query") -> "MatchNone": + return self + + __and__ = __rand__ = __radd__ = __add__ + + def __or__(self, other: "Query") -> "Query": + return other._clone() + + __ror__ = __or__ + + def __invert__(self) -> MatchAll: + return MatchAll() + + {% elif k.name == "Bool" %} + def __add__(self, other: Query) -> "Bool": + q = self._clone() + if isinstance(other, Bool): + q.must += other.must + q.should += other.should + q.must_not += other.must_not + q.filter += other.filter + else: + q.must.append(other) + return q + + __radd__ = __add__ + + def __or__(self, other: Query) -> Query: + for q in (self, other): + if isinstance(q, Bool) and not any( + (q.must, q.must_not, q.filter, getattr(q, "minimum_should_match", None)) + ): + other = self if q is other else other + q = q._clone() + if isinstance(other, Bool) and not any( + ( + other.must, + other.must_not, + other.filter, + getattr(other, "minimum_should_match", None), + ) + ): + q.should.extend(other.should) + else: + q.should.append(other) + return q + + return Bool(should=[self, other]) + + __ror__ = __or__ + + @property + def _min_should_match(self) -> int: + return getattr( + self, + "minimum_should_match", + 0 if not self.should or (self.must or self.filter) else 1, + ) + + def __invert__(self) -> Query: + # Because an empty Bool query is treated like + # MatchAll the inverse should be MatchNone + if not any(chain(self.must, self.filter, self.should, self.must_not)): + return MatchNone() + + negations: List[Query] = [] + for q in chain(self.must, self.filter): + negations.append(~q) + + for q in self.must_not: + negations.append(q) + + if self.should and self._min_should_match: + negations.append(Bool(must_not=self.should[:])) + + if len(negations) == 1: + return negations[0] + return Bool(should=negations) + + def __and__(self, other: Query) -> Query: + q = self._clone() + if isinstance(other, Bool): + q.must += other.must + q.must_not += other.must_not + q.filter += other.filter + q.should = [] + + # reset minimum_should_match as it will get calculated below + if "minimum_should_match" in q._params: + del q._params["minimum_should_match"] + + for qx in (self, other): + min_should_match = qx._min_should_match + # TODO: percentages or negative numbers will fail here + # for now we report an error + if not isinstance(min_should_match, int) or min_should_match < 0: + raise ValueError( + "Can only combine queries with positive integer values for minimum_should_match" + ) + # all subqueries are required + if len(qx.should) <= min_should_match: + q.must.extend(qx.should) + # not all of them are required, use it and remember min_should_match + elif not q.should: + q.minimum_should_match = min_should_match + q.should = qx.should + # all queries are optional, just extend should + elif q._min_should_match == 0 and min_should_match == 0: + q.should.extend(qx.should) + # not all are required, add a should list to the must with proper min_should_match + else: + q.must.append( + Bool(should=qx.should, minimum_should_match=min_should_match) + ) + else: + if not (q.must or q.filter) and q.should: + q._params.setdefault("minimum_should_match", 1) + q.must.append(other) + return q + + __rand__ = __and__ + + {% elif k.name == "Terms" %} + def _setattr(self, name: str, value: Any) -> None: + super()._setattr(name, list(value)) + + {% endif %} + +{% endfor %} diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl new file mode 100644 index 00000000..6fa29cc9 --- /dev/null +++ b/utils/templates/interfaces.py.tpl @@ -0,0 +1,22 @@ +from typing import TYPE_CHECKING, Any, List, Literal, Mapping, TypedDict, Union +from elasticsearch_dsl.search_base import InstrumentedField +from elasticsearch_dsl.utils import AttrDict + +if TYPE_CHECKING: + from elasticsearch_dsl import analysis, function, wrappers + +PipeSeparatedFlags = str + + +{% for k in classes %} +class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}TypedDict{% endif %}): + {% if k.properties %} + {% for p in k.properties %} + {{ p.name }}: {{ p.type }} + {% endfor %} + {% else %} + pass + {% endif %} + + +{% endfor %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl new file mode 100644 index 00000000..0fa9aff3 --- /dev/null +++ b/utils/templates/query.py.tpl @@ -0,0 +1,145 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import collections.abc +from copy import deepcopy +from itertools import chain +from typing import ( + TYPE_CHECKING, + Any, + Callable, + ClassVar, + List, + Literal, + Mapping, + MutableMapping, + Optional, + Protocol, + TypeVar, + Union, + cast, + overload, +) + +# 'SF' looks unused but the test suite assumes it's available +# from this module so others are liable to do so as well. +from .function import SF # noqa: F401 +from .function import ScoreFunction +from .utils import DslBase, NOT_SET + +if TYPE_CHECKING: + from .document_base import InstrumentedField + from .utils import NotSet + from elasticsearch_dsl import interfaces as i + +_T = TypeVar("_T") +_M = TypeVar("_M", bound=Mapping[str, Any]) + + +class QProxiedProtocol(Protocol[_T]): + _proxied: _T + + +@overload +def Q(name_or_query: MutableMapping[str, _M]) -> "Query": ... + + +@overload +def Q(name_or_query: "Query") -> "Query": ... + + +@overload +def Q(name_or_query: QProxiedProtocol[_T]) -> _T: ... + + +@overload +def Q(name_or_query: str = "match_all", **params: Any) -> "Query": ... + + +def Q( + name_or_query: Union[ + str, + "Query", + QProxiedProtocol[_T], + MutableMapping[str, _M], + ] = "match_all", + **params: Any, +) -> Union["Query", _T]: + # {"match": {"title": "python"}} + if isinstance(name_or_query, collections.abc.MutableMapping): + if params: + raise ValueError("Q() cannot accept parameters when passing in a dict.") + if len(name_or_query) != 1: + raise ValueError( + 'Q() can only accept dict with a single query ({"match": {...}}). ' + "Instead it got (%r)" % name_or_query + ) + name, q_params = deepcopy(name_or_query).popitem() + return Query.get_dsl_class(name)(_expand__to_dot=False, **q_params) + + # MatchAll() + if isinstance(name_or_query, Query): + if params: + raise ValueError( + "Q() cannot accept parameters when passing in a Query object." + ) + return name_or_query + + # s.query = Q('filtered', query=s.query) + if hasattr(name_or_query, "_proxied"): + return cast(QProxiedProtocol[_T], name_or_query)._proxied + + # "match", title="python" + return Query.get_dsl_class(name_or_query)(**params) + + +class Query(DslBase): + _type_name = "query" + _type_shortcut = staticmethod(Q) + name: ClassVar[Optional[str]] = None + + # Add type annotations for methods not defined in every subclass + __ror__: ClassVar[Callable[["Query", "Query"], "Query"]] + __radd__: ClassVar[Callable[["Query", "Query"], "Query"]] + __rand__: ClassVar[Callable[["Query", "Query"], "Query"]] + + def __add__(self, other: "Query") -> "Query": + # make sure we give queries that know how to combine themselves + # preference + if hasattr(other, "__radd__"): + return other.__radd__(self) + return Bool(must=[self, other]) + + def __invert__(self) -> "Query": + return Bool(must_not=[self]) + + def __or__(self, other: "Query") -> "Query": + # make sure we give queries that know how to combine themselves + # preference + if hasattr(other, "__ror__"): + return other.__ror__(self) + return Bool(should=[self, other]) + + def __and__(self, other: "Query") -> "Query": + # make sure we give queries that know how to combine themselves + # preference + if hasattr(other, "__rand__"): + return other.__rand__(self) + return Bool(must=[self, other]) + + +{% include "dsl_classes.tpl" %} From 47f0e4dd16583fe6599dfabf20fc711f5ed4d6ef Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 28 Aug 2024 19:12:16 +0100 Subject: [PATCH 02/27] handle Python reserved keywords such as from --- elasticsearch_dsl/interfaces.py | 483 +++++++++++++---------- elasticsearch_dsl/query.py | 622 +++++++++++++----------------- elasticsearch_dsl/utils.py | 11 +- utils/generator.py | 35 +- utils/templates/interfaces.py.tpl | 7 +- utils/templates/query.py.tpl | 2 +- 6 files changed, 571 insertions(+), 589 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index a92d3239..c630c1a1 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -1,9 +1,25 @@ -from typing import TYPE_CHECKING, Any, List, Literal, Mapping, TypedDict, Union +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from typing import Any, List, Literal, Mapping, TypedDict, Union + +from elasticsearch_dsl import Query, analysis, function +from elasticsearch_dsl import interfaces as i from elasticsearch_dsl.search_base import InstrumentedField -from elasticsearch_dsl.utils import AttrDict - -if TYPE_CHECKING: - from elasticsearch_dsl import analysis, function, wrappers PipeSeparatedFlags = str @@ -13,47 +29,61 @@ class QueryBase(TypedDict): _name: str -class FuzzyQuery(QueryBase): - max_expansions: int - prefix_length: int - rewrite: str - transpositions: bool - fuzziness: Union[str, int] - value: Union[str, float, bool] - - -class SpanTermQuery(QueryBase): - value: str +class TermQuery(QueryBase): + value: Union[int, float, str, bool, None, Any] + case_insensitive: bool -class CommonTermsQuery(QueryBase): +class MatchPhrasePrefixQuery(QueryBase): analyzer: str - cutoff_frequency: float - high_freq_operator: Literal["and", "or"] - low_freq_operator: Literal["and", "or"] - minimum_should_match: Union[int, str] + max_expansions: int query: str + slop: int + zero_terms_query: Literal["all", "none"] class RankFeatureFunction(TypedDict): pass -class RankFeatureFunctionSaturation(RankFeatureFunction): - pivot: float +class RankFeatureFunctionLogarithm(RankFeatureFunction): + scaling_factor: float -class MatchPhraseQuery(QueryBase): +class CommonTermsQuery(QueryBase): analyzer: str + cutoff_frequency: float + high_freq_operator: Literal["and", "or"] + low_freq_operator: Literal["and", "or"] + minimum_should_match: Union[int, str] query: str - slop: int - zero_terms_query: Literal["all", "none"] + + +class PrefixQuery(QueryBase): + rewrite: str + value: str + case_insensitive: bool class FunctionScoreContainer(TypedDict): - exp: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] - gauss: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] - linear: Union["function.UntypedDecayFunction", "function.DateDecayFunction", "function.NumericDecayFunction", "function.GeoDecayFunction"] + exp: Union[ + "function.UntypedDecayFunction", + "function.DateDecayFunction", + "function.NumericDecayFunction", + "function.GeoDecayFunction", + ] + gauss: Union[ + "function.UntypedDecayFunction", + "function.DateDecayFunction", + "function.NumericDecayFunction", + "function.GeoDecayFunction", + ] + linear: Union[ + "function.UntypedDecayFunction", + "function.DateDecayFunction", + "function.NumericDecayFunction", + "function.GeoDecayFunction", + ] field_value_factor: "function.FieldValueFactorScoreFunction" random_score: "function.RandomScoreFunction" script_score: "function.ScriptScoreFunction" @@ -61,40 +91,6 @@ class FunctionScoreContainer(TypedDict): weight: float -class InnerHits(TypedDict): - name: str - size: int - from: int - collapse: "i.FieldCollapse" - docvalue_fields: List["i.FieldAndFormat"] - explain: bool - highlight: "i.Highlight" - ignore_unmapped: bool - script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] - seq_no_primary_term: bool - fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] - sort: Union[Union[Union[str, "InstrumentedField"], "i.SortOptions"], List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]]] - _source: Union[bool, "i.SourceFilter"] - stored_fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] - track_scores: bool - version: bool - - -class WildcardQuery(QueryBase): - case_insensitive: bool - rewrite: str - value: str - wildcard: str - - -class RegexpQuery(QueryBase): - case_insensitive: bool - flags: str - max_determinized_states: int - rewrite: str - value: str - - class LikeDocument(TypedDict): doc: Any fields: List[Union[str, "InstrumentedField"]] @@ -106,57 +102,58 @@ class LikeDocument(TypedDict): version_type: Literal["internal", "external", "external_gte", "force"] -class TermsSetQuery(QueryBase): - minimum_should_match_field: Union[str, "InstrumentedField"] - minimum_should_match_script: "i.Script" - terms: List[str] - - -class SpanQuery(TypedDict): - span_containing: "i.SpanContainingQuery" - span_field_masking: "i.SpanFieldMaskingQuery" - span_first: "i.SpanFirstQuery" - span_gap: Mapping[Union[str, "InstrumentedField"], int] - span_multi: "i.SpanMultiTermQuery" - span_near: "i.SpanNearQuery" - span_not: "i.SpanNotQuery" - span_or: "i.SpanOrQuery" - span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] - span_within: "i.SpanWithinQuery" +class TokenPruningConfig(TypedDict): + tokens_freq_ratio_threshold: int + tokens_weight_threshold: float + only_score_pruned_tokens: bool -class PrefixQuery(QueryBase): +class WildcardQuery(QueryBase): + case_insensitive: bool rewrite: str value: str - case_insensitive: bool + wildcard: str -class TokenPruningConfig(TypedDict): - tokens_freq_ratio_threshold: int - tokens_weight_threshold: float - only_score_pruned_tokens: bool +class WeightedTokensQuery(QueryBase): + tokens: Mapping[str, float] + pruning_config: "i.TokenPruningConfig" -class RankFeatureFunctionLinear(RankFeatureFunction): - pass +class RankFeatureFunctionSaturation(RankFeatureFunction): + pivot: float -class TextExpansionQuery(QueryBase): - model_id: str - model_text: str - pruning_config: "i.TokenPruningConfig" +class MatchPhraseQuery(QueryBase): + analyzer: str + query: str + slop: int + zero_terms_query: Literal["all", "none"] -class MatchBoolPrefixQuery(QueryBase): +class MatchQuery(QueryBase): analyzer: str + auto_generate_synonyms_phrase_query: bool + cutoff_frequency: float fuzziness: Union[str, int] fuzzy_rewrite: str fuzzy_transpositions: bool + lenient: bool max_expansions: int minimum_should_match: Union[int, str] operator: Literal["and", "or"] prefix_length: int - query: str + query: Union[str, float, bool] + zero_terms_query: Literal["all", "none"] + + +class QueryVectorBuilder(TypedDict): + text_embedding: "i.TextEmbedding" + + +class PinnedDoc(TypedDict): + _id: str + _index: str class Script(TypedDict): @@ -167,13 +164,54 @@ class Script(TypedDict): options: Mapping[str, str] -class PinnedDoc(TypedDict): - _id: str - _index: str +class RankFeatureFunctionLinear(RankFeatureFunction): + pass -class QueryVectorBuilder(TypedDict): - text_embedding: "i.TextEmbedding" +class MatchBoolPrefixQuery(QueryBase): + analyzer: str + fuzziness: Union[str, int] + fuzzy_rewrite: str + fuzzy_transpositions: bool + max_expansions: int + minimum_should_match: Union[int, str] + operator: Literal["and", "or"] + prefix_length: int + query: str + + +class InnerHits(TypedDict): + name: str + size: int + from_: int + collapse: "i.FieldCollapse" + docvalue_fields: List["i.FieldAndFormat"] + explain: bool + highlight: "i.Highlight" + ignore_unmapped: bool + script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] + seq_no_primary_term: bool + fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + ] + _source: Union[bool, "i.SourceFilter"] + stored_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + track_scores: bool + version: bool + + +class RegexpQuery(QueryBase): + case_insensitive: bool + flags: str + max_determinized_states: int + rewrite: str + value: str class RankFeatureFunctionSigmoid(RankFeatureFunction): @@ -181,6 +219,15 @@ class RankFeatureFunctionSigmoid(RankFeatureFunction): exponent: float +class FuzzyQuery(QueryBase): + max_expansions: int + prefix_length: int + rewrite: str + transpositions: bool + fuzziness: Union[str, int] + value: Union[str, float, bool] + + class IntervalsQuery(QueryBase): all_of: "i.IntervalsAllOf" any_of: "i.IntervalsAnyOf" @@ -190,58 +237,52 @@ class IntervalsQuery(QueryBase): wildcard: "i.IntervalsWildcard" -class RankFeatureFunctionLogarithm(RankFeatureFunction): - scaling_factor: float - - -class TermQuery(QueryBase): - value: Union[int, float, str, bool, None, Any] - case_insensitive: bool +class SpanTermQuery(QueryBase): + value: str -class MatchQuery(QueryBase): - analyzer: str - auto_generate_synonyms_phrase_query: bool - cutoff_frequency: float - fuzziness: Union[str, int] - fuzzy_rewrite: str - fuzzy_transpositions: bool - lenient: bool - max_expansions: int - minimum_should_match: Union[int, str] - operator: Literal["and", "or"] - prefix_length: int - query: Union[str, float, bool] - zero_terms_query: Literal["all", "none"] +class TermsSetQuery(QueryBase): + minimum_should_match_field: Union[str, "InstrumentedField"] + minimum_should_match_script: "i.Script" + terms: List[str] -class WeightedTokensQuery(QueryBase): - tokens: Mapping[str, float] +class TextExpansionQuery(QueryBase): + model_id: str + model_text: str pruning_config: "i.TokenPruningConfig" -class MatchPhrasePrefixQuery(QueryBase): - analyzer: str - max_expansions: int - query: str - slop: int - zero_terms_query: Literal["all", "none"] +class SpanQuery(TypedDict): + span_containing: "i.SpanContainingQuery" + span_field_masking: "i.SpanFieldMaskingQuery" + span_first: "i.SpanFirstQuery" + span_gap: Mapping[Union[str, "InstrumentedField"], int] + span_multi: "i.SpanMultiTermQuery" + span_near: "i.SpanNearQuery" + span_not: "i.SpanNotQuery" + span_or: "i.SpanOrQuery" + span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] + span_within: "i.SpanWithinQuery" -class ScriptField(TypedDict): - script: "i.Script" - ignore_failure: bool +class TextEmbedding(TypedDict): + model_id: str + model_text: str -class SourceFilter(TypedDict): - excludes: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] - includes: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] +class SortOptions(TypedDict): + _score: "i.ScoreSort" + _doc: "i.ScoreSort" + _geo_distance: "i.GeoDistanceSort" + _script: "i.ScriptSort" -class FieldAndFormat(TypedDict): +class FieldCollapse(TypedDict): field: Union[str, "InstrumentedField"] - format: str - include_unmapped: bool + inner_hits: Union["i.InnerHits", List["i.InnerHits"]] + max_concurrent_group_searches: int + collapse: "i.FieldCollapse" class HighlightBase(TypedDict): @@ -273,65 +314,38 @@ class Highlight(HighlightBase): fields: Mapping[Union[str, "InstrumentedField"], "i.HighlightField"] -class FieldCollapse(TypedDict): - field: Union[str, "InstrumentedField"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"]] - max_concurrent_group_searches: int - collapse: "i.FieldCollapse" - - -class SortOptions(TypedDict): - _score: "i.ScoreSort" - _doc: "i.ScoreSort" - _geo_distance: "i.GeoDistanceSort" - _script: "i.ScriptSort" - - -class SpanMultiTermQuery(QueryBase): - match: Query - - -class SpanNotQuery(QueryBase): - dist: int - exclude: "i.SpanQuery" - include: "i.SpanQuery" - post: int - pre: int - - -class SpanWithinQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" - - -class SpanFirstQuery(QueryBase): - end: int - match: "i.SpanQuery" - - -class SpanOrQuery(QueryBase): - clauses: List["i.SpanQuery"] +class ScriptField(TypedDict): + script: "i.Script" + ignore_failure: bool -class SpanNearQuery(QueryBase): - clauses: List["i.SpanQuery"] - in_order: bool - slop: int +class FieldAndFormat(TypedDict): + field: Union[str, "InstrumentedField"] + format: str + include_unmapped: bool -class SpanFieldMaskingQuery(QueryBase): - field: Union[str, "InstrumentedField"] - query: "i.SpanQuery" +class SourceFilter(TypedDict): + excludes: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + includes: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] -class SpanContainingQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" +class IntervalsAnyOf(TypedDict): + intervals: List["i.IntervalsContainer"] + filter: "i.IntervalsFilter" -class TextEmbedding(TypedDict): - model_id: str - model_text: str +class IntervalsMatch(TypedDict): + analyzer: str + max_gaps: int + ordered: bool + query: str + use_field: Union[str, "InstrumentedField"] + filter: "i.IntervalsFilter" class IntervalsWildcard(TypedDict): @@ -340,8 +354,16 @@ class IntervalsWildcard(TypedDict): use_field: Union[str, "InstrumentedField"] -class IntervalsAnyOf(TypedDict): +class IntervalsPrefix(TypedDict): + analyzer: str + prefix: str + use_field: Union[str, "InstrumentedField"] + + +class IntervalsAllOf(TypedDict): intervals: List["i.IntervalsContainer"] + max_gaps: int + ordered: bool filter: "i.IntervalsFilter" @@ -354,32 +376,46 @@ class IntervalsFuzzy(TypedDict): use_field: Union[str, "InstrumentedField"] -class IntervalsPrefix(TypedDict): - analyzer: str - prefix: str - use_field: Union[str, "InstrumentedField"] +class SpanFirstQuery(QueryBase): + end: int + match: "i.SpanQuery" -class IntervalsMatch(TypedDict): - analyzer: str - max_gaps: int - ordered: bool - query: str - use_field: Union[str, "InstrumentedField"] - filter: "i.IntervalsFilter" +class SpanMultiTermQuery(QueryBase): + match: Query -class IntervalsAllOf(TypedDict): - intervals: List["i.IntervalsContainer"] - max_gaps: int - ordered: bool - filter: "i.IntervalsFilter" +class SpanNearQuery(QueryBase): + clauses: List["i.SpanQuery"] + in_order: bool + slop: int -class HighlightField(HighlightBase): - fragment_offset: int - matched_fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]]] - analyzer: Union["analysis.CustomAnalyzer", "analysis.FingerprintAnalyzer", "analysis.KeywordAnalyzer", "analysis.LanguageAnalyzer", "analysis.NoriAnalyzer", "analysis.PatternAnalyzer", "analysis.SimpleAnalyzer", "analysis.StandardAnalyzer", "analysis.StopAnalyzer", "analysis.WhitespaceAnalyzer", "analysis.IcuAnalyzer", "analysis.KuromojiAnalyzer", "analysis.SnowballAnalyzer", "analysis.DutchAnalyzer"] +class SpanContainingQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" + + +class SpanNotQuery(QueryBase): + dist: int + exclude: "i.SpanQuery" + include: "i.SpanQuery" + post: int + pre: int + + +class SpanOrQuery(QueryBase): + clauses: List["i.SpanQuery"] + + +class SpanFieldMaskingQuery(QueryBase): + field: Union[str, "InstrumentedField"] + query: "i.SpanQuery" + + +class SpanWithinQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" class GeoDistanceSort(TypedDict): @@ -391,6 +427,10 @@ class GeoDistanceSort(TypedDict): nested: "i.NestedSortValue" +class ScoreSort(TypedDict): + order: Literal["asc", "desc"] + + class ScriptSort(TypedDict): order: Literal["asc", "desc"] script: "i.Script" @@ -399,8 +439,27 @@ class ScriptSort(TypedDict): nested: "i.NestedSortValue" -class ScoreSort(TypedDict): - order: Literal["asc", "desc"] +class HighlightField(HighlightBase): + fragment_offset: int + matched_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + analyzer: Union[ + "analysis.CustomAnalyzer", + "analysis.FingerprintAnalyzer", + "analysis.KeywordAnalyzer", + "analysis.LanguageAnalyzer", + "analysis.NoriAnalyzer", + "analysis.PatternAnalyzer", + "analysis.SimpleAnalyzer", + "analysis.StandardAnalyzer", + "analysis.StopAnalyzer", + "analysis.WhitespaceAnalyzer", + "analysis.IcuAnalyzer", + "analysis.KuromojiAnalyzer", + "analysis.SnowballAnalyzer", + "analysis.DutchAnalyzer", + ] class IntervalsFilter(TypedDict): @@ -429,5 +488,3 @@ class NestedSortValue(TypedDict): max_children: int nested: "i.NestedSortValue" path: Union[str, "InstrumentedField"] - - diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 162b793a..30747bc7 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -39,12 +39,14 @@ # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import DslBase, NOT_SET +from .utils import NOT_SET, DslBase if TYPE_CHECKING: + from elasticsearch_dsl import interfaces as i + from elasticsearch_dsl import wrappers + from .document_base import InstrumentedField from .utils import NotSet - from elasticsearch_dsl import interfaces as i _T = TypeVar("_T") _M = TypeVar("_M", bound=Mapping[str, Any]) @@ -158,12 +160,13 @@ class Bool(Query): :arg should: The clause (query) should appear in the matching document. """ + name = "bool" _param_defs = { - "filter": {'type': 'query', 'multi': True}, - "must": {'type': 'query', 'multi': True}, - "must_not": {'type': 'query', 'multi': True}, - "should": {'type': 'query', 'multi': True}, + "filter": {"type": "query", "multi": True}, + "must": {"type": "query", "multi": True}, + "must_not": {"type": "query", "multi": True}, + "should": {"type": "query", "multi": True}, } def __init__( @@ -174,7 +177,7 @@ def __init__( must: Union[Query, List[Query], "NotSet"] = NOT_SET, must_not: Union[Query, List[Query], "NotSet"] = NOT_SET, should: Union[Query, List[Query], "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( filter=filter, @@ -182,7 +185,7 @@ def __init__( must=must, must_not=must_not, should=should, - **kwargs + **kwargs, ) def __add__(self, other: Query) -> "Bool": @@ -292,7 +295,7 @@ def __and__(self, other: Query) -> Query: return q __rand__ = __and__ - + class Boosting(Query): """ @@ -306,25 +309,21 @@ class Boosting(Query): decrease the relevance scores of documents matching the `negative` query. """ + name = "boosting" _param_defs = { - "negative": {'type': 'query'}, - "positive": {'type': 'query'}, + "negative": {"type": "query"}, + "positive": {"type": "query"}, } def __init__( - self, - *, - negative: Query, - positive: Query, - negative_boost: float, - **kwargs: Any + self, *, negative: Query, positive: Query, negative_boost: float, **kwargs: Any ): super().__init__( negative=negative, positive=positive, negative_boost=negative_boost, - **kwargs + **kwargs, ) @@ -335,19 +334,18 @@ class Common(Query): :arg field: Field to use :arg value: Field value """ + name = "common" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.CommonTermsQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class CombinedFields(Query): @@ -371,6 +369,7 @@ class CombinedFields(Query): the analyzer removes all tokens, such as when using a `stop` filter. """ + name = "combined_fields" def __init__( @@ -382,7 +381,7 @@ def __init__( operator: Union[Literal["or", "and"], "NotSet"] = NOT_SET, minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, zero_terms_query: Union[Literal["none", "all"], "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( query=query, @@ -391,7 +390,7 @@ def __init__( operator=operator, minimum_should_match=minimum_should_match, zero_terms_query=zero_terms_query, - **kwargs + **kwargs, ) @@ -405,21 +404,14 @@ class ConstantScore(Query): scores. To speed up performance, Elasticsearch automatically caches frequently used filter queries. """ + name = "constant_score" _param_defs = { - "filter": {'type': 'query'}, + "filter": {"type": "query"}, } - def __init__( - self, - *, - filter: Query, - **kwargs: Any - ): - super().__init__( - filter=filter, - **kwargs - ) + def __init__(self, *, filter: Query, **kwargs: Any): + super().__init__(filter=filter, **kwargs) class DisMax(Query): @@ -437,6 +429,7 @@ class DisMax(Query): increase the relevance scores of documents matching multiple query clauses. """ + name = "dis_max" def __init__( @@ -444,13 +437,9 @@ def __init__( *, queries: List[Query], tie_breaker: Union[float, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): - super().__init__( - queries=queries, - tie_breaker=tie_breaker, - **kwargs - ) + super().__init__(queries=queries, tie_breaker=tie_breaker, **kwargs) class DistanceFeature(Query): @@ -459,15 +448,11 @@ class DistanceFeature(Query): date or point. For example, you can use this query to give more weight to documents closer to a certain date or location. """ + name = "distance_feature" - def __init__( - self, - **kwargs: Any - ): - super().__init__( - **kwargs - ) + def __init__(self, **kwargs: Any): + super().__init__(**kwargs) class Exists(Query): @@ -476,18 +461,11 @@ class Exists(Query): :arg field: Name of the field you wish to search. """ + name = "exists" - def __init__( - self, - *, - field: Union[str, "InstrumentedField"], - **kwargs: Any - ): - super().__init__( - field=field, - **kwargs - ) + def __init__(self, *, field: Union[str, "InstrumentedField"], **kwargs: Any): + super().__init__(field=field, **kwargs) class FunctionScore(Query): @@ -507,21 +485,26 @@ class FunctionScore(Query): score is computed. :arg score_mode: Specifies how the computed scores are combined """ + name = "function_score" _param_defs = { - "query": {'type': 'query'}, + "query": {"type": "query"}, } def __init__( self, *, - boost_mode: Union[Literal["multiply", "replace", "sum", "avg", "max", "min"], "NotSet"] = NOT_SET, + boost_mode: Union[ + Literal["multiply", "replace", "sum", "avg", "max", "min"], "NotSet" + ] = NOT_SET, functions: Union[List["i.FunctionScoreContainer"], "NotSet"] = NOT_SET, max_boost: Union[float, "NotSet"] = NOT_SET, min_score: Union[float, "NotSet"] = NOT_SET, query: Union[Query, "NotSet"] = NOT_SET, - score_mode: Union[Literal["multiply", "sum", "avg", "first", "max", "min"], "NotSet"] = NOT_SET, - **kwargs: Any + score_mode: Union[ + Literal["multiply", "sum", "avg", "first", "max", "min"], "NotSet" + ] = NOT_SET, + **kwargs: Any, ): if functions is None: functions = [] @@ -535,7 +518,7 @@ def __init__( min_score=min_score, query=query, score_mode=score_mode, - **kwargs + **kwargs, ) @@ -547,19 +530,18 @@ class Fuzzy(Query): :arg field: Field to use :arg value: Field value """ + name = "fuzzy" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.FuzzyQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class GeoBoundingBox(Query): @@ -574,21 +556,24 @@ class GeoBoundingBox(Query): not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. """ + name = "geo_bounding_box" def __init__( self, *, type: Union[Literal["memory", "indexed"], "NotSet"] = NOT_SET, - validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + validation_method: Union[ + Literal["coerce", "ignore_malformed", "strict"], "NotSet" + ] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( type=type, validation_method=validation_method, ignore_unmapped=ignore_unmapped, - **kwargs + **kwargs, ) @@ -610,6 +595,7 @@ class GeoDistance(Query): not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. """ + name = "geo_distance" def __init__( @@ -617,16 +603,18 @@ def __init__( *, distance: str, distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, - validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + validation_method: Union[ + Literal["coerce", "ignore_malformed", "strict"], "NotSet" + ] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( distance=distance, distance_type=distance_type, validation_method=validation_method, ignore_unmapped=ignore_unmapped, - **kwargs + **kwargs, ) @@ -637,19 +625,22 @@ class GeoPolygon(Query): :arg validation_method: None :arg ignore_unmapped: None """ + name = "geo_polygon" def __init__( self, *, - validation_method: Union[Literal["coerce", "ignore_malformed", "strict"], "NotSet"] = NOT_SET, + validation_method: Union[ + Literal["coerce", "ignore_malformed", "strict"], "NotSet" + ] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( validation_method=validation_method, ignore_unmapped=ignore_unmapped, - **kwargs + **kwargs, ) @@ -662,18 +653,13 @@ class GeoShape(Query): not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. """ + name = "geo_shape" def __init__( - self, - *, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + self, *, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any ): - super().__init__( - ignore_unmapped=ignore_unmapped, - **kwargs - ) + super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) class HasChild(Query): @@ -699,9 +685,10 @@ class HasChild(Query): :arg score_mode: Indicates how scores for matching child documents affect the root parent document’s relevance score. """ + name = "has_child" _param_defs = { - "query": {'type': 'query'}, + "query": {"type": "query"}, } def __init__( @@ -713,8 +700,10 @@ def __init__( inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, max_children: Union[int, "NotSet"] = NOT_SET, min_children: Union[int, "NotSet"] = NOT_SET, - score_mode: Union[Literal["none", "avg", "sum", "max", "min"], "NotSet"] = NOT_SET, - **kwargs: Any + score_mode: Union[ + Literal["none", "avg", "sum", "max", "min"], "NotSet" + ] = NOT_SET, + **kwargs: Any, ): super().__init__( query=query, @@ -724,7 +713,7 @@ def __init__( max_children=max_children, min_children=min_children, score_mode=score_mode, - **kwargs + **kwargs, ) @@ -746,9 +735,10 @@ class HasParent(Query): :arg score: Indicates whether the relevance score of a matching parent document is aggregated into its child documents. """ + name = "has_parent" _param_defs = { - "query": {'type': 'query'}, + "query": {"type": "query"}, } def __init__( @@ -759,7 +749,7 @@ def __init__( ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, score: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( parent_type=parent_type, @@ -767,7 +757,7 @@ def __init__( ignore_unmapped=ignore_unmapped, inner_hits=inner_hits, score=score, - **kwargs + **kwargs, ) @@ -778,18 +768,13 @@ class Ids(Query): :arg values: An array of document IDs. """ + name = "ids" def __init__( - self, - *, - values: Union[str, List[str], "NotSet"] = NOT_SET, - **kwargs: Any + self, *, values: Union[str, List[str], "NotSet"] = NOT_SET, **kwargs: Any ): - super().__init__( - values=values, - **kwargs - ) + super().__init__(values=values, **kwargs) class Intervals(Query): @@ -799,19 +784,18 @@ class Intervals(Query): :arg field: Field to use :arg value: Field value """ + name = "intervals" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.IntervalsQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class Knn(Query): @@ -831,9 +815,10 @@ class Knn(Query): :arg similarity: The minimum similarity for a vector to be considered a match """ + name = "knn" _param_defs = { - "filter": {'type': 'query', 'multi': True}, + "filter": {"type": "query", "multi": True}, } def __init__( @@ -846,7 +831,7 @@ def __init__( k: Union[int, "NotSet"] = NOT_SET, filter: Union[Query, List[Query], "NotSet"] = NOT_SET, similarity: Union[float, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( field=field, @@ -856,7 +841,7 @@ def __init__( k=k, filter=filter, similarity=similarity, - **kwargs + **kwargs, ) @@ -868,34 +853,29 @@ class Match(Query): :arg field: Field to use :arg value: Field value """ + name = "match" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.MatchQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class MatchAll(Query): """ Matches all documents, giving them all a `_score` of 1.0. """ + name = "match_all" - def __init__( - self, - **kwargs: Any - ): - super().__init__( - **kwargs - ) + def __init__(self, **kwargs: Any): + super().__init__(**kwargs) def __add__(self, other: "Query") -> "Query": return other._clone() @@ -923,34 +903,29 @@ class MatchBoolPrefix(Query): :arg field: Field to use :arg value: Field value """ + name = "match_bool_prefix" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.MatchBoolPrefixQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class MatchNone(Query): """ Matches no documents. """ + name = "match_none" - def __init__( - self, - **kwargs: Any - ): - super().__init__( - **kwargs - ) + def __init__(self, **kwargs: Any): + super().__init__(**kwargs) def __add__(self, other: "Query") -> "MatchNone": return self @@ -973,19 +948,18 @@ class MatchPhrase(Query): :arg field: Field to use :arg value: Field value """ + name = "match_phrase" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.MatchPhraseQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class MatchPhrasePrefix(Query): @@ -997,19 +971,18 @@ class MatchPhrasePrefix(Query): :arg field: Field to use :arg value: Field value """ + name = "match_phrase_prefix" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.MatchPhrasePrefixQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class MoreLikeThis(Query): @@ -1055,6 +1028,7 @@ class MoreLikeThis(Query): :arg version: None :arg version_type: None """ + name = "more_like_this" def __init__( @@ -1075,10 +1049,14 @@ def __init__( min_word_length: Union[int, "NotSet"] = NOT_SET, routing: Union[str, "NotSet"] = NOT_SET, stop_words: Union[str, List[str], "NotSet"] = NOT_SET, - unlike: Union[Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], "NotSet"] = NOT_SET, + unlike: Union[ + Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], "NotSet" + ] = NOT_SET, version: Union[int, "NotSet"] = NOT_SET, - version_type: Union[Literal["internal", "external", "external_gte", "force"], "NotSet"] = NOT_SET, - **kwargs: Any + version_type: Union[ + Literal["internal", "external", "external_gte", "force"], "NotSet" + ] = NOT_SET, + **kwargs: Any, ): super().__init__( like=like, @@ -1099,7 +1077,7 @@ def __init__( unlike=unlike, version=version, version_type=version_type, - **kwargs + **kwargs, ) @@ -1144,6 +1122,7 @@ class MultiMatch(Query): the `analyzer` removes all tokens, such as when using a `stop` filter. """ + name = "multi_match" def __init__( @@ -1153,7 +1132,11 @@ def __init__( analyzer: Union[str, "NotSet"] = NOT_SET, auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - fields: Union[Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, fuzziness: Union[str, int, "NotSet"] = NOT_SET, fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, @@ -1164,9 +1147,19 @@ def __init__( prefix_length: Union[int, "NotSet"] = NOT_SET, slop: Union[int, "NotSet"] = NOT_SET, tie_breaker: Union[float, "NotSet"] = NOT_SET, - type: Union[Literal["best_fields", "most_fields", "cross_fields", "phrase", "phrase_prefix", "bool_prefix"], "NotSet"] = NOT_SET, + type: Union[ + Literal[ + "best_fields", + "most_fields", + "cross_fields", + "phrase", + "phrase_prefix", + "bool_prefix", + ], + "NotSet", + ] = NOT_SET, zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( query=query, @@ -1186,7 +1179,7 @@ def __init__( tie_breaker=tie_breaker, type=type, zero_terms_query=zero_terms_query, - **kwargs + **kwargs, ) @@ -1203,9 +1196,10 @@ class Nested(Query): :arg score_mode: How scores for matching child objects affect the root parent document’s relevance score. """ + name = "nested" _param_defs = { - "query": {'type': 'query'}, + "query": {"type": "query"}, } def __init__( @@ -1215,8 +1209,10 @@ def __init__( query: Query, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, - score_mode: Union[Literal["none", "avg", "sum", "max", "min"], "NotSet"] = NOT_SET, - **kwargs: Any + score_mode: Union[ + Literal["none", "avg", "sum", "max", "min"], "NotSet" + ] = NOT_SET, + **kwargs: Any, ): super().__init__( path=path, @@ -1224,7 +1220,7 @@ def __init__( ignore_unmapped=ignore_unmapped, inner_hits=inner_hits, score_mode=score_mode, - **kwargs + **kwargs, ) @@ -1237,6 +1233,7 @@ class ParentId(Query): and not return any documents instead of an error. :arg type: Name of the child relationship mapped for the `join` field. """ + name = "parent_id" def __init__( @@ -1245,14 +1242,9 @@ def __init__( id: Union[str, "NotSet"] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, type: Union[str, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): - super().__init__( - id=id, - ignore_unmapped=ignore_unmapped, - type=type, - **kwargs - ) + super().__init__(id=id, ignore_unmapped=ignore_unmapped, type=type, **kwargs) class Percolate(Query): @@ -1271,6 +1263,7 @@ class Percolate(Query): :arg routing: Routing used to fetch document to percolate. :arg version: The expected version of a stored document to percolate. """ + name = "percolate" def __init__( @@ -1285,7 +1278,7 @@ def __init__( preference: Union[str, "NotSet"] = NOT_SET, routing: Union[str, "NotSet"] = NOT_SET, version: Union[int, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( field=field, @@ -1297,7 +1290,7 @@ def __init__( preference=preference, routing=routing, version=version, - **kwargs + **kwargs, ) @@ -1313,9 +1306,10 @@ class Pinned(Query): :arg docs: Documents listed in the order they are to appear in results. Required if `ids` is not specified. """ + name = "pinned" _param_defs = { - "organic": {'type': 'query'}, + "organic": {"type": "query"}, } def __init__( @@ -1324,14 +1318,9 @@ def __init__( organic: Query, ids: Union[List[str], "NotSet"] = NOT_SET, docs: Union[List["i.PinnedDoc"], "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): - super().__init__( - organic=organic, - ids=ids, - docs=docs, - **kwargs - ) + super().__init__(organic=organic, ids=ids, docs=docs, **kwargs) class Prefix(Query): @@ -1341,19 +1330,18 @@ class Prefix(Query): :arg field: Field to use :arg value: Field value """ + name = "prefix" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.PrefixQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class QueryString(Query): @@ -1410,6 +1398,7 @@ class QueryString(Query): zone used to convert date values in the query string to UTC. :arg type: Determines how the query matches and scores documents. """ + name = "query_string" def __init__( @@ -1439,8 +1428,18 @@ def __init__( rewrite: Union[str, "NotSet"] = NOT_SET, tie_breaker: Union[float, "NotSet"] = NOT_SET, time_zone: Union[str, "NotSet"] = NOT_SET, - type: Union[Literal["best_fields", "most_fields", "cross_fields", "phrase", "phrase_prefix", "bool_prefix"], "NotSet"] = NOT_SET, - **kwargs: Any + type: Union[ + Literal[ + "best_fields", + "most_fields", + "cross_fields", + "phrase", + "phrase_prefix", + "bool_prefix", + ], + "NotSet", + ] = NOT_SET, + **kwargs: Any, ): super().__init__( query=query, @@ -1468,7 +1467,7 @@ def __init__( tie_breaker=tie_breaker, time_zone=time_zone, type=type, - **kwargs + **kwargs, ) @@ -1479,19 +1478,24 @@ class Range(Query): :arg field: Field to use :arg value: Field value """ + name = "range" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["wrappers.Range", "wrappers.Range", "wrappers.Range", "wrappers.Range", "NotSet"] = NOT_SET, - **kwargs: Any + value: Union[ + "wrappers.Range", + "wrappers.Range", + "wrappers.Range", + "wrappers.Range", + "NotSet", + ] = NOT_SET, + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class RankFeature(Query): @@ -1510,6 +1514,7 @@ class RankFeature(Query): :arg sigmoid: Sigmoid function used to boost relevance scores based on the value of the rank feature `field`. """ + name = "rank_feature" def __init__( @@ -1520,7 +1525,7 @@ def __init__( log: Union["i.RankFeatureFunctionLogarithm", "NotSet"] = NOT_SET, linear: Union["i.RankFeatureFunctionLinear", "NotSet"] = NOT_SET, sigmoid: Union["i.RankFeatureFunctionSigmoid", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( field=field, @@ -1528,7 +1533,7 @@ def __init__( log=log, linear=linear, sigmoid=sigmoid, - **kwargs + **kwargs, ) @@ -1539,19 +1544,18 @@ class Regexp(Query): :arg field: Field to use :arg value: Field value """ + name = "regexp" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.RegexpQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class Rule(Query): @@ -1562,9 +1566,10 @@ class Rule(Query): :arg match_criteria: None :arg organic: None """ + name = "rule" _param_defs = { - "organic": {'type': 'query'}, + "organic": {"type": "query"}, } def __init__( @@ -1573,13 +1578,13 @@ def __init__( ruleset_ids: List[str], match_criteria: Any, organic: Query, - **kwargs: Any + **kwargs: Any, ): super().__init__( ruleset_ids=ruleset_ids, match_criteria=match_criteria, organic=organic, - **kwargs + **kwargs, ) @@ -1591,18 +1596,11 @@ class Script(Query): :arg script: Contains a script to run as a query. This script must return a boolean value, `true` or `false`. """ + name = "script" - def __init__( - self, - *, - script: "i.Script", - **kwargs: Any - ): - super().__init__( - script=script, - **kwargs - ) + def __init__(self, *, script: "i.Script", **kwargs: Any): + super().__init__(script=script, **kwargs) class ScriptScore(Query): @@ -1616,9 +1614,10 @@ class ScriptScore(Query): :arg min_score: Documents with a score lower than this floating point number are excluded from the search results. """ + name = "script_score" _param_defs = { - "query": {'type': 'query'}, + "query": {"type": "query"}, } def __init__( @@ -1627,14 +1626,9 @@ def __init__( query: Query, script: "i.Script", min_score: Union[float, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): - super().__init__( - query=query, - script=script, - min_score=min_score, - **kwargs - ) + super().__init__(query=query, script=script, min_score=min_score, **kwargs) class Semantic(Query): @@ -1645,20 +1639,11 @@ class Semantic(Query): :arg field: The field to query, which must be a semantic_text field type """ + name = "semantic" - def __init__( - self, - *, - query: str, - field: str, - **kwargs: Any - ): - super().__init__( - query=query, - field=field, - **kwargs - ) + def __init__(self, *, query: str, field: str, **kwargs: Any): + super().__init__(query=query, field=field, **kwargs) class Shape(Query): @@ -1668,18 +1653,13 @@ class Shape(Query): :arg ignore_unmapped: When set to `true` the query ignores an unmapped field and will not match any documents. """ + name = "shape" def __init__( - self, - *, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any + self, *, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any ): - super().__init__( - ignore_unmapped=ignore_unmapped, - **kwargs - ) + super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) class SimpleQueryString(Query): @@ -1718,6 +1698,7 @@ class SimpleQueryString(Query): :arg quote_field_suffix: Suffix appended to quoted text in the query string. """ + name = "simple_query_string" def __init__( @@ -1729,14 +1710,14 @@ def __init__( auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - flags: Union["PipeSeparatedFlags", "NotSet"] = NOT_SET, + flags: Union["i.PipeSeparatedFlags", "NotSet"] = NOT_SET, fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, lenient: Union[bool, "NotSet"] = NOT_SET, minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, quote_field_suffix: Union[str, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( query=query, @@ -1752,7 +1733,7 @@ def __init__( lenient=lenient, minimum_should_match=minimum_should_match, quote_field_suffix=quote_field_suffix, - **kwargs + **kwargs, ) @@ -1765,20 +1746,11 @@ class SpanContaining(Query): :arg big: Can be any span query. Matching spans from `big` that contain matches from `little` are returned. """ + name = "span_containing" - def __init__( - self, - *, - little: "i.SpanQuery", - big: "i.SpanQuery", - **kwargs: Any - ): - super().__init__( - little=little, - big=big, - **kwargs - ) + def __init__(self, *, little: "i.SpanQuery", big: "i.SpanQuery", **kwargs: Any): + super().__init__(little=little, big=big, **kwargs) class SpanFieldMasking(Query): @@ -1789,6 +1761,7 @@ class SpanFieldMasking(Query): :arg query: None :arg field: None """ + name = "span_field_masking" def __init__( @@ -1796,13 +1769,9 @@ def __init__( *, query: "i.SpanQuery", field: Union[str, "InstrumentedField"], - **kwargs: Any + **kwargs: Any, ): - super().__init__( - query=query, - field=field, - **kwargs - ) + super().__init__(query=query, field=field, **kwargs) class SpanFirst(Query): @@ -1812,20 +1781,11 @@ class SpanFirst(Query): :arg match: Can be any other span type query. :arg end: Controls the maximum end position permitted in a match. """ + name = "span_first" - def __init__( - self, - *, - match: "i.SpanQuery", - end: int, - **kwargs: Any - ): - super().__init__( - match=match, - end=end, - **kwargs - ) + def __init__(self, *, match: "i.SpanQuery", end: int, **kwargs: Any): + super().__init__(match=match, end=end, **kwargs) class SpanMulti(Query): @@ -1837,21 +1797,14 @@ class SpanMulti(Query): :arg match: Should be a multi term query (one of `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). """ + name = "span_multi" _param_defs = { - "match": {'type': 'query'}, + "match": {"type": "query"}, } - def __init__( - self, - *, - match: Query, - **kwargs: Any - ): - super().__init__( - match=match, - **kwargs - ) + def __init__(self, *, match: Query, **kwargs: Any): + super().__init__(match=match, **kwargs) class SpanNear(Query): @@ -1865,6 +1818,7 @@ class SpanNear(Query): :arg slop: Controls the maximum number of intervening unmatched positions permitted. """ + name = "span_near" def __init__( @@ -1873,14 +1827,9 @@ def __init__( clauses: List["i.SpanQuery"], in_order: Union[bool, "NotSet"] = NOT_SET, slop: Union[int, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): - super().__init__( - clauses=clauses, - in_order=in_order, - slop=slop, - **kwargs - ) + super().__init__(clauses=clauses, in_order=in_order, slop=slop, **kwargs) class SpanNot(Query): @@ -1900,6 +1849,7 @@ class SpanNot(Query): :arg pre: The number of tokens before the include span that can’t have overlap with the exclude span. """ + name = "span_not" def __init__( @@ -1910,15 +1860,10 @@ def __init__( dist: Union[int, "NotSet"] = NOT_SET, post: Union[int, "NotSet"] = NOT_SET, pre: Union[int, "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( - exclude=exclude, - include=include, - dist=dist, - post=post, - pre=pre, - **kwargs + exclude=exclude, include=include, dist=dist, post=post, pre=pre, **kwargs ) @@ -1928,18 +1873,11 @@ class SpanOr(Query): :arg clauses: Array of one or more other span type queries. """ + name = "span_or" - def __init__( - self, - *, - clauses: List["i.SpanQuery"], - **kwargs: Any - ): - super().__init__( - clauses=clauses, - **kwargs - ) + def __init__(self, *, clauses: List["i.SpanQuery"], **kwargs: Any): + super().__init__(clauses=clauses, **kwargs) class SpanTerm(Query): @@ -1949,19 +1887,18 @@ class SpanTerm(Query): :arg field: Field to use :arg value: Field value """ + name = "span_term" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.SpanTermQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class SpanWithin(Query): @@ -1973,20 +1910,11 @@ class SpanWithin(Query): :arg big: Can be any span query. Matching spans from `little` that are enclosed within `big` are returned. """ + name = "span_within" - def __init__( - self, - *, - little: "i.SpanQuery", - big: "i.SpanQuery", - **kwargs: Any - ): - super().__init__( - little=little, - big=big, - **kwargs - ) + def __init__(self, *, little: "i.SpanQuery", big: "i.SpanQuery", **kwargs: Any): + super().__init__(little=little, big=big, **kwargs) class SparseVector(Query): @@ -2019,6 +1947,7 @@ class SparseVector(Query): true. If prune is set to true but pruning_config is not specified, default values will be used. """ + name = "sparse_vector" def __init__( @@ -2030,7 +1959,7 @@ def __init__( query: Union[str, "NotSet"] = NOT_SET, prune: Union[bool, "NotSet"] = NOT_SET, pruning_config: Union["i.TokenPruningConfig", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): super().__init__( field=field, @@ -2039,7 +1968,7 @@ def __init__( query=query, prune=prune, pruning_config=pruning_config, - **kwargs + **kwargs, ) @@ -2052,19 +1981,18 @@ class Term(Query): :arg field: Field to use :arg value: Field value """ + name = "term" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.TermQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class Terms(Query): @@ -2073,15 +2001,11 @@ class Terms(Query): field. To return a document, one or more terms must exactly match a field value, including whitespace and capitalization. """ + name = "terms" - def __init__( - self, - **kwargs: Any - ): - super().__init__( - **kwargs - ) + def __init__(self, **kwargs: Any): + super().__init__(**kwargs) def _setattr(self, name: str, value: Any) -> None: # here we convert any iterables that are not strings to lists @@ -2100,19 +2024,18 @@ class TermsSet(Query): :arg field: Field to use :arg value: Field value """ + name = "terms_set" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.TermsSetQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class TextExpansion(Query): @@ -2124,19 +2047,18 @@ class TextExpansion(Query): :arg field: Field to use :arg value: Field value """ + name = "text_expansion" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.TextExpansionQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class WeightedTokens(Query): @@ -2147,19 +2069,18 @@ class WeightedTokens(Query): :arg field: Field to use :arg value: Field value """ + name = "weighted_tokens" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.WeightedTokensQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class Wildcard(Query): @@ -2169,19 +2090,18 @@ class Wildcard(Query): :arg field: Field to use :arg value: Field value """ + name = "wildcard" def __init__( self, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, value: Union["i.WildcardQuery", "NotSet"] = NOT_SET, - **kwargs: Any + **kwargs: Any, ): if field != NOT_SET: kwargs[str(field)] = value - super().__init__( - **kwargs - ) + super().__init__(**kwargs) class Wrapper(Query): @@ -2191,18 +2111,11 @@ class Wrapper(Query): :arg query: A base64 encoded query. The binary data format can be any of JSON, YAML, CBOR or SMILE encodings """ + name = "wrapper" - def __init__( - self, - *, - query: str, - **kwargs: Any - ): - super().__init__( - query=query, - **kwargs - ) + def __init__(self, *, query: str, **kwargs: Any): + super().__init__(query=query, **kwargs) class Type(Query): @@ -2211,17 +2124,8 @@ class Type(Query): :arg value: None """ - name = "type" - - def __init__( - self, - *, - value: str, - **kwargs: Any - ): - super().__init__( - value=value, - **kwargs - ) + name = "type" + def __init__(self, *, value: str, **kwargs: Any): + super().__init__(value=value, **kwargs) diff --git a/elasticsearch_dsl/utils.py b/elasticsearch_dsl/utils.py index 4c9d2c0f..66594c9d 100644 --- a/elasticsearch_dsl/utils.py +++ b/elasticsearch_dsl/utils.py @@ -169,6 +169,7 @@ class AttrDict(Generic[_ValT]): """ _d_: Dict[str, _ValT] + RESERVED: Dict[str, str] = {"from_": "from"} def __init__(self, d: Dict[str, _ValT]): # assign the inner dict manually to prevent __setattr__ from firing @@ -217,20 +218,20 @@ def __getattr__(self, attr_name: str) -> Any: def __delattr__(self, attr_name: str) -> None: try: - del self._d_[attr_name] + del self._d_[self.RESERVED.get(attr_name, attr_name)] except KeyError: raise AttributeError( f"{self.__class__.__name__!r} object has no attribute {attr_name!r}" ) def __getitem__(self, key: str) -> Any: - return _wrap(self._d_[key]) + return _wrap(self._d_[self.RESERVED.get(key, key)]) def __setitem__(self, key: str, value: _ValT) -> None: - self._d_[key] = value + self._d_[self.RESERVED.get(key, key)] = value def __delitem__(self, key: str) -> None: - del self._d_[key] + del self._d_[self.RESERVED.get(key, key)] def __setattr__(self, name: str, value: _ValT) -> None: # the __orig__class__ attribute has to be treated as an exception, as @@ -238,7 +239,7 @@ def __setattr__(self, name: str, value: _ValT) -> None: if ( name in self._d_ or not hasattr(self.__class__, name) ) and name != "__orig_class__": - self._d_[name] = value + self._d_[self.RESERVED.get(name, name)] = value else: # there is an attribute on the class (could be property, ..) - don't add it as field super().__setattr__(name, value) diff --git a/utils/generator.py b/utils/generator.py index b8e2d5f3..779a0f61 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -1,10 +1,29 @@ -from elasticsearch_dsl import VERSION +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + import json import textwrap -from urllib.request import urlopen from urllib.error import HTTPError +from urllib.request import urlopen + from jinja2 import Environment, PackageLoader, select_autoescape +from elasticsearch_dsl import VERSION + jinja_env = Environment( loader=PackageLoader("utils"), autoescape=select_autoescape(), @@ -14,6 +33,8 @@ query_py = jinja_env.get_template("query.py.tpl") interfaces_py = jinja_env.get_template("interfaces.py.tpl") +RESERVED = {"from": "from_"} + def wrapped_doc(text, width=70, initial_indent="", subsequent_indent=""): """Formats a docstring as a list of lines of up to the request width.""" @@ -122,7 +143,7 @@ def get_python_type(self, schema_type): == {"name": "T", "namespace": "_spec_utils.PipeSeparatedFlags"} ): self.interfaces.add("PipeSeparatedFlags") - return '"PipeSeparatedFlags"', None + return '"i.PipeSeparatedFlags"', None else: types = [self.get_python_type(t) for t in schema_type["items"]] return "Union[" + ", ".join([type_ for type_, _ in types]) + "]", None @@ -180,7 +201,7 @@ def generate_query_classes(schema, filename): if arg["required"] is False: k["kwargs"].append( { - "name": arg["name"], + "name": RESERVED.get(arg["name"], arg["name"]), "type": type_, "doc": doc, "required": False, @@ -194,7 +215,7 @@ def generate_query_classes(schema, filename): k["kwargs"].insert( i, { - "name": arg["name"], + "name": RESERVED.get(arg["name"], arg["name"]), "type": type_, "doc": doc, "required": True, @@ -274,7 +295,9 @@ def generate_interfaces(schema, interfaces, filename): schema.reset_interfaces() for p in type_["properties"]: type_, param = schema.get_python_type(p["type"]) - k["properties"].append({"name": p["name"], "type": type_}) + k["properties"].append( + {"name": RESERVED.get(p["name"], p["name"]), "type": type_} + ) for new_interface in schema.interfaces: if new_interface not in interfaces: interfaces.append(new_interface) diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index 6fa29cc9..c68a594d 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -1,9 +1,6 @@ -from typing import TYPE_CHECKING, Any, List, Literal, Mapping, TypedDict, Union +from typing import Any, List, Literal, Mapping, TypedDict, Union from elasticsearch_dsl.search_base import InstrumentedField -from elasticsearch_dsl.utils import AttrDict - -if TYPE_CHECKING: - from elasticsearch_dsl import analysis, function, wrappers +from elasticsearch_dsl import analysis, function, interfaces as i, Query PipeSeparatedFlags = str diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 0fa9aff3..5453db08 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -44,7 +44,7 @@ from .utils import DslBase, NOT_SET if TYPE_CHECKING: from .document_base import InstrumentedField from .utils import NotSet - from elasticsearch_dsl import interfaces as i + from elasticsearch_dsl import interfaces as i, wrappers _T = TypeVar("_T") _M = TypeVar("_M", bound=Mapping[str, Any]) From 2d581cf8068f64a67898d80025675ef2bc248e5d Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 28 Aug 2024 19:53:19 +0100 Subject: [PATCH 03/27] replace long deprecated 'filtered' query from tests --- tests/_async/test_search.py | 17 ++++++++++------- tests/_async/test_update_by_query.py | 17 ++++++++++------- tests/_sync/test_search.py | 17 ++++++++++------- tests/_sync/test_update_by_query.py | 17 ++++++++++------- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/tests/_async/test_search.py b/tests/_async/test_search.py index 28e07a50..008246ab 100644 --- a/tests/_async/test_search.py +++ b/tests/_async/test_search.py @@ -479,7 +479,7 @@ def test_complex_example() -> None: def test_reverse() -> None: d = { "query": { - "filtered": { + "bool": { "filter": { "bool": { "should": [ @@ -488,13 +488,15 @@ def test_reverse() -> None: ] } }, - "query": { - "bool": { - "must": [{"match": {"title": "python"}}], - "must_not": [{"match": {"title": "ruby"}}], - "minimum_should_match": 2, + "must": [ + { + "bool": { + "must": [{"match": {"title": "python"}}], + "must_not": [{"match": {"title": "ruby"}}], + "minimum_should_match": 2, + } } - }, + ], } }, "post_filter": {"bool": {"must": [{"terms": {"tags": ["prague", "czech"]}}]}}, @@ -523,6 +525,7 @@ def test_reverse() -> None: # make sure we haven't modified anything in place assert d == d2 assert {"size": 5} == s._extra + d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == s.to_dict() diff --git a/tests/_async/test_update_by_query.py b/tests/_async/test_update_by_query.py index 4bde5ee0..beae2249 100644 --- a/tests/_async/test_update_by_query.py +++ b/tests/_async/test_update_by_query.py @@ -101,7 +101,7 @@ def test_exclude() -> None: def test_reverse() -> None: d = { "query": { - "filtered": { + "bool": { "filter": { "bool": { "should": [ @@ -110,13 +110,15 @@ def test_reverse() -> None: ] } }, - "query": { - "bool": { - "must": [{"match": {"title": "python"}}], - "must_not": [{"match": {"title": "ruby"}}], - "minimum_should_match": 2, + "must": [ + { + "bool": { + "must": [{"match": {"title": "python"}}], + "must_not": [{"match": {"title": "ruby"}}], + "minimum_should_match": 2, + } } - }, + ], } }, "script": { @@ -131,6 +133,7 @@ def test_reverse() -> None: ubq = AsyncUpdateByQuery.from_dict(d) assert d == d2 + d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == ubq.to_dict() diff --git a/tests/_sync/test_search.py b/tests/_sync/test_search.py index d777508f..272b8a90 100644 --- a/tests/_sync/test_search.py +++ b/tests/_sync/test_search.py @@ -479,7 +479,7 @@ def test_complex_example() -> None: def test_reverse() -> None: d = { "query": { - "filtered": { + "bool": { "filter": { "bool": { "should": [ @@ -488,13 +488,15 @@ def test_reverse() -> None: ] } }, - "query": { - "bool": { - "must": [{"match": {"title": "python"}}], - "must_not": [{"match": {"title": "ruby"}}], - "minimum_should_match": 2, + "must": [ + { + "bool": { + "must": [{"match": {"title": "python"}}], + "must_not": [{"match": {"title": "ruby"}}], + "minimum_should_match": 2, + } } - }, + ], } }, "post_filter": {"bool": {"must": [{"terms": {"tags": ["prague", "czech"]}}]}}, @@ -523,6 +525,7 @@ def test_reverse() -> None: # make sure we haven't modified anything in place assert d == d2 assert {"size": 5} == s._extra + d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == s.to_dict() diff --git a/tests/_sync/test_update_by_query.py b/tests/_sync/test_update_by_query.py index 68d89c50..bc4db61e 100644 --- a/tests/_sync/test_update_by_query.py +++ b/tests/_sync/test_update_by_query.py @@ -101,7 +101,7 @@ def test_exclude() -> None: def test_reverse() -> None: d = { "query": { - "filtered": { + "bool": { "filter": { "bool": { "should": [ @@ -110,13 +110,15 @@ def test_reverse() -> None: ] } }, - "query": { - "bool": { - "must": [{"match": {"title": "python"}}], - "must_not": [{"match": {"title": "ruby"}}], - "minimum_should_match": 2, + "must": [ + { + "bool": { + "must": [{"match": {"title": "python"}}], + "must_not": [{"match": {"title": "ruby"}}], + "minimum_should_match": 2, + } } - }, + ], } }, "script": { @@ -131,6 +133,7 @@ def test_reverse() -> None: ubq = UpdateByQuery.from_dict(d) assert d == d2 + d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == ubq.to_dict() From 3992d9fdb0359537c8647db58f2a19067ce12f29 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 28 Aug 2024 20:02:51 +0100 Subject: [PATCH 04/27] minor code generation updates --- elasticsearch_dsl/interfaces.py | 508 ++++++++++++++++---------------- elasticsearch_dsl/query.py | 192 ++++++------ utils/generator.py | 15 +- utils/templates/dsl_classes.tpl | 6 +- 4 files changed, 362 insertions(+), 359 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index c630c1a1..67a6eafe 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -29,11 +29,6 @@ class QueryBase(TypedDict): _name: str -class TermQuery(QueryBase): - value: Union[int, float, str, bool, None, Any] - case_insensitive: bool - - class MatchPhrasePrefixQuery(QueryBase): analyzer: str max_expansions: int @@ -42,6 +37,41 @@ class MatchPhrasePrefixQuery(QueryBase): zero_terms_query: Literal["all", "none"] +class MatchPhraseQuery(QueryBase): + analyzer: str + query: str + slop: int + zero_terms_query: Literal["all", "none"] + + +class WeightedTokensQuery(QueryBase): + tokens: Mapping[str, float] + pruning_config: "i.TokenPruningConfig" + + +class IntervalsQuery(QueryBase): + all_of: "i.IntervalsAllOf" + any_of: "i.IntervalsAnyOf" + fuzzy: "i.IntervalsFuzzy" + match: "i.IntervalsMatch" + prefix: "i.IntervalsPrefix" + wildcard: "i.IntervalsWildcard" + + +class PinnedDoc(TypedDict): + _id: str + _index: str + + +class FuzzyQuery(QueryBase): + max_expansions: int + prefix_length: int + rewrite: str + transpositions: bool + fuzziness: Union[str, int] + value: Union[str, float, bool] + + class RankFeatureFunction(TypedDict): pass @@ -50,6 +80,69 @@ class RankFeatureFunctionLogarithm(RankFeatureFunction): scaling_factor: float +class TextExpansionQuery(QueryBase): + model_id: str + model_text: str + pruning_config: "i.TokenPruningConfig" + + +class PrefixQuery(QueryBase): + rewrite: str + value: str + case_insensitive: bool + + +class TokenPruningConfig(TypedDict): + tokens_freq_ratio_threshold: int + tokens_weight_threshold: float + only_score_pruned_tokens: bool + + +class TermQuery(QueryBase): + value: Union[int, float, str, bool, None, Any] + case_insensitive: bool + + +class SpanQuery(TypedDict): + span_containing: "i.SpanContainingQuery" + span_field_masking: "i.SpanFieldMaskingQuery" + span_first: "i.SpanFirstQuery" + span_gap: Mapping[Union[str, "InstrumentedField"], int] + span_multi: "i.SpanMultiTermQuery" + span_near: "i.SpanNearQuery" + span_not: "i.SpanNotQuery" + span_or: "i.SpanOrQuery" + span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] + span_within: "i.SpanWithinQuery" + + +class RankFeatureFunctionSaturation(RankFeatureFunction): + pivot: float + + +class WildcardQuery(QueryBase): + case_insensitive: bool + rewrite: str + value: str + wildcard: str + + +class SpanTermQuery(QueryBase): + value: str + + +class QueryVectorBuilder(TypedDict): + text_embedding: "i.TextEmbedding" + + +class Script(TypedDict): + source: str + id: str + params: Mapping[str, Any] + lang: Literal["painless", "expression", "mustache", "java"] + options: Mapping[str, str] + + class CommonTermsQuery(QueryBase): analyzer: str cutoff_frequency: float @@ -59,10 +152,42 @@ class CommonTermsQuery(QueryBase): query: str -class PrefixQuery(QueryBase): - rewrite: str - value: str - case_insensitive: bool +class InnerHits(TypedDict): + name: str + size: int + from_: int + collapse: "i.FieldCollapse" + docvalue_fields: List["i.FieldAndFormat"] + explain: bool + highlight: "i.Highlight" + ignore_unmapped: bool + script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] + seq_no_primary_term: bool + fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + ] + _source: Union[bool, "i.SourceFilter"] + stored_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] + ] + track_scores: bool + version: bool + + +class MatchBoolPrefixQuery(QueryBase): + analyzer: str + fuzziness: Union[str, int] + fuzzy_rewrite: str + fuzzy_transpositions: bool + max_expansions: int + minimum_should_match: Union[int, str] + operator: Literal["and", "or"] + prefix_length: int + query: str class FunctionScoreContainer(TypedDict): @@ -91,6 +216,16 @@ class FunctionScoreContainer(TypedDict): weight: float +class RankFeatureFunctionLinear(RankFeatureFunction): + pass + + +class TermsSetQuery(QueryBase): + minimum_should_match_field: Union[str, "InstrumentedField"] + minimum_should_match_script: "i.Script" + terms: List[str] + + class LikeDocument(TypedDict): doc: Any fields: List[Union[str, "InstrumentedField"]] @@ -102,33 +237,12 @@ class LikeDocument(TypedDict): version_type: Literal["internal", "external", "external_gte", "force"] -class TokenPruningConfig(TypedDict): - tokens_freq_ratio_threshold: int - tokens_weight_threshold: float - only_score_pruned_tokens: bool - - -class WildcardQuery(QueryBase): +class RegexpQuery(QueryBase): case_insensitive: bool + flags: str + max_determinized_states: int rewrite: str value: str - wildcard: str - - -class WeightedTokensQuery(QueryBase): - tokens: Mapping[str, float] - pruning_config: "i.TokenPruningConfig" - - -class RankFeatureFunctionSaturation(RankFeatureFunction): - pivot: float - - -class MatchPhraseQuery(QueryBase): - analyzer: str - query: str - slop: int - zero_terms_query: Literal["all", "none"] class MatchQuery(QueryBase): @@ -147,123 +261,93 @@ class MatchQuery(QueryBase): zero_terms_query: Literal["all", "none"] -class QueryVectorBuilder(TypedDict): - text_embedding: "i.TextEmbedding" - - -class PinnedDoc(TypedDict): - _id: str - _index: str +class RankFeatureFunctionSigmoid(RankFeatureFunction): + pivot: float + exponent: float -class Script(TypedDict): - source: str - id: str - params: Mapping[str, Any] - lang: Literal["painless", "expression", "mustache", "java"] - options: Mapping[str, str] +class IntervalsAllOf(TypedDict): + intervals: List["i.IntervalsContainer"] + max_gaps: int + ordered: bool + filter: "i.IntervalsFilter" -class RankFeatureFunctionLinear(RankFeatureFunction): - pass +class IntervalsAnyOf(TypedDict): + intervals: List["i.IntervalsContainer"] + filter: "i.IntervalsFilter" -class MatchBoolPrefixQuery(QueryBase): +class IntervalsFuzzy(TypedDict): analyzer: str fuzziness: Union[str, int] - fuzzy_rewrite: str - fuzzy_transpositions: bool - max_expansions: int - minimum_should_match: Union[int, str] - operator: Literal["and", "or"] prefix_length: int + term: str + transpositions: bool + use_field: Union[str, "InstrumentedField"] + + +class IntervalsPrefix(TypedDict): + analyzer: str + prefix: str + use_field: Union[str, "InstrumentedField"] + + +class IntervalsMatch(TypedDict): + analyzer: str + max_gaps: int + ordered: bool query: str + use_field: Union[str, "InstrumentedField"] + filter: "i.IntervalsFilter" -class InnerHits(TypedDict): - name: str - size: int - from_: int - collapse: "i.FieldCollapse" - docvalue_fields: List["i.FieldAndFormat"] - explain: bool - highlight: "i.Highlight" - ignore_unmapped: bool - script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] - seq_no_primary_term: bool - fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], - ] - _source: Union[bool, "i.SourceFilter"] - stored_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - track_scores: bool - version: bool +class IntervalsWildcard(TypedDict): + analyzer: str + pattern: str + use_field: Union[str, "InstrumentedField"] -class RegexpQuery(QueryBase): - case_insensitive: bool - flags: str - max_determinized_states: int - rewrite: str - value: str +class SpanFieldMaskingQuery(QueryBase): + field: Union[str, "InstrumentedField"] + query: "i.SpanQuery" -class RankFeatureFunctionSigmoid(RankFeatureFunction): - pivot: float - exponent: float +class SpanNearQuery(QueryBase): + clauses: List["i.SpanQuery"] + in_order: bool + slop: int -class FuzzyQuery(QueryBase): - max_expansions: int - prefix_length: int - rewrite: str - transpositions: bool - fuzziness: Union[str, int] - value: Union[str, float, bool] +class SpanContainingQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" -class IntervalsQuery(QueryBase): - all_of: "i.IntervalsAllOf" - any_of: "i.IntervalsAnyOf" - fuzzy: "i.IntervalsFuzzy" - match: "i.IntervalsMatch" - prefix: "i.IntervalsPrefix" - wildcard: "i.IntervalsWildcard" +class SpanOrQuery(QueryBase): + clauses: List["i.SpanQuery"] -class SpanTermQuery(QueryBase): - value: str +class SpanNotQuery(QueryBase): + dist: int + exclude: "i.SpanQuery" + include: "i.SpanQuery" + post: int + pre: int -class TermsSetQuery(QueryBase): - minimum_should_match_field: Union[str, "InstrumentedField"] - minimum_should_match_script: "i.Script" - terms: List[str] +class SpanFirstQuery(QueryBase): + end: int + match: "i.SpanQuery" -class TextExpansionQuery(QueryBase): - model_id: str - model_text: str - pruning_config: "i.TokenPruningConfig" +class SpanMultiTermQuery(QueryBase): + match: Query -class SpanQuery(TypedDict): - span_containing: "i.SpanContainingQuery" - span_field_masking: "i.SpanFieldMaskingQuery" - span_first: "i.SpanFirstQuery" - span_gap: Mapping[Union[str, "InstrumentedField"], int] - span_multi: "i.SpanMultiTermQuery" - span_near: "i.SpanNearQuery" - span_not: "i.SpanNotQuery" - span_or: "i.SpanOrQuery" - span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] - span_within: "i.SpanWithinQuery" +class SpanWithinQuery(QueryBase): + big: "i.SpanQuery" + little: "i.SpanQuery" class TextEmbedding(TypedDict): @@ -271,18 +355,10 @@ class TextEmbedding(TypedDict): model_text: str -class SortOptions(TypedDict): - _score: "i.ScoreSort" - _doc: "i.ScoreSort" - _geo_distance: "i.GeoDistanceSort" - _script: "i.ScriptSort" - - -class FieldCollapse(TypedDict): +class FieldAndFormat(TypedDict): field: Union[str, "InstrumentedField"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"]] - max_concurrent_group_searches: int - collapse: "i.FieldCollapse" + format: str + include_unmapped: bool class HighlightBase(TypedDict): @@ -314,17 +390,6 @@ class Highlight(HighlightBase): fields: Mapping[Union[str, "InstrumentedField"], "i.HighlightField"] -class ScriptField(TypedDict): - script: "i.Script" - ignore_failure: bool - - -class FieldAndFormat(TypedDict): - field: Union[str, "InstrumentedField"] - format: str - include_unmapped: bool - - class SourceFilter(TypedDict): excludes: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] @@ -334,109 +399,44 @@ class SourceFilter(TypedDict): ] -class IntervalsAnyOf(TypedDict): - intervals: List["i.IntervalsContainer"] - filter: "i.IntervalsFilter" - - -class IntervalsMatch(TypedDict): - analyzer: str - max_gaps: int - ordered: bool - query: str - use_field: Union[str, "InstrumentedField"] - filter: "i.IntervalsFilter" - - -class IntervalsWildcard(TypedDict): - analyzer: str - pattern: str - use_field: Union[str, "InstrumentedField"] - - -class IntervalsPrefix(TypedDict): - analyzer: str - prefix: str - use_field: Union[str, "InstrumentedField"] - - -class IntervalsAllOf(TypedDict): - intervals: List["i.IntervalsContainer"] - max_gaps: int - ordered: bool - filter: "i.IntervalsFilter" - - -class IntervalsFuzzy(TypedDict): - analyzer: str - fuzziness: Union[str, int] - prefix_length: int - term: str - transpositions: bool - use_field: Union[str, "InstrumentedField"] - - -class SpanFirstQuery(QueryBase): - end: int - match: "i.SpanQuery" - - -class SpanMultiTermQuery(QueryBase): - match: Query - - -class SpanNearQuery(QueryBase): - clauses: List["i.SpanQuery"] - in_order: bool - slop: int - - -class SpanContainingQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" - - -class SpanNotQuery(QueryBase): - dist: int - exclude: "i.SpanQuery" - include: "i.SpanQuery" - post: int - pre: int - - -class SpanOrQuery(QueryBase): - clauses: List["i.SpanQuery"] +class SortOptions(TypedDict): + _score: "i.ScoreSort" + _doc: "i.ScoreSort" + _geo_distance: "i.GeoDistanceSort" + _script: "i.ScriptSort" -class SpanFieldMaskingQuery(QueryBase): +class FieldCollapse(TypedDict): field: Union[str, "InstrumentedField"] - query: "i.SpanQuery" - - -class SpanWithinQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" + inner_hits: Union["i.InnerHits", List["i.InnerHits"]] + max_concurrent_group_searches: int + collapse: "i.FieldCollapse" -class GeoDistanceSort(TypedDict): - mode: Literal["min", "max", "sum", "avg", "median"] - distance_type: Literal["arc", "plane"] - ignore_unmapped: bool - order: Literal["asc", "desc"] - unit: Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"] - nested: "i.NestedSortValue" +class ScriptField(TypedDict): + script: "i.Script" + ignore_failure: bool -class ScoreSort(TypedDict): - order: Literal["asc", "desc"] +class IntervalsContainer(TypedDict): + all_of: "i.IntervalsAllOf" + any_of: "i.IntervalsAnyOf" + fuzzy: "i.IntervalsFuzzy" + match: "i.IntervalsMatch" + prefix: "i.IntervalsPrefix" + wildcard: "i.IntervalsWildcard" -class ScriptSort(TypedDict): - order: Literal["asc", "desc"] +class IntervalsFilter(TypedDict): + after: "i.IntervalsContainer" + before: "i.IntervalsContainer" + contained_by: "i.IntervalsContainer" + containing: "i.IntervalsContainer" + not_contained_by: "i.IntervalsContainer" + not_containing: "i.IntervalsContainer" + not_overlapping: "i.IntervalsContainer" + overlapping: "i.IntervalsContainer" script: "i.Script" - type: Literal["string", "number", "version"] - mode: Literal["min", "max", "sum", "avg", "median"] - nested: "i.NestedSortValue" class HighlightField(HighlightBase): @@ -462,25 +462,25 @@ class HighlightField(HighlightBase): ] -class IntervalsFilter(TypedDict): - after: "i.IntervalsContainer" - before: "i.IntervalsContainer" - contained_by: "i.IntervalsContainer" - containing: "i.IntervalsContainer" - not_contained_by: "i.IntervalsContainer" - not_containing: "i.IntervalsContainer" - not_overlapping: "i.IntervalsContainer" - overlapping: "i.IntervalsContainer" - script: "i.Script" +class GeoDistanceSort(TypedDict): + mode: Literal["min", "max", "sum", "avg", "median"] + distance_type: Literal["arc", "plane"] + ignore_unmapped: bool + order: Literal["asc", "desc"] + unit: Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"] + nested: "i.NestedSortValue" -class IntervalsContainer(TypedDict): - all_of: "i.IntervalsAllOf" - any_of: "i.IntervalsAnyOf" - fuzzy: "i.IntervalsFuzzy" - match: "i.IntervalsMatch" - prefix: "i.IntervalsPrefix" - wildcard: "i.IntervalsWildcard" +class ScoreSort(TypedDict): + order: Literal["asc", "desc"] + + +class ScriptSort(TypedDict): + order: Literal["asc", "desc"] + script: "i.Script" + type: Literal["string", "number", "version"] + mode: Literal["min", "max", "sum", "avg", "median"] + nested: "i.NestedSortValue" class NestedSortValue(TypedDict): diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 30747bc7..4fa6f105 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -331,20 +331,20 @@ class Common(Query): """ No documentation available. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "common" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.CommonTermsQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.CommonTermsQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -527,20 +527,20 @@ class Fuzzy(Query): Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "fuzzy" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.FuzzyQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.FuzzyQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -781,20 +781,20 @@ class Intervals(Query): """ Returns documents based on the order and proximity of matching terms. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "intervals" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.IntervalsQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.IntervalsQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -850,20 +850,20 @@ class Match(Query): Returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "match" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.MatchQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.MatchQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -900,20 +900,20 @@ class MatchBoolPrefix(Query): term except the last is used in a `term` query. The last term is used in a prefix query. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "match_bool_prefix" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.MatchBoolPrefixQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.MatchBoolPrefixQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -945,20 +945,20 @@ class MatchPhrase(Query): """ Analyzes the text and creates a phrase query out of the analyzed text. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "match_phrase" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.MatchPhraseQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.MatchPhraseQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -968,20 +968,20 @@ class MatchPhrasePrefix(Query): same order as provided. The last term of the provided text is treated as a prefix, matching any words that begin with that term. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "match_phrase_prefix" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.MatchPhrasePrefixQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.MatchPhrasePrefixQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1327,20 +1327,20 @@ class Prefix(Query): """ Returns documents that contain a specific prefix in a provided field. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "prefix" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.PrefixQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.PrefixQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1475,16 +1475,16 @@ class Range(Query): """ Returns documents that contain terms within a provided range. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "range" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union[ + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union[ "wrappers.Range", "wrappers.Range", "wrappers.Range", @@ -1493,8 +1493,8 @@ def __init__( ] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1541,20 +1541,20 @@ class Regexp(Query): """ Returns documents that contain terms matching a regular expression. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "regexp" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.RegexpQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.RegexpQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1884,20 +1884,20 @@ class SpanTerm(Query): """ Matches spans containing a term. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "span_term" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.SpanTermQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.SpanTermQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1978,20 +1978,20 @@ class Term(Query): return a document, the query term must exactly match the queried field's value, including whitespace and capitalization. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "term" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.TermQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.TermQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2021,20 +2021,20 @@ class TermsSet(Query): exactly match the field values, including whitespace and capitalization. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "terms_set" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.TermsSetQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.TermsSetQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2044,20 +2044,20 @@ class TextExpansion(Query): into a list of token-weight pairs which are then used in a query against a sparse vector or rank features field. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "text_expansion" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.TextExpansionQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.TextExpansionQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2066,20 +2066,20 @@ class WeightedTokens(Query): Supports returning text_expansion query results by sending in precomputed tokens with the query. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "weighted_tokens" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.WeightedTokensQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.WeightedTokensQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2087,20 +2087,20 @@ class Wildcard(Query): """ Returns documents that contain terms matching a wildcard pattern. - :arg field: Field to use - :arg value: Field value + :arg _field: The field to use in this query. + :arg _value: The query value for the field. """ name = "wildcard" def __init__( self, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - value: Union["i.WildcardQuery", "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + _value: Union["i.WildcardQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value super().__init__(**kwargs) diff --git a/utils/generator.py b/utils/generator.py index 779a0f61..98439a6e 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -62,6 +62,7 @@ def __init__(self): url = f"https://raw.githubusercontent.com/elastic/elasticsearch-specification/{branch}/output/schema/schema.json" try: response = urlopen(url) + print(f"Initializing code generation with '{branch}' specification.") break except HTTPError: continue @@ -231,15 +232,15 @@ def generate_query_classes(schema, filename): if p["type"]["singleKey"]: k["kwargs"] = [ { - "name": "field", + "name": "_field", "type": add_not_set(key_type), - "doc": [":arg field: Field to use"], + "doc": [":arg _field: The field to use in this query."], "required": False, }, { - "name": "value", + "name": "_value", "type": add_not_set(value_type), - "doc": [":arg value: Field value"], + "doc": [":arg _value: The query value for the field."], "required": False, }, ] @@ -247,10 +248,10 @@ def generate_query_classes(schema, filename): else: k["kwargs"] = [ { - "name": "fields", + "name": "_fields", "type": f"Optional[Mapping[{key_type}, {value_type}]]", "doc": [ - ":arg fields: A dictionary of fields with their values." + ":arg _fields: A dictionary of fields with their values." ], "required": False, }, @@ -269,6 +270,7 @@ def generate_query_classes(schema, filename): classes=classes, parent="Query", interfaces=sorted(schema.interfaces) ) ) + print(f"Generated {filename}.") def generate_interfaces(schema, interfaces, filename): @@ -325,6 +327,7 @@ def generate_interfaces(schema, interfaces, filename): with open(filename, "wt") as f: f.write(interfaces_py.render(classes=classes_list)) + print(f"Generated {filename}.") if __name__ == "__main__": diff --git a/utils/templates/dsl_classes.tpl b/utils/templates/dsl_classes.tpl index c94a5455..44af7c4a 100644 --- a/utils/templates/dsl_classes.tpl +++ b/utils/templates/dsl_classes.tpl @@ -39,11 +39,11 @@ class {{ k.name }}({{ parent }}): if name in kwargs: functions.append({name: kwargs.pop(name)}) {% elif k.has_field %} - if field != NOT_SET: - kwargs[str(field)] = value + if _field != NOT_SET: + kwargs[str(_field)] = _value {% elif k.has_fields %} if fields != NOT_SET: - for field, value in field.items(): + for field, value in _fields.items(): kwargs[str(field)] = value {% endif %} super().__init__( From 3aa24309ef2fb1eba958ed9ddd441e7f5eb381a4 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 30 Aug 2024 15:47:56 +0100 Subject: [PATCH 05/27] more code generation updates --- elasticsearch_dsl/interfaces.py | 2307 ++++++++++++++++++++++++----- elasticsearch_dsl/query.py | 381 +++-- utils/generator.py | 253 ++-- utils/templates/dsl_classes.tpl | 19 +- utils/templates/interfaces.py.tpl | 36 +- utils/templates/query.py.tpl | 1 + 6 files changed, 2357 insertions(+), 640 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index 67a6eafe..bfb7ee2b 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -15,476 +15,2007 @@ # specific language governing permissions and limitations # under the License. -from typing import Any, List, Literal, Mapping, TypedDict, Union +from typing import Any, Dict, List, Literal, Mapping, Union -from elasticsearch_dsl import Query, analysis, function +from elasticsearch_dsl import Query +from elasticsearch_dsl import analysis as a +from elasticsearch_dsl import function as f from elasticsearch_dsl import interfaces as i -from elasticsearch_dsl.search_base import InstrumentedField +from elasticsearch_dsl.document_base import InstrumentedField +from elasticsearch_dsl.utils import NOT_SET, AttrDict, NotSet PipeSeparatedFlags = str -class QueryBase(TypedDict): - boost: float - _name: str +class QueryBase(AttrDict[Any]): + """ + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. + """ + + def __init__( + self, + *, + boost: Union[float, "NotSet"] = NOT_SET, + _name: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if boost != NOT_SET: + kwargs["boost"] = boost + if _name != NOT_SET: + kwargs["_name"] = _name + super().__init__(kwargs) -class MatchPhrasePrefixQuery(QueryBase): - analyzer: str - max_expansions: int - query: str - slop: int - zero_terms_query: Literal["all", "none"] - - -class MatchPhraseQuery(QueryBase): - analyzer: str - query: str - slop: int - zero_terms_query: Literal["all", "none"] - +class TermQuery(QueryBase): + """ + :arg value: (required)Term you wish to find in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. When + `false`, the case sensitivity of matching depends on the + underlying field’s mapping. + """ + + def __init__( + self, + *, + value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if value != NOT_SET: + kwargs["value"] = value + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) -class WeightedTokensQuery(QueryBase): - tokens: Mapping[str, float] - pruning_config: "i.TokenPruningConfig" +class TextExpansionQuery(QueryBase): + """ + :arg model_id: (required)The text expansion NLP model to use + :arg model_text: (required)The query text + :arg pruning_config: Token pruning configurations + """ + + def __init__( + self, + *, + model_id: Union[str, "NotSet"] = NOT_SET, + model_text: Union[str, "NotSet"] = NOT_SET, + pruning_config: Union[ + "i.TokenPruningConfig", Dict[str, Any], "NotSet" + ] = NOT_SET, + **kwargs: Any, + ): + if model_id != NOT_SET: + kwargs["model_id"] = model_id + if model_text != NOT_SET: + kwargs["model_text"] = model_text + if pruning_config != NOT_SET: + kwargs["pruning_config"] = pruning_config + super().__init__(**kwargs) + + +class QueryVectorBuilder(AttrDict[Any]): + """ + :arg text_embedding: No documentation available. + """ + + def __init__( + self, + *, + text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if text_embedding != NOT_SET: + kwargs["text_embedding"] = text_embedding + super().__init__(kwargs) + + +class DistanceFeatureQueryBase(QueryBase): + """ + :arg origin: (required)Date or point of origin used to calculate + distances. If the `field` value is a `date` or `date_nanos` field, + the `origin` value must be a date. Date Math, such as `now-1h`, is + supported. If the field value is a `geo_point` field, the `origin` + value must be a geopoint. + :arg pivot: (required)Distance from the `origin` at which relevance + scores receive half of the `boost` value. If the `field` value is + a `date` or `date_nanos` field, the `pivot` value must be a time + unit, such as `1h` or `10d`. If the `field` value is a `geo_point` + field, the `pivot` value must be a distance unit, such as `1km` or + `12m`. + :arg field: (required)Name of the field used to calculate distances. + This field must meet the following criteria: be a `date`, + `date_nanos` or `geo_point` field; have an `index` mapping + parameter value of `true`, which is the default; have an + `doc_values` mapping parameter value of `true`, which is the + default. + """ + + def __init__( + self, + *, + origin: Any = NOT_SET, + pivot: Any = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if origin != NOT_SET: + kwargs["origin"] = origin + if pivot != NOT_SET: + kwargs["pivot"] = pivot + if field != NOT_SET: + kwargs["field"] = str(field) + super().__init__(**kwargs) + + +class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): + pass -class IntervalsQuery(QueryBase): - all_of: "i.IntervalsAllOf" - any_of: "i.IntervalsAnyOf" - fuzzy: "i.IntervalsFuzzy" - match: "i.IntervalsMatch" - prefix: "i.IntervalsPrefix" - wildcard: "i.IntervalsWildcard" +class InnerHits(AttrDict[Any]): + """ + :arg name: The name for the particular inner hit definition in the + response. Useful when a search request contains multiple inner + hits. + :arg size: The maximum number of hits to return per `inner_hits`. + :arg from: Inner hit starting document offset. + :arg collapse: No documentation available. + :arg docvalue_fields: No documentation available. + :arg explain: No documentation available. + :arg highlight: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg script_fields: No documentation available. + :arg seq_no_primary_term: No documentation available. + :arg fields: No documentation available. + :arg sort: How the inner hits should be sorted per `inner_hits`. By + default, inner hits are sorted by score. + :arg _source: No documentation available. + :arg stored_fields: No documentation available. + :arg track_scores: No documentation available. + :arg version: No documentation available. + """ + + def __init__( + self, + *, + name: Union[str, "NotSet"] = NOT_SET, + size: Union[int, "NotSet"] = NOT_SET, + from_: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + docvalue_fields: Union[ + List["i.FieldAndFormat"], Dict[str, Any], "NotSet" + ] = NOT_SET, + explain: Union[bool, "NotSet"] = NOT_SET, + highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + script_fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, + fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, + stored_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + track_scores: Union[bool, "NotSet"] = NOT_SET, + version: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if name != NOT_SET: + kwargs["name"] = name + if size != NOT_SET: + kwargs["size"] = size + if from_ != NOT_SET: + kwargs["from_"] = from_ + if collapse != NOT_SET: + kwargs["collapse"] = collapse + if docvalue_fields != NOT_SET: + kwargs["docvalue_fields"] = docvalue_fields + if explain != NOT_SET: + kwargs["explain"] = explain + if highlight != NOT_SET: + kwargs["highlight"] = highlight + if ignore_unmapped != NOT_SET: + kwargs["ignore_unmapped"] = ignore_unmapped + if script_fields != NOT_SET: + kwargs["script_fields"] = str(script_fields) + if seq_no_primary_term != NOT_SET: + kwargs["seq_no_primary_term"] = seq_no_primary_term + if fields != NOT_SET: + kwargs["fields"] = str(fields) + if sort != NOT_SET: + kwargs["sort"] = str(sort) + if _source != NOT_SET: + kwargs["_source"] = _source + if stored_fields != NOT_SET: + kwargs["stored_fields"] = str(stored_fields) + if track_scores != NOT_SET: + kwargs["track_scores"] = track_scores + if version != NOT_SET: + kwargs["version"] = version + super().__init__(kwargs) + + +class GeoDistanceFeatureQuery(DistanceFeatureQueryBase): + pass -class PinnedDoc(TypedDict): - _id: str - _index: str +class SpanTermQuery(QueryBase): + """ + :arg value: (required)No documentation available. + """ -class FuzzyQuery(QueryBase): - max_expansions: int - prefix_length: int - rewrite: str - transpositions: bool - fuzziness: Union[str, int] - value: Union[str, float, bool] + def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): + if value != NOT_SET: + kwargs["value"] = value + super().__init__(**kwargs) -class RankFeatureFunction(TypedDict): +class DateDistanceFeatureQuery(DistanceFeatureQueryBase): pass -class RankFeatureFunctionLogarithm(RankFeatureFunction): - scaling_factor: float +class PinnedDoc(AttrDict[Any]): + """ + :arg _id: (required)The unique document ID. + :arg _index: (required)The index that contains the document. + """ + def __init__( + self, + *, + _id: Union[str, "NotSet"] = NOT_SET, + _index: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if _id != NOT_SET: + kwargs["_id"] = _id + if _index != NOT_SET: + kwargs["_index"] = _index + super().__init__(kwargs) -class TextExpansionQuery(QueryBase): - model_id: str - model_text: str - pruning_config: "i.TokenPruningConfig" - -class PrefixQuery(QueryBase): - rewrite: str - value: str - case_insensitive: bool +class TermsSetQuery(QueryBase): + """ + :arg minimum_should_match_field: Numeric field containing the number + of matching terms required to return a document. + :arg minimum_should_match_script: Custom script containing the number + of matching terms required to return a document. + :arg terms: (required)Array of terms you wish to find in the provided + field. + """ + + def __init__( + self, + *, + minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + minimum_should_match_script: Union[ + "i.Script", Dict[str, Any], "NotSet" + ] = NOT_SET, + terms: Union[List[str], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if minimum_should_match_field != NOT_SET: + kwargs["minimum_should_match_field"] = str(minimum_should_match_field) + if minimum_should_match_script != NOT_SET: + kwargs["minimum_should_match_script"] = minimum_should_match_script + if terms != NOT_SET: + kwargs["terms"] = terms + super().__init__(**kwargs) + + +class RankFeatureFunction(AttrDict[Any]): + pass -class TokenPruningConfig(TypedDict): - tokens_freq_ratio_threshold: int - tokens_weight_threshold: float - only_score_pruned_tokens: bool +class RankFeatureFunctionSaturation(RankFeatureFunction): + """ + :arg pivot: Configurable pivot value so that the result will be less + than 0.5. + """ + def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): + if pivot != NOT_SET: + kwargs["pivot"] = pivot + super().__init__(**kwargs) -class TermQuery(QueryBase): - value: Union[int, float, str, bool, None, Any] - case_insensitive: bool +class RegexpQuery(QueryBase): + """ + :arg case_insensitive: Allows case insensitive matching of the regular + expression value with the indexed field values when set to `true`. + When `false`, case sensitivity of matching depends on the + underlying field’s mapping. + :arg flags: Enables optional operators for the regular expression. + :arg max_determinized_states: Maximum number of automaton states + required for the query. + :arg rewrite: Method used to rewrite the query. + :arg value: (required)Regular expression for terms you wish to find in + the provided field. + """ + + def __init__( + self, + *, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + flags: Union[str, "NotSet"] = NOT_SET, + max_determinized_states: Union[int, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + if flags != NOT_SET: + kwargs["flags"] = flags + if max_determinized_states != NOT_SET: + kwargs["max_determinized_states"] = max_determinized_states + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if value != NOT_SET: + kwargs["value"] = value + super().__init__(**kwargs) -class SpanQuery(TypedDict): - span_containing: "i.SpanContainingQuery" - span_field_masking: "i.SpanFieldMaskingQuery" - span_first: "i.SpanFirstQuery" - span_gap: Mapping[Union[str, "InstrumentedField"], int] - span_multi: "i.SpanMultiTermQuery" - span_near: "i.SpanNearQuery" - span_not: "i.SpanNotQuery" - span_or: "i.SpanOrQuery" - span_term: Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"] - span_within: "i.SpanWithinQuery" +class MatchBoolPrefixQuery(QueryBase): + """ + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg fuzziness: Maximum edit distance allowed for matching. Can be + applied to the term subqueries constructed for all terms but the + final term. + :arg fuzzy_rewrite: Method used to rewrite the query. Can be applied + to the term subqueries constructed for all terms but the final + term. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). Can be applied to the term subqueries constructed for all + terms but the final term. + :arg max_expansions: Maximum number of terms to which the query will + expand. Can be applied to the term subqueries constructed for all + terms but the final term. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. Applied to the constructed bool + query. + :arg operator: Boolean logic used to interpret text in the query + value. Applied to the constructed bool query. + :arg prefix_length: Number of beginning characters left unchanged for + fuzzy matching. Can be applied to the term subqueries constructed + for all terms but the final term. + :arg query: (required)Terms you wish to find in the provided field. + The last term is used in a prefix query. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if fuzzy_rewrite != NOT_SET: + kwargs["fuzzy_rewrite"] = fuzzy_rewrite + if fuzzy_transpositions != NOT_SET: + kwargs["fuzzy_transpositions"] = fuzzy_transpositions + if max_expansions != NOT_SET: + kwargs["max_expansions"] = max_expansions + if minimum_should_match != NOT_SET: + kwargs["minimum_should_match"] = minimum_should_match + if operator != NOT_SET: + kwargs["operator"] = operator + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if query != NOT_SET: + kwargs["query"] = query + super().__init__(**kwargs) -class RankFeatureFunctionSaturation(RankFeatureFunction): - pivot: float +class FuzzyQuery(QueryBase): + """ + :arg max_expansions: Maximum number of variations created. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg rewrite: Number of beginning characters left unchanged when + creating expansions. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example `ab` to `ba`). + :arg fuzziness: Maximum edit distance allowed for matching. + :arg value: (required)Term you wish to find in the provided field. + """ + + def __init__( + self, + *, + max_expansions: Union[int, "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + value: Union[str, float, bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if max_expansions != NOT_SET: + kwargs["max_expansions"] = max_expansions + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if transpositions != NOT_SET: + kwargs["transpositions"] = transpositions + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if value != NOT_SET: + kwargs["value"] = value + super().__init__(**kwargs) -class WildcardQuery(QueryBase): - case_insensitive: bool - rewrite: str - value: str - wildcard: str +class MatchPhraseQuery(QueryBase): + """ + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg query: (required)Query terms that are analyzed and turned into a + phrase query. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if query != NOT_SET: + kwargs["query"] = query + if slop != NOT_SET: + kwargs["slop"] = slop + if zero_terms_query != NOT_SET: + kwargs["zero_terms_query"] = zero_terms_query + super().__init__(**kwargs) -class SpanTermQuery(QueryBase): - value: str +class WildcardQuery(QueryBase): + """ + :arg case_insensitive: Allows case insensitive matching of the pattern + with the indexed field values when set to true. Default is false + which means the case sensitivity of matching depends on the + underlying field’s mapping. + :arg rewrite: Method used to rewrite the query. + :arg value: Wildcard pattern for terms you wish to find in the + provided field. Required, when wildcard is not set. + :arg wildcard: Wildcard pattern for terms you wish to find in the + provided field. Required, when value is not set. + """ + + def __init__( + self, + *, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + wildcard: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if value != NOT_SET: + kwargs["value"] = value + if wildcard != NOT_SET: + kwargs["wildcard"] = wildcard + super().__init__(**kwargs) -class QueryVectorBuilder(TypedDict): - text_embedding: "i.TextEmbedding" +class RankFeatureFunctionLogarithm(RankFeatureFunction): + """ + :arg scaling_factor: (required)Configurable scaling factor. + """ -class Script(TypedDict): - source: str - id: str - params: Mapping[str, Any] - lang: Literal["painless", "expression", "mustache", "java"] - options: Mapping[str, str] + def __init__( + self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + ): + if scaling_factor != NOT_SET: + kwargs["scaling_factor"] = scaling_factor + super().__init__(**kwargs) -class CommonTermsQuery(QueryBase): - analyzer: str - cutoff_frequency: float - high_freq_operator: Literal["and", "or"] - low_freq_operator: Literal["and", "or"] - minimum_should_match: Union[int, str] - query: str - - -class InnerHits(TypedDict): - name: str - size: int - from_: int - collapse: "i.FieldCollapse" - docvalue_fields: List["i.FieldAndFormat"] - explain: bool - highlight: "i.Highlight" - ignore_unmapped: bool - script_fields: Mapping[Union[str, "InstrumentedField"], "i.ScriptField"] - seq_no_primary_term: bool - fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], - ] - _source: Union[bool, "i.SourceFilter"] - stored_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - track_scores: bool - version: bool +class MatchPhrasePrefixQuery(QueryBase): + """ + :arg analyzer: Analyzer used to convert text in the query value into + tokens. + :arg max_expansions: Maximum number of terms to which the last + provided term of the query value will expand. + :arg query: (required)Text you wish to find in the provided field. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg zero_terms_query: Indicates whether no documents are returned if + the analyzer removes all tokens, such as when using a `stop` + filter. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if max_expansions != NOT_SET: + kwargs["max_expansions"] = max_expansions + if query != NOT_SET: + kwargs["query"] = query + if slop != NOT_SET: + kwargs["slop"] = slop + if zero_terms_query != NOT_SET: + kwargs["zero_terms_query"] = zero_terms_query + super().__init__(**kwargs) + + +class TokenPruningConfig(AttrDict[Any]): + """ + :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than + this threshold times the average frequency of all tokens in the + specified field are considered outliers and pruned. + :arg tokens_weight_threshold: Tokens whose weight is less than this + threshold are considered nonsignificant and pruned. + :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs + only scoring kept tokens. + """ + + def __init__( + self, + *, + tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, + tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, + only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if tokens_freq_ratio_threshold != NOT_SET: + kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold + if tokens_weight_threshold != NOT_SET: + kwargs["tokens_weight_threshold"] = tokens_weight_threshold + if only_score_pruned_tokens != NOT_SET: + kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens + super().__init__(kwargs) + + +class FunctionScoreContainer(AttrDict[Any]): + """ + :arg exp: Function that scores a document with a exponential decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg gauss: Function that scores a document with a normal decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg linear: Function that scores a document with a linear decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg field_value_factor: Function allows you to use a field from a + document to influence the score. It’s similar to using the + script_score function, however, it avoids the overhead of + scripting. + :arg random_score: Generates scores that are uniformly distributed + from 0 up to but not including 1. In case you want scores to be + reproducible, it is possible to provide a `seed` and `field`. + :arg script_score: Enables you to wrap another query and customize the + scoring of it optionally with a computation derived from other + numeric field values in the doc using a script expression. + :arg filter: No documentation available. + :arg weight: No documentation available. + """ + + def __init__( + self, + *, + exp: Union[ + "f.UntypedDecayFunction", + "f.DateDecayFunction", + "f.NumericDecayFunction", + "f.GeoDecayFunction", + "NotSet", + ] = NOT_SET, + gauss: Union[ + "f.UntypedDecayFunction", + "f.DateDecayFunction", + "f.NumericDecayFunction", + "f.GeoDecayFunction", + "NotSet", + ] = NOT_SET, + linear: Union[ + "f.UntypedDecayFunction", + "f.DateDecayFunction", + "f.NumericDecayFunction", + "f.GeoDecayFunction", + "NotSet", + ] = NOT_SET, + field_value_factor: Union[ + "f.FieldValueFactorScoreFunction", "NotSet" + ] = NOT_SET, + random_score: Union["f.RandomScoreFunction", "NotSet"] = NOT_SET, + script_score: Union["f.ScriptScoreFunction", "NotSet"] = NOT_SET, + filter: Union[Query, "NotSet"] = NOT_SET, + weight: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if exp != NOT_SET: + kwargs["exp"] = exp + if gauss != NOT_SET: + kwargs["gauss"] = gauss + if linear != NOT_SET: + kwargs["linear"] = linear + if field_value_factor != NOT_SET: + kwargs["field_value_factor"] = field_value_factor + if random_score != NOT_SET: + kwargs["random_score"] = random_score + if script_score != NOT_SET: + kwargs["script_score"] = script_score + if filter != NOT_SET: + kwargs["filter"] = filter + if weight != NOT_SET: + kwargs["weight"] = weight + super().__init__(kwargs) -class MatchBoolPrefixQuery(QueryBase): - analyzer: str - fuzziness: Union[str, int] - fuzzy_rewrite: str - fuzzy_transpositions: bool - max_expansions: int - minimum_should_match: Union[int, str] - operator: Literal["and", "or"] - prefix_length: int - query: str - - -class FunctionScoreContainer(TypedDict): - exp: Union[ - "function.UntypedDecayFunction", - "function.DateDecayFunction", - "function.NumericDecayFunction", - "function.GeoDecayFunction", - ] - gauss: Union[ - "function.UntypedDecayFunction", - "function.DateDecayFunction", - "function.NumericDecayFunction", - "function.GeoDecayFunction", - ] - linear: Union[ - "function.UntypedDecayFunction", - "function.DateDecayFunction", - "function.NumericDecayFunction", - "function.GeoDecayFunction", - ] - field_value_factor: "function.FieldValueFactorScoreFunction" - random_score: "function.RandomScoreFunction" - script_score: "function.ScriptScoreFunction" - filter: Query - weight: float +class IntervalsQuery(QueryBase): + """ + :arg all_of: Returns matches that span a combination of other rules. + :arg any_of: Returns intervals produced by any of its sub-rules. + :arg fuzzy: Matches terms that are similar to the provided term, + within an edit distance defined by `fuzziness`. + :arg match: Matches analyzed text. + :arg prefix: Matches terms that start with a specified set of + characters. + :arg wildcard: Matches terms using a wildcard pattern. + """ + + def __init__( + self, + *, + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, + match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if all_of != NOT_SET: + kwargs["all_of"] = all_of + if any_of != NOT_SET: + kwargs["any_of"] = any_of + if fuzzy != NOT_SET: + kwargs["fuzzy"] = fuzzy + if match != NOT_SET: + kwargs["match"] = match + if prefix != NOT_SET: + kwargs["prefix"] = prefix + if wildcard != NOT_SET: + kwargs["wildcard"] = wildcard + super().__init__(**kwargs) class RankFeatureFunctionLinear(RankFeatureFunction): pass -class TermsSetQuery(QueryBase): - minimum_should_match_field: Union[str, "InstrumentedField"] - minimum_should_match_script: "i.Script" - terms: List[str] - - -class LikeDocument(TypedDict): - doc: Any - fields: List[Union[str, "InstrumentedField"]] - _id: str - _index: str - per_field_analyzer: Mapping[Union[str, "InstrumentedField"], str] - routing: str - version: int - version_type: Literal["internal", "external", "external_gte", "force"] - - -class RegexpQuery(QueryBase): - case_insensitive: bool - flags: str - max_determinized_states: int - rewrite: str - value: str - - class MatchQuery(QueryBase): - analyzer: str - auto_generate_synonyms_phrase_query: bool - cutoff_frequency: float - fuzziness: Union[str, int] - fuzzy_rewrite: str - fuzzy_transpositions: bool - lenient: bool - max_expansions: int - minimum_should_match: Union[int, str] - operator: Literal["and", "or"] - prefix_length: int - query: Union[str, float, bool] - zero_terms_query: Literal["all", "none"] - - -class RankFeatureFunctionSigmoid(RankFeatureFunction): - pivot: float - exponent: float - + """ + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg auto_generate_synonyms_phrase_query: If `true`, match phrase + queries are automatically created for multi-term synonyms. + :arg cutoff_frequency: No documentation available. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg fuzzy_rewrite: Method used to rewrite the query. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). + :arg lenient: If `true`, format-based errors, such as providing a text + query value for a numeric field, are ignored. + :arg max_expansions: Maximum number of terms to which the query will + expand. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg operator: Boolean logic used to interpret text in the query + value. + :arg prefix_length: Number of beginning characters left unchanged for + fuzzy matching. + :arg query: (required)Text, number, boolean value or date you wish to + find in the provided field. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + query: Union[str, float, bool, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if auto_generate_synonyms_phrase_query != NOT_SET: + kwargs["auto_generate_synonyms_phrase_query"] = ( + auto_generate_synonyms_phrase_query + ) + if cutoff_frequency != NOT_SET: + kwargs["cutoff_frequency"] = cutoff_frequency + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if fuzzy_rewrite != NOT_SET: + kwargs["fuzzy_rewrite"] = fuzzy_rewrite + if fuzzy_transpositions != NOT_SET: + kwargs["fuzzy_transpositions"] = fuzzy_transpositions + if lenient != NOT_SET: + kwargs["lenient"] = lenient + if max_expansions != NOT_SET: + kwargs["max_expansions"] = max_expansions + if minimum_should_match != NOT_SET: + kwargs["minimum_should_match"] = minimum_should_match + if operator != NOT_SET: + kwargs["operator"] = operator + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if query != NOT_SET: + kwargs["query"] = query + if zero_terms_query != NOT_SET: + kwargs["zero_terms_query"] = zero_terms_query + super().__init__(**kwargs) -class IntervalsAllOf(TypedDict): - intervals: List["i.IntervalsContainer"] - max_gaps: int - ordered: bool - filter: "i.IntervalsFilter" - -class IntervalsAnyOf(TypedDict): - intervals: List["i.IntervalsContainer"] - filter: "i.IntervalsFilter" +class WeightedTokensQuery(QueryBase): + """ + :arg tokens: (required)The tokens representing this query + :arg pruning_config: Token pruning configurations + """ + + def __init__( + self, + *, + tokens: Union[Mapping[str, float], "NotSet"] = NOT_SET, + pruning_config: Union[ + "i.TokenPruningConfig", Dict[str, Any], "NotSet" + ] = NOT_SET, + **kwargs: Any, + ): + if tokens != NOT_SET: + kwargs["tokens"] = tokens + if pruning_config != NOT_SET: + kwargs["pruning_config"] = pruning_config + super().__init__(**kwargs) + + +class LikeDocument(AttrDict[Any]): + """ + :arg doc: A document not present in the index. + :arg fields: No documentation available. + :arg _id: ID of a document. + :arg _index: Index of a document. + :arg per_field_analyzer: Overrides the default analyzer. + :arg routing: No documentation available. + :arg version: No documentation available. + :arg version_type: No documentation available. + """ + + def __init__( + self, + *, + doc: Any = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + _id: Union[str, "NotSet"] = NOT_SET, + _index: Union[str, "NotSet"] = NOT_SET, + per_field_analyzer: Union[ + Mapping[Union[str, "InstrumentedField"], str], "NotSet" + ] = NOT_SET, + routing: Union[str, "NotSet"] = NOT_SET, + version: Union[int, "NotSet"] = NOT_SET, + version_type: Union[ + Literal["internal", "external", "external_gte", "force"], "NotSet" + ] = NOT_SET, + **kwargs: Any, + ): + if doc != NOT_SET: + kwargs["doc"] = doc + if fields != NOT_SET: + kwargs["fields"] = str(fields) + if _id != NOT_SET: + kwargs["_id"] = _id + if _index != NOT_SET: + kwargs["_index"] = _index + if per_field_analyzer != NOT_SET: + kwargs["per_field_analyzer"] = str(per_field_analyzer) + if routing != NOT_SET: + kwargs["routing"] = routing + if version != NOT_SET: + kwargs["version"] = version + if version_type != NOT_SET: + kwargs["version_type"] = version_type + super().__init__(kwargs) + + +class SpanQuery(AttrDict[Any]): + """ + :arg span_containing: Accepts a list of span queries, but only returns + those spans which also match a second span query. + :arg span_field_masking: Allows queries like `span_near` or `span_or` + across different fields. + :arg span_first: Accepts another span query whose matches must appear + within the first N positions of the field. + :arg span_gap: No documentation available. + :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, + `regexp`, or `fuzzy` query. + :arg span_near: Accepts multiple span queries whose matches must be + within the specified distance of each other, and possibly in the + same order. + :arg span_not: Wraps another span query, and excludes any documents + which match that query. + :arg span_or: Combines multiple span queries and returns documents + which match any of the specified queries. + :arg span_term: The equivalent of the `term` query but for use with + other span queries. + :arg span_within: The result from a single span query is returned as + long is its span falls within the spans returned by a list of + other span queries. + """ + + def __init__( + self, + *, + span_containing: Union[ + "i.SpanContainingQuery", Dict[str, Any], "NotSet" + ] = NOT_SET, + span_field_masking: Union[ + "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" + ] = NOT_SET, + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_gap: Union[ + Mapping[Union[str, "InstrumentedField"], int], "NotSet" + ] = NOT_SET, + span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_term: Union[ + Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if span_containing != NOT_SET: + kwargs["span_containing"] = span_containing + if span_field_masking != NOT_SET: + kwargs["span_field_masking"] = span_field_masking + if span_first != NOT_SET: + kwargs["span_first"] = span_first + if span_gap != NOT_SET: + kwargs["span_gap"] = str(span_gap) + if span_multi != NOT_SET: + kwargs["span_multi"] = span_multi + if span_near != NOT_SET: + kwargs["span_near"] = span_near + if span_not != NOT_SET: + kwargs["span_not"] = span_not + if span_or != NOT_SET: + kwargs["span_or"] = span_or + if span_term != NOT_SET: + kwargs["span_term"] = str(span_term) + if span_within != NOT_SET: + kwargs["span_within"] = span_within + super().__init__(kwargs) -class IntervalsFuzzy(TypedDict): - analyzer: str - fuzziness: Union[str, int] - prefix_length: int - term: str - transpositions: bool - use_field: Union[str, "InstrumentedField"] +class PrefixQuery(QueryBase): + """ + :arg rewrite: Method used to rewrite the query. + :arg value: (required)Beginning characters of terms you wish to find + in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. Default is + `false` which means the case sensitivity of matching depends on + the underlying field’s mapping. + """ + + def __init__( + self, + *, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if value != NOT_SET: + kwargs["value"] = value + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) -class IntervalsPrefix(TypedDict): - analyzer: str - prefix: str - use_field: Union[str, "InstrumentedField"] +class RankFeatureFunctionSigmoid(RankFeatureFunction): + """ + :arg pivot: (required)Configurable pivot value so that the result will + be less than 0.5. + :arg exponent: (required)Configurable Exponent. + """ + + def __init__( + self, + *, + pivot: Union[float, "NotSet"] = NOT_SET, + exponent: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if pivot != NOT_SET: + kwargs["pivot"] = pivot + if exponent != NOT_SET: + kwargs["exponent"] = exponent + super().__init__(**kwargs) -class IntervalsMatch(TypedDict): - analyzer: str - max_gaps: int - ordered: bool - query: str - use_field: Union[str, "InstrumentedField"] - filter: "i.IntervalsFilter" +class CommonTermsQuery(QueryBase): + """ + :arg analyzer: No documentation available. + :arg cutoff_frequency: No documentation available. + :arg high_freq_operator: No documentation available. + :arg low_freq_operator: No documentation available. + :arg minimum_should_match: No documentation available. + :arg query: (required)No documentation available. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if cutoff_frequency != NOT_SET: + kwargs["cutoff_frequency"] = cutoff_frequency + if high_freq_operator != NOT_SET: + kwargs["high_freq_operator"] = high_freq_operator + if low_freq_operator != NOT_SET: + kwargs["low_freq_operator"] = low_freq_operator + if minimum_should_match != NOT_SET: + kwargs["minimum_should_match"] = minimum_should_match + if query != NOT_SET: + kwargs["query"] = query + super().__init__(**kwargs) + + +class Script(AttrDict[Any]): + """ + :arg source: The script source. + :arg id: The `id` for a stored script. + :arg params: Specifies any named parameters that are passed into the + script as variables. Use parameters instead of hard-coded values + to decrease compile time. + :arg lang: Specifies the language the script is written in. + :arg options: No documentation available. + """ + + def __init__( + self, + *, + source: Union[str, "NotSet"] = NOT_SET, + id: Union[str, "NotSet"] = NOT_SET, + params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + lang: Union[ + Literal["painless", "expression", "mustache", "java"], "NotSet" + ] = NOT_SET, + options: Union[Mapping[str, str], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if source != NOT_SET: + kwargs["source"] = source + if id != NOT_SET: + kwargs["id"] = id + if params != NOT_SET: + kwargs["params"] = params + if lang != NOT_SET: + kwargs["lang"] = lang + if options != NOT_SET: + kwargs["options"] = options + super().__init__(kwargs) + + +class TextEmbedding(AttrDict[Any]): + """ + :arg model_id: (required)No documentation available. + :arg model_text: (required)No documentation available. + """ + + def __init__( + self, + *, + model_id: Union[str, "NotSet"] = NOT_SET, + model_text: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if model_id != NOT_SET: + kwargs["model_id"] = model_id + if model_text != NOT_SET: + kwargs["model_text"] = model_text + super().__init__(kwargs) + + +class HighlightBase(AttrDict[Any]): + """ + :arg type: No documentation available. + :arg boundary_chars: A string that contains each boundary character. + :arg boundary_max_scan: How far to scan for boundary characters. + :arg boundary_scanner: Specifies how to break the highlighted + fragments: chars, sentence, or word. Only valid for the unified + and fvh highlighters. Defaults to `sentence` for the `unified` + highlighter. Defaults to `chars` for the `fvh` highlighter. + :arg boundary_scanner_locale: Controls which locale is used to search + for sentence and word boundaries. This parameter takes a form of a + language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + :arg force_source: No documentation available. + :arg fragmenter: Specifies how text should be broken up in highlight + snippets: `simple` or `span`. Only valid for the `plain` + highlighter. + :arg fragment_size: The size of the highlighted fragment in + characters. + :arg highlight_filter: No documentation available. + :arg highlight_query: Highlight matches for a query other than the + search query. This is especially useful if you use a rescore query + because those are not taken into account by highlighting by + default. + :arg max_fragment_length: No documentation available. + :arg max_analyzed_offset: If set to a non-negative value, highlighting + stops at this defined maximum limit. The rest of the text is not + processed, thus not highlighted and no error is returned The + `max_analyzed_offset` query setting does not override the + `index.highlight.max_analyzed_offset` setting, which prevails when + it’s set to lower value than the query setting. + :arg no_match_size: The amount of text you want to return from the + beginning of the field if there are no matching fragments to + highlight. + :arg number_of_fragments: The maximum number of fragments to return. + If the number of fragments is set to `0`, no fragments are + returned. Instead, the entire field contents are highlighted and + returned. This can be handy when you need to highlight short texts + such as a title or address, but fragmentation is not required. If + `number_of_fragments` is `0`, `fragment_size` is ignored. + :arg options: No documentation available. + :arg order: Sorts highlighted fragments by score when set to `score`. + By default, fragments will be output in the order they appear in + the field (order: `none`). Setting this option to `score` will + output the most relevant fragments first. Each highlighter applies + its own logic to compute relevancy scores. + :arg phrase_limit: Controls the number of matching phrases in a + document that are considered. Prevents the `fvh` highlighter from + analyzing too many phrases and consuming too much memory. When + using `matched_fields`, `phrase_limit` phrases per matched field + are considered. Raising the limit increases query time and + consumes more memory. Only supported by the `fvh` highlighter. + :arg post_tags: Use in conjunction with `pre_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg pre_tags: Use in conjunction with `post_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg require_field_match: By default, only fields that contains a + query match are highlighted. Set to `false` to highlight all + fields. + :arg tags_schema: Set to `styled` to use the built-in tag schema. + """ + + def __init__( + self, + *, + type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, + boundary_chars: Union[str, "NotSet"] = NOT_SET, + boundary_max_scan: Union[int, "NotSet"] = NOT_SET, + boundary_scanner: Union[ + Literal["chars", "sentence", "word"], "NotSet" + ] = NOT_SET, + boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, + force_source: Union[bool, "NotSet"] = NOT_SET, + fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, + fragment_size: Union[int, "NotSet"] = NOT_SET, + highlight_filter: Union[bool, "NotSet"] = NOT_SET, + highlight_query: Union[Query, "NotSet"] = NOT_SET, + max_fragment_length: Union[int, "NotSet"] = NOT_SET, + max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, + no_match_size: Union[int, "NotSet"] = NOT_SET, + number_of_fragments: Union[int, "NotSet"] = NOT_SET, + options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + order: Union[Literal["score"], "NotSet"] = NOT_SET, + phrase_limit: Union[int, "NotSet"] = NOT_SET, + post_tags: Union[List[str], "NotSet"] = NOT_SET, + pre_tags: Union[List[str], "NotSet"] = NOT_SET, + require_field_match: Union[bool, "NotSet"] = NOT_SET, + tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if type != NOT_SET: + kwargs["type"] = type + if boundary_chars != NOT_SET: + kwargs["boundary_chars"] = boundary_chars + if boundary_max_scan != NOT_SET: + kwargs["boundary_max_scan"] = boundary_max_scan + if boundary_scanner != NOT_SET: + kwargs["boundary_scanner"] = boundary_scanner + if boundary_scanner_locale != NOT_SET: + kwargs["boundary_scanner_locale"] = boundary_scanner_locale + if force_source != NOT_SET: + kwargs["force_source"] = force_source + if fragmenter != NOT_SET: + kwargs["fragmenter"] = fragmenter + if fragment_size != NOT_SET: + kwargs["fragment_size"] = fragment_size + if highlight_filter != NOT_SET: + kwargs["highlight_filter"] = highlight_filter + if highlight_query != NOT_SET: + kwargs["highlight_query"] = highlight_query + if max_fragment_length != NOT_SET: + kwargs["max_fragment_length"] = max_fragment_length + if max_analyzed_offset != NOT_SET: + kwargs["max_analyzed_offset"] = max_analyzed_offset + if no_match_size != NOT_SET: + kwargs["no_match_size"] = no_match_size + if number_of_fragments != NOT_SET: + kwargs["number_of_fragments"] = number_of_fragments + if options != NOT_SET: + kwargs["options"] = options + if order != NOT_SET: + kwargs["order"] = order + if phrase_limit != NOT_SET: + kwargs["phrase_limit"] = phrase_limit + if post_tags != NOT_SET: + kwargs["post_tags"] = post_tags + if pre_tags != NOT_SET: + kwargs["pre_tags"] = pre_tags + if require_field_match != NOT_SET: + kwargs["require_field_match"] = require_field_match + if tags_schema != NOT_SET: + kwargs["tags_schema"] = tags_schema + super().__init__(kwargs) -class IntervalsWildcard(TypedDict): - analyzer: str - pattern: str - use_field: Union[str, "InstrumentedField"] +class Highlight(HighlightBase): + """ + :arg encoder: No documentation available. + :arg fields: (required)No documentation available. + """ + + def __init__( + self, + *, + encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, + fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + **kwargs: Any, + ): + if encoder != NOT_SET: + kwargs["encoder"] = encoder + if fields != NOT_SET: + kwargs["fields"] = str(fields) + super().__init__(**kwargs) + + +class FieldCollapse(AttrDict[Any]): + """ + :arg field: (required)The field to collapse the result set on + :arg inner_hits: The number of inner hits and their sort order + :arg max_concurrent_group_searches: The number of concurrent requests + allowed to retrieve the inner_hits per group + :arg collapse: No documentation available. + """ + + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + inner_hits: Union[ + "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if field != NOT_SET: + kwargs["field"] = str(field) + if inner_hits != NOT_SET: + kwargs["inner_hits"] = inner_hits + if max_concurrent_group_searches != NOT_SET: + kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches + if collapse != NOT_SET: + kwargs["collapse"] = collapse + super().__init__(kwargs) + + +class FieldAndFormat(AttrDict[Any]): + """ + :arg field: (required)Wildcard pattern. The request returns values for + field names matching this pattern. + :arg format: Format in which the values are returned. + :arg include_unmapped: No documentation available. + """ + + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + format: Union[str, "NotSet"] = NOT_SET, + include_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if field != NOT_SET: + kwargs["field"] = str(field) + if format != NOT_SET: + kwargs["format"] = format + if include_unmapped != NOT_SET: + kwargs["include_unmapped"] = include_unmapped + super().__init__(kwargs) + + +class SourceFilter(AttrDict[Any]): + """ + :arg excludes: No documentation available. + :arg includes: No documentation available. + """ + + def __init__( + self, + *, + excludes: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + includes: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + **kwargs: Any, + ): + if excludes != NOT_SET: + kwargs["excludes"] = str(excludes) + if includes != NOT_SET: + kwargs["includes"] = str(includes) + super().__init__(kwargs) + + +class ScriptField(AttrDict[Any]): + """ + :arg script: (required)No documentation available. + :arg ignore_failure: No documentation available. + """ + + def __init__( + self, + *, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_failure: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if script != NOT_SET: + kwargs["script"] = script + if ignore_failure != NOT_SET: + kwargs["ignore_failure"] = ignore_failure + super().__init__(kwargs) + + +class SortOptions(AttrDict[Any]): + """ + :arg _score: No documentation available. + :arg _doc: No documentation available. + :arg _geo_distance: No documentation available. + :arg _script: No documentation available. + """ + + def __init__( + self, + *, + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if _score != NOT_SET: + kwargs["_score"] = _score + if _doc != NOT_SET: + kwargs["_doc"] = _doc + if _geo_distance != NOT_SET: + kwargs["_geo_distance"] = _geo_distance + if _script != NOT_SET: + kwargs["_script"] = _script + super().__init__(kwargs) + + +class IntervalsFuzzy(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to normalize the term. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg term: (required)The term to match. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example, `ab` to `ba`). + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `term` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + term: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if term != NOT_SET: + kwargs["term"] = term + if transpositions != NOT_SET: + kwargs["transpositions"] = transpositions + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + +class IntervalsAllOf(AttrDict[Any]): + """ + :arg intervals: (required)An array of rules to combine. All rules must + produce a match in a document for the overall source to match. + :arg max_gaps: Maximum number of positions between the matching terms. + Intervals produced by the rules further apart than this are not + considered matches. + :arg ordered: If `true`, intervals produced by the rules should appear + in the order in which they are specified. + :arg filter: Rule used to filter returned intervals. + """ + + def __init__( + self, + *, + intervals: Union[ + List["i.IntervalsContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_gaps: Union[int, "NotSet"] = NOT_SET, + ordered: Union[bool, "NotSet"] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if intervals != NOT_SET: + kwargs["intervals"] = intervals + if max_gaps != NOT_SET: + kwargs["max_gaps"] = max_gaps + if ordered != NOT_SET: + kwargs["ordered"] = ordered + if filter != NOT_SET: + kwargs["filter"] = filter + super().__init__(kwargs) + + +class IntervalsMatch(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze terms in the query. + :arg max_gaps: Maximum number of positions between the matching terms. + Terms further apart than this are not considered matches. + :arg ordered: If `true`, matching terms must appear in their specified + order. + :arg query: (required)Text you wish to find in the provided field. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `term` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. + :arg filter: An optional interval filter. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + max_gaps: Union[int, "NotSet"] = NOT_SET, + ordered: Union[bool, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if max_gaps != NOT_SET: + kwargs["max_gaps"] = max_gaps + if ordered != NOT_SET: + kwargs["ordered"] = ordered + if query != NOT_SET: + kwargs["query"] = query + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + if filter != NOT_SET: + kwargs["filter"] = filter + super().__init__(kwargs) + + +class IntervalsPrefix(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze the `prefix`. + :arg prefix: (required)Beginning characters of terms you wish to find + in the top-level field. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `prefix` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + prefix: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if prefix != NOT_SET: + kwargs["prefix"] = prefix + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + +class IntervalsWildcard(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the + top-level field's analyzer. + :arg pattern: (required)Wildcard pattern used to find matching terms. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `pattern` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + pattern: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if pattern != NOT_SET: + kwargs["pattern"] = pattern + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + +class IntervalsAnyOf(AttrDict[Any]): + """ + :arg intervals: (required)An array of rules to match. + :arg filter: Rule used to filter returned intervals. + """ + + def __init__( + self, + *, + intervals: Union[ + List["i.IntervalsContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if intervals != NOT_SET: + kwargs["intervals"] = intervals + if filter != NOT_SET: + kwargs["filter"] = filter + super().__init__(kwargs) class SpanFieldMaskingQuery(QueryBase): - field: Union[str, "InstrumentedField"] - query: "i.SpanQuery" + """ + :arg field: (required)No documentation available. + :arg query: (required)No documentation available. + """ + + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if field != NOT_SET: + kwargs["field"] = str(field) + if query != NOT_SET: + kwargs["query"] = query + super().__init__(**kwargs) class SpanNearQuery(QueryBase): - clauses: List["i.SpanQuery"] - in_order: bool - slop: int - + """ + :arg clauses: (required)Array of one or more other span type queries. + :arg in_order: Controls whether matches are required to be in-order. + :arg slop: Controls the maximum number of intervening unmatched + positions permitted. + """ + + def __init__( + self, + *, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + in_order: Union[bool, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if clauses != NOT_SET: + kwargs["clauses"] = clauses + if in_order != NOT_SET: + kwargs["in_order"] = in_order + if slop != NOT_SET: + kwargs["slop"] = slop + super().__init__(**kwargs) -class SpanContainingQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" +class SpanMultiTermQuery(QueryBase): + """ + :arg match: (required)Should be a multi term query (one of `wildcard`, + `fuzzy`, `prefix`, `range`, or `regexp` query). + """ -class SpanOrQuery(QueryBase): - clauses: List["i.SpanQuery"] + def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): + if match != NOT_SET: + kwargs["match"] = match + super().__init__(**kwargs) -class SpanNotQuery(QueryBase): - dist: int - exclude: "i.SpanQuery" - include: "i.SpanQuery" - post: int - pre: int +class SpanContainingQuery(QueryBase): + """ + :arg big: (required)Can be any span query. Matching spans from `big` + that contain matches from `little` are returned. + :arg little: (required)Can be any span query. Matching spans from + `big` that contain matches from `little` are returned. + """ + + def __init__( + self, + *, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if big != NOT_SET: + kwargs["big"] = big + if little != NOT_SET: + kwargs["little"] = little + super().__init__(**kwargs) class SpanFirstQuery(QueryBase): - end: int - match: "i.SpanQuery" + """ + :arg end: (required)Controls the maximum end position permitted in a + match. + :arg match: (required)Can be any other span type query. + """ + + def __init__( + self, + *, + end: Union[int, "NotSet"] = NOT_SET, + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if end != NOT_SET: + kwargs["end"] = end + if match != NOT_SET: + kwargs["match"] = match + super().__init__(**kwargs) -class SpanMultiTermQuery(QueryBase): - match: Query +class SpanNotQuery(QueryBase): + """ + :arg dist: The number of tokens from within the include span that + can’t have overlap with the exclude span. Equivalent to setting + both `pre` and `post`. + :arg exclude: (required)Span query whose matches must not overlap + those returned. + :arg include: (required)Span query whose matches are filtered. + :arg post: The number of tokens after the include span that can’t have + overlap with the exclude span. + :arg pre: The number of tokens before the include span that can’t have + overlap with the exclude span. + """ + + def __init__( + self, + *, + dist: Union[int, "NotSet"] = NOT_SET, + exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + post: Union[int, "NotSet"] = NOT_SET, + pre: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if dist != NOT_SET: + kwargs["dist"] = dist + if exclude != NOT_SET: + kwargs["exclude"] = exclude + if include != NOT_SET: + kwargs["include"] = include + if post != NOT_SET: + kwargs["post"] = post + if pre != NOT_SET: + kwargs["pre"] = pre + super().__init__(**kwargs) class SpanWithinQuery(QueryBase): - big: "i.SpanQuery" - little: "i.SpanQuery" - - -class TextEmbedding(TypedDict): - model_id: str - model_text: str - - -class FieldAndFormat(TypedDict): - field: Union[str, "InstrumentedField"] - format: str - include_unmapped: bool - - -class HighlightBase(TypedDict): - type: Literal["plain", "fvh", "unified"] - boundary_chars: str - boundary_max_scan: int - boundary_scanner: Literal["chars", "sentence", "word"] - boundary_scanner_locale: str - force_source: bool - fragmenter: Literal["simple", "span"] - fragment_size: int - highlight_filter: bool - highlight_query: Query - max_fragment_length: int - max_analyzed_offset: int - no_match_size: int - number_of_fragments: int - options: Mapping[str, Any] - order: Literal["score"] - phrase_limit: int - post_tags: List[str] - pre_tags: List[str] - require_field_match: bool - tags_schema: Literal["styled"] - - -class Highlight(HighlightBase): - encoder: Literal["default", "html"] - fields: Mapping[Union[str, "InstrumentedField"], "i.HighlightField"] - + """ + :arg big: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg little: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + """ + + def __init__( + self, + *, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if big != NOT_SET: + kwargs["big"] = big + if little != NOT_SET: + kwargs["little"] = little + super().__init__(**kwargs) -class SourceFilter(TypedDict): - excludes: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - includes: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - - -class SortOptions(TypedDict): - _score: "i.ScoreSort" - _doc: "i.ScoreSort" - _geo_distance: "i.GeoDistanceSort" - _script: "i.ScriptSort" - - -class FieldCollapse(TypedDict): - field: Union[str, "InstrumentedField"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"]] - max_concurrent_group_searches: int - collapse: "i.FieldCollapse" - - -class ScriptField(TypedDict): - script: "i.Script" - ignore_failure: bool - - -class IntervalsContainer(TypedDict): - all_of: "i.IntervalsAllOf" - any_of: "i.IntervalsAnyOf" - fuzzy: "i.IntervalsFuzzy" - match: "i.IntervalsMatch" - prefix: "i.IntervalsPrefix" - wildcard: "i.IntervalsWildcard" +class SpanOrQuery(QueryBase): + """ + :arg clauses: (required)Array of one or more other span type queries. + """ -class IntervalsFilter(TypedDict): - after: "i.IntervalsContainer" - before: "i.IntervalsContainer" - contained_by: "i.IntervalsContainer" - containing: "i.IntervalsContainer" - not_contained_by: "i.IntervalsContainer" - not_containing: "i.IntervalsContainer" - not_overlapping: "i.IntervalsContainer" - overlapping: "i.IntervalsContainer" - script: "i.Script" + def __init__( + self, + *, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if clauses != NOT_SET: + kwargs["clauses"] = clauses + super().__init__(**kwargs) class HighlightField(HighlightBase): - fragment_offset: int - matched_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]] - ] - analyzer: Union[ - "analysis.CustomAnalyzer", - "analysis.FingerprintAnalyzer", - "analysis.KeywordAnalyzer", - "analysis.LanguageAnalyzer", - "analysis.NoriAnalyzer", - "analysis.PatternAnalyzer", - "analysis.SimpleAnalyzer", - "analysis.StandardAnalyzer", - "analysis.StopAnalyzer", - "analysis.WhitespaceAnalyzer", - "analysis.IcuAnalyzer", - "analysis.KuromojiAnalyzer", - "analysis.SnowballAnalyzer", - "analysis.DutchAnalyzer", - ] - - -class GeoDistanceSort(TypedDict): - mode: Literal["min", "max", "sum", "avg", "median"] - distance_type: Literal["arc", "plane"] - ignore_unmapped: bool - order: Literal["asc", "desc"] - unit: Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"] - nested: "i.NestedSortValue" - - -class ScoreSort(TypedDict): - order: Literal["asc", "desc"] - - -class ScriptSort(TypedDict): - order: Literal["asc", "desc"] - script: "i.Script" - type: Literal["string", "number", "version"] - mode: Literal["min", "max", "sum", "avg", "median"] - nested: "i.NestedSortValue" - - -class NestedSortValue(TypedDict): - filter: Query - max_children: int - nested: "i.NestedSortValue" - path: Union[str, "InstrumentedField"] + """ + :arg fragment_offset: No documentation available. + :arg matched_fields: No documentation available. + :arg analyzer: No documentation available. + """ + + def __init__( + self, + *, + fragment_offset: Union[int, "NotSet"] = NOT_SET, + matched_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + analyzer: Union[ + "a.CustomAnalyzer", + "a.FingerprintAnalyzer", + "a.KeywordAnalyzer", + "a.LanguageAnalyzer", + "a.NoriAnalyzer", + "a.PatternAnalyzer", + "a.SimpleAnalyzer", + "a.StandardAnalyzer", + "a.StopAnalyzer", + "a.WhitespaceAnalyzer", + "a.IcuAnalyzer", + "a.KuromojiAnalyzer", + "a.SnowballAnalyzer", + "a.DutchAnalyzer", + "NotSet", + ] = NOT_SET, + **kwargs: Any, + ): + if fragment_offset != NOT_SET: + kwargs["fragment_offset"] = fragment_offset + if matched_fields != NOT_SET: + kwargs["matched_fields"] = str(matched_fields) + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + super().__init__(**kwargs) + + +class ScriptSort(AttrDict[Any]): + """ + :arg order: No documentation available. + :arg script: (required)No documentation available. + :arg type: No documentation available. + :arg mode: No documentation available. + :arg nested: No documentation available. + """ + + def __init__( + self, + *, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if order != NOT_SET: + kwargs["order"] = order + if script != NOT_SET: + kwargs["script"] = script + if type != NOT_SET: + kwargs["type"] = type + if mode != NOT_SET: + kwargs["mode"] = mode + if nested != NOT_SET: + kwargs["nested"] = nested + super().__init__(kwargs) + + +class GeoDistanceSort(AttrDict[Any]): + """ + :arg mode: No documentation available. + :arg distance_type: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg order: No documentation available. + :arg unit: No documentation available. + :arg nested: No documentation available. + """ + + def __init__( + self, + *, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + unit: Union[ + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" + ] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if mode != NOT_SET: + kwargs["mode"] = mode + if distance_type != NOT_SET: + kwargs["distance_type"] = distance_type + if ignore_unmapped != NOT_SET: + kwargs["ignore_unmapped"] = ignore_unmapped + if order != NOT_SET: + kwargs["order"] = order + if unit != NOT_SET: + kwargs["unit"] = unit + if nested != NOT_SET: + kwargs["nested"] = nested + super().__init__(kwargs) + + +class ScoreSort(AttrDict[Any]): + """ + :arg order: No documentation available. + """ + + def __init__( + self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + ): + if order != NOT_SET: + kwargs["order"] = order + super().__init__(kwargs) + + +class IntervalsContainer(AttrDict[Any]): + """ + :arg all_of: Returns matches that span a combination of other rules. + :arg any_of: Returns intervals produced by any of its sub-rules. + :arg fuzzy: Matches analyzed text. + :arg match: Matches analyzed text. + :arg prefix: Matches terms that start with a specified set of + characters. + :arg wildcard: Matches terms using a wildcard pattern. + """ + + def __init__( + self, + *, + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, + match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if all_of != NOT_SET: + kwargs["all_of"] = all_of + if any_of != NOT_SET: + kwargs["any_of"] = any_of + if fuzzy != NOT_SET: + kwargs["fuzzy"] = fuzzy + if match != NOT_SET: + kwargs["match"] = match + if prefix != NOT_SET: + kwargs["prefix"] = prefix + if wildcard != NOT_SET: + kwargs["wildcard"] = wildcard + super().__init__(kwargs) + + +class IntervalsFilter(AttrDict[Any]): + """ + :arg after: Query used to return intervals that follow an interval + from the `filter` rule. + :arg before: Query used to return intervals that occur before an + interval from the `filter` rule. + :arg contained_by: Query used to return intervals contained by an + interval from the `filter` rule. + :arg containing: Query used to return intervals that contain an + interval from the `filter` rule. + :arg not_contained_by: Query used to return intervals that are **not** + contained by an interval from the `filter` rule. + :arg not_containing: Query used to return intervals that do **not** + contain an interval from the `filter` rule. + :arg not_overlapping: Query used to return intervals that do **not** + overlap with an interval from the `filter` rule. + :arg overlapping: Query used to return intervals that overlap with an + interval from the `filter` rule. + :arg script: Script used to return matching documents. This script + must return a boolean value: `true` or `false`. + """ + + def __init__( + self, + *, + after: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + before: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + not_contained_by: Union[ + "i.IntervalsContainer", Dict[str, Any], "NotSet" + ] = NOT_SET, + not_containing: Union[ + "i.IntervalsContainer", Dict[str, Any], "NotSet" + ] = NOT_SET, + not_overlapping: Union[ + "i.IntervalsContainer", Dict[str, Any], "NotSet" + ] = NOT_SET, + overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if after != NOT_SET: + kwargs["after"] = after + if before != NOT_SET: + kwargs["before"] = before + if contained_by != NOT_SET: + kwargs["contained_by"] = contained_by + if containing != NOT_SET: + kwargs["containing"] = containing + if not_contained_by != NOT_SET: + kwargs["not_contained_by"] = not_contained_by + if not_containing != NOT_SET: + kwargs["not_containing"] = not_containing + if not_overlapping != NOT_SET: + kwargs["not_overlapping"] = not_overlapping + if overlapping != NOT_SET: + kwargs["overlapping"] = overlapping + if script != NOT_SET: + kwargs["script"] = script + super().__init__(kwargs) + + +class NestedSortValue(AttrDict[Any]): + """ + :arg filter: No documentation available. + :arg max_children: No documentation available. + :arg nested: No documentation available. + :arg path: (required)No documentation available. + """ + + def __init__( + self, + *, + filter: Union[Query, "NotSet"] = NOT_SET, + max_children: Union[int, "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + path: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if filter != NOT_SET: + kwargs["filter"] = filter + if max_children != NOT_SET: + kwargs["max_children"] = max_children + if nested != NOT_SET: + kwargs["nested"] = nested + if path != NOT_SET: + kwargs["path"] = str(path) + super().__init__(kwargs) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 4fa6f105..b5fb307e 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -23,6 +23,7 @@ Any, Callable, ClassVar, + Dict, List, Literal, Mapping, @@ -302,12 +303,12 @@ class Boosting(Query): Returns documents matching a `positive` query while reducing the relevance score of documents that also match a `negative` query. - :arg negative: Query used to decrease the relevance score of matching - documents. - :arg positive: Any returned documents must match this query. - :arg negative_boost: Floating point number between 0 and 1.0 used to - decrease the relevance scores of documents matching the `negative` - query. + :arg negative: (required)Query used to decrease the relevance score of + matching documents. + :arg positive: (required)Any returned documents must match this query. + :arg negative_boost: (required)Floating point number between 0 and 1.0 + used to decrease the relevance scores of documents matching the + `negative` query. """ name = "boosting" @@ -317,7 +318,12 @@ class Boosting(Query): } def __init__( - self, *, negative: Query, positive: Query, negative_boost: float, **kwargs: Any + self, + *, + negative: Union[Query, "NotSet"] = NOT_SET, + positive: Union[Query, "NotSet"] = NOT_SET, + negative_boost: Union[float, "NotSet"] = NOT_SET, + **kwargs: Any, ): super().__init__( negative=negative, @@ -353,12 +359,12 @@ class CombinedFields(Query): The `combined_fields` query supports searching multiple text fields as if their contents had been indexed into one combined field. - :arg query: Text to search for in the provided `fields`. The + :arg query: (required)Text to search for in the provided `fields`. The `combined_fields` query analyzes the provided text before performing a search. - :arg fields: List of fields to search. Field wildcard patterns are - allowed. Only `text` fields are supported, and they must all have - the same search `analyzer`. + :arg fields: (required)List of fields to search. Field wildcard + patterns are allowed. Only `text` fields are supported, and they + must all have the same search `analyzer`. :arg auto_generate_synonyms_phrase_query: If true, match phrase queries are automatically created for multi-term synonyms. :arg operator: Boolean logic used to interpret text in the query @@ -375,8 +381,8 @@ class CombinedFields(Query): def __init__( self, *, - query: str, - fields: List[Union[str, "InstrumentedField"]], + query: Union[str, "NotSet"] = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, operator: Union[Literal["or", "and"], "NotSet"] = NOT_SET, minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, @@ -399,10 +405,10 @@ class ConstantScore(Query): Wraps a filter query and returns every matching document with a relevance score equal to the `boost` parameter value. - :arg filter: Filter query you wish to run. Any returned documents must - match this query. Filter queries do not calculate relevance - scores. To speed up performance, Elasticsearch automatically - caches frequently used filter queries. + :arg filter: (required)Filter query you wish to run. Any returned + documents must match this query. Filter queries do not calculate + relevance scores. To speed up performance, Elasticsearch + automatically caches frequently used filter queries. """ name = "constant_score" @@ -410,7 +416,7 @@ class ConstantScore(Query): "filter": {"type": "query"}, } - def __init__(self, *, filter: Query, **kwargs: Any): + def __init__(self, *, filter: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): super().__init__(filter=filter, **kwargs) @@ -422,20 +428,23 @@ class DisMax(Query): relevance score from any matching clause, plus a tie breaking increment for any additional matching subqueries. - :arg queries: One or more query clauses. Returned documents must match - one or more of these queries. If a document matches multiple - queries, Elasticsearch uses the highest relevance score. + :arg queries: (required)One or more query clauses. Returned documents + must match one or more of these queries. If a document matches + multiple queries, Elasticsearch uses the highest relevance score. :arg tie_breaker: Floating point number between 0 and 1.0 used to increase the relevance scores of documents matching multiple query clauses. """ name = "dis_max" + _param_defs = { + "queries": {"type": "query", "multi": True}, + } def __init__( self, *, - queries: List[Query], + queries: Union[List[Query], "NotSet"] = NOT_SET, tie_breaker: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): @@ -447,11 +456,28 @@ class DistanceFeature(Query): Boosts the relevance score of documents closer to a provided origin date or point. For example, you can use this query to give more weight to documents closer to a certain date or location. + + :arg untyped: An instance of ``UntypedDistanceFeatureQuery``. + :arg geo: An instance of ``GeoDistanceFeatureQuery``. + :arg date: An instance of ``DateDistanceFeatureQuery``. """ name = "distance_feature" - def __init__(self, **kwargs: Any): + def __init__( + self, + *, + untyped: Union["i.UntypedDistanceFeatureQuery", "NotSet"] = NOT_SET, + geo: Union["i.GeoDistanceFeatureQuery", "NotSet"] = NOT_SET, + date: Union["i.DateDistanceFeatureQuery", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if untyped != NOT_SET: + kwargs = untyped + elif geo != NOT_SET: + kwargs = geo + elif date != NOT_SET: + kwargs = date super().__init__(**kwargs) @@ -459,12 +485,17 @@ class Exists(Query): """ Returns documents that contain an indexed value for a field. - :arg field: Name of the field you wish to search. + :arg field: (required)Name of the field you wish to search. """ name = "exists" - def __init__(self, *, field: Union[str, "InstrumentedField"], **kwargs: Any): + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(field=field, **kwargs) @@ -489,6 +520,8 @@ class FunctionScore(Query): name = "function_score" _param_defs = { "query": {"type": "query"}, + "filter": {"type": "query"}, + "functions": {"type": "score_function", "multi": True}, } def __init__( @@ -497,7 +530,9 @@ def __init__( boost_mode: Union[ Literal["multiply", "replace", "sum", "avg", "max", "min"], "NotSet" ] = NOT_SET, - functions: Union[List["i.FunctionScoreContainer"], "NotSet"] = NOT_SET, + functions: Union[ + List["i.FunctionScoreContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, max_boost: Union[float, "NotSet"] = NOT_SET, min_score: Union[float, "NotSet"] = NOT_SET, query: Union[Query, "NotSet"] = NOT_SET, @@ -506,7 +541,7 @@ def __init__( ] = NOT_SET, **kwargs: Any, ): - if functions is None: + if functions == NOT_SET: functions = [] for name in ScoreFunction._classes: if name in kwargs: @@ -548,7 +583,7 @@ class GeoBoundingBox(Query): """ Matches geo_point and geo_shape values that intersect a bounding box. - :arg type: None + :arg type: No documentation available. :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude. Set to `COERCE` to also try to infer correct latitude or longitude. @@ -582,9 +617,9 @@ class GeoDistance(Query): Matches `geo_point` and `geo_shape` values within a given distance of a geopoint. - :arg distance: The radius of the circle centred on the specified - location. Points which fall into this circle are considered to be - matches. + :arg distance: (required)The radius of the circle centred on the + specified location. Points which fall into this circle are + considered to be matches. :arg distance_type: How to compute the distance. Set to `plane` for a faster calculation that's inaccurate on long distances and close to the poles. @@ -601,7 +636,7 @@ class GeoDistance(Query): def __init__( self, *, - distance: str, + distance: Union[str, "NotSet"] = NOT_SET, distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, validation_method: Union[ Literal["coerce", "ignore_malformed", "strict"], "NotSet" @@ -622,8 +657,8 @@ class GeoPolygon(Query): """ No documentation available. - :arg validation_method: None - :arg ignore_unmapped: None + :arg validation_method: No documentation available. + :arg ignore_unmapped: No documentation available. """ name = "geo_polygon" @@ -667,10 +702,11 @@ class HasChild(Query): Returns parent documents whose joined child documents match a provided query. - :arg query: Query you wish to run on child documents of the `type` - field. If a child document matches the search, the query returns - the parent document. - :arg type: Name of the child relationship mapped for the `join` field. + :arg query: (required)Query you wish to run on child documents of the + `type` field. If a child document matches the search, the query + returns the parent document. + :arg type: (required)Name of the child relationship mapped for the + `join` field. :arg ignore_unmapped: Indicates whether to ignore an unmapped `type` and not return any documents instead of an error. :arg inner_hits: If defined, each search hit will contain inner hits. @@ -694,10 +730,10 @@ class HasChild(Query): def __init__( self, *, - query: Query, - type: str, + query: Union[Query, "NotSet"] = NOT_SET, + type: Union[str, "NotSet"] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, max_children: Union[int, "NotSet"] = NOT_SET, min_children: Union[int, "NotSet"] = NOT_SET, score_mode: Union[ @@ -722,9 +758,9 @@ class HasParent(Query): Returns child documents whose joined parent document matches a provided query. - :arg parent_type: Name of the parent relationship mapped for the - `join` field. - :arg query: Query you wish to run on parent documents of the + :arg parent_type: (required)Name of the parent relationship mapped for + the `join` field. + :arg query: (required)Query you wish to run on parent documents of the `parent_type` field. If a parent document matches the search, the query returns its child documents. :arg ignore_unmapped: Indicates whether to ignore an unmapped @@ -744,10 +780,10 @@ class HasParent(Query): def __init__( self, *, - parent_type: str, - query: Query, + parent_type: Union[str, "NotSet"] = NOT_SET, + query: Union[Query, "NotSet"] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, score: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): @@ -804,7 +840,7 @@ class Knn(Query): similarity metric. knn query finds nearest vectors through approximate search on indexed dense_vectors. - :arg field: The name of the vector field to search against + :arg field: (required)The name of the vector field to search against :arg query_vector: The query vector :arg query_vector_builder: The query vector builder. You must provide a query_vector_builder or query_vector, but not both. @@ -824,9 +860,11 @@ class Knn(Query): def __init__( self, *, - field: Union[str, "InstrumentedField"], + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, query_vector: Union[List[float], "NotSet"] = NOT_SET, - query_vector_builder: Union["i.QueryVectorBuilder", "NotSet"] = NOT_SET, + query_vector_builder: Union[ + "i.QueryVectorBuilder", Dict[str, Any], "NotSet" + ] = NOT_SET, num_candidates: Union[int, "NotSet"] = NOT_SET, k: Union[int, "NotSet"] = NOT_SET, filter: Union[Query, List[Query], "NotSet"] = NOT_SET, @@ -989,8 +1027,8 @@ class MoreLikeThis(Query): """ Returns documents that are "like" a given set of documents. - :arg like: Specifies free form text and/or a single or multiple - documents for which you want to find similar documents. + :arg like: (required)Specifies free form text and/or a single or + multiple documents for which you want to find similar documents. :arg analyzer: The analyzer that is used to analyze the free form text. Defaults to the analyzer associated with the first field in fields. @@ -1020,13 +1058,13 @@ class MoreLikeThis(Query): are ignored from the input document. :arg min_word_length: The minimum word length below which the terms are ignored. - :arg routing: None + :arg routing: No documentation available. :arg stop_words: An array of stop words. Any word in this set is ignored. :arg unlike: Used in combination with `like` to exclude documents that match a set of terms. - :arg version: None - :arg version_type: None + :arg version: No documentation available. + :arg version_type: No documentation available. """ name = "more_like_this" @@ -1034,7 +1072,12 @@ class MoreLikeThis(Query): def __init__( self, *, - like: Union[Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]]], + like: Union[ + Union[str, "i.LikeDocument"], + List[Union[str, "i.LikeDocument"]], + Dict[str, Any], + "NotSet", + ] = NOT_SET, analyzer: Union[str, "NotSet"] = NOT_SET, boost_terms: Union[float, "NotSet"] = NOT_SET, fail_on_unsupported_field: Union[bool, "NotSet"] = NOT_SET, @@ -1050,7 +1093,10 @@ def __init__( routing: Union[str, "NotSet"] = NOT_SET, stop_words: Union[str, List[str], "NotSet"] = NOT_SET, unlike: Union[ - Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], "NotSet" + Union[str, "i.LikeDocument"], + List[Union[str, "i.LikeDocument"]], + Dict[str, Any], + "NotSet", ] = NOT_SET, version: Union[int, "NotSet"] = NOT_SET, version_type: Union[ @@ -1087,13 +1133,13 @@ class MultiMatch(Query): value across multiple fields. The provided text is analyzed before matching. - :arg query: Text, number, boolean value or date you wish to find in - the provided field. + :arg query: (required)Text, number, boolean value or date you wish to + find in the provided field. :arg analyzer: Analyzer used to convert the text in the query value into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. - :arg cutoff_frequency: None + :arg cutoff_frequency: No documentation available. :arg fields: The fields to be queried. Defaults to the `index.query.default_field` index settings, which in turn defaults to `*`. @@ -1128,7 +1174,7 @@ class MultiMatch(Query): def __init__( self, *, - query: str, + query: Union[str, "NotSet"] = NOT_SET, analyzer: Union[str, "NotSet"] = NOT_SET, auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, cutoff_frequency: Union[float, "NotSet"] = NOT_SET, @@ -1188,8 +1234,9 @@ class Nested(Query): Wraps another query to search nested fields. If an object matches the search, the nested query returns the root parent document. - :arg path: Path to the nested object you wish to search. - :arg query: Query you wish to run on nested objects in the path. + :arg path: (required)Path to the nested object you wish to search. + :arg query: (required)Query you wish to run on nested objects in the + path. :arg ignore_unmapped: Indicates whether to ignore an unmapped path and not return any documents instead of an error. :arg inner_hits: If defined, each search hit will contain inner hits. @@ -1205,10 +1252,10 @@ class Nested(Query): def __init__( self, *, - path: Union[str, "InstrumentedField"], - query: Query, + path: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + query: Union[Query, "NotSet"] = NOT_SET, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", "NotSet"] = NOT_SET, + inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, score_mode: Union[ Literal["none", "avg", "sum", "max", "min"], "NotSet" ] = NOT_SET, @@ -1251,8 +1298,8 @@ class Percolate(Query): """ Matches queries stored in an index. - :arg field: Field that holds the indexed queries. The field must use - the `percolator` mapping type. + :arg field: (required)Field that holds the indexed queries. The field + must use the `percolator` mapping type. :arg document: The source of the document being percolated. :arg documents: An array of sources of the documents being percolated. :arg id: The ID of a stored document to percolate. @@ -1269,7 +1316,7 @@ class Percolate(Query): def __init__( self, *, - field: Union[str, "InstrumentedField"], + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, document: Any = NOT_SET, documents: Union[List[Any], "NotSet"] = NOT_SET, id: Union[str, "NotSet"] = NOT_SET, @@ -1299,8 +1346,8 @@ class Pinned(Query): Promotes selected documents to rank higher than those matching a given query. - :arg organic: Any choice of query used to rank documents which will be - ranked below the "pinned" documents. + :arg organic: (required)Any choice of query used to rank documents + which will be ranked below the "pinned" documents. :arg ids: Document IDs listed in the order they are to appear in results. Required if `docs` is not specified. :arg docs: Documents listed in the order they are to appear in @@ -1315,9 +1362,9 @@ class Pinned(Query): def __init__( self, *, - organic: Query, + organic: Union[Query, "NotSet"] = NOT_SET, ids: Union[List[str], "NotSet"] = NOT_SET, - docs: Union[List["i.PinnedDoc"], "NotSet"] = NOT_SET, + docs: Union[List["i.PinnedDoc"], Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): super().__init__(organic=organic, ids=ids, docs=docs, **kwargs) @@ -1349,7 +1396,8 @@ class QueryString(Query): Returns documents based on a provided query string, using a parser with a strict syntax. - :arg query: Query string you wish to parse and use for search. + :arg query: (required)Query string you wish to parse and use for + search. :arg allow_leading_wildcard: If `true`, the wildcard characters `*` and `?` are allowed as the first character of the query string. :arg analyzer: Analyzer used to convert text in the query string into @@ -1366,7 +1414,7 @@ class QueryString(Query): the query string if no operators are specified. :arg enable_position_increments: If `true`, enable position increments in queries constructed from a `query_string` search. - :arg escape: None + :arg escape: No documentation available. :arg fields: Array of fields to search. Supports wildcards (`*`). :arg fuzziness: Maximum edit distance allowed for fuzzy matching. :arg fuzzy_max_expansions: Maximum number of terms to which the query @@ -1404,7 +1452,7 @@ class QueryString(Query): def __init__( self, *, - query: str, + query: Union[str, "NotSet"] = NOT_SET, allow_leading_wildcard: Union[bool, "NotSet"] = NOT_SET, analyzer: Union[str, "NotSet"] = NOT_SET, analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, @@ -1503,8 +1551,8 @@ class RankFeature(Query): Boosts the relevance score of documents based on the numeric value of a `rank_feature` or `rank_features` field. - :arg field: `rank_feature` or `rank_features` field used to boost - relevance scores. + :arg field: (required)`rank_feature` or `rank_features` field used to + boost relevance scores. :arg saturation: Saturation function used to boost relevance scores based on the value of the rank feature `field`. :arg log: Logarithmic function used to boost relevance scores based on @@ -1520,11 +1568,19 @@ class RankFeature(Query): def __init__( self, *, - field: Union[str, "InstrumentedField"], - saturation: Union["i.RankFeatureFunctionSaturation", "NotSet"] = NOT_SET, - log: Union["i.RankFeatureFunctionLogarithm", "NotSet"] = NOT_SET, - linear: Union["i.RankFeatureFunctionLinear", "NotSet"] = NOT_SET, - sigmoid: Union["i.RankFeatureFunctionSigmoid", "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + saturation: Union[ + "i.RankFeatureFunctionSaturation", Dict[str, Any], "NotSet" + ] = NOT_SET, + log: Union[ + "i.RankFeatureFunctionLogarithm", Dict[str, Any], "NotSet" + ] = NOT_SET, + linear: Union[ + "i.RankFeatureFunctionLinear", Dict[str, Any], "NotSet" + ] = NOT_SET, + sigmoid: Union[ + "i.RankFeatureFunctionSigmoid", Dict[str, Any], "NotSet" + ] = NOT_SET, **kwargs: Any, ): super().__init__( @@ -1562,9 +1618,9 @@ class Rule(Query): """ No documentation available. - :arg ruleset_ids: None - :arg match_criteria: None - :arg organic: None + :arg ruleset_ids: (required)No documentation available. + :arg match_criteria: (required)No documentation available. + :arg organic: (required)No documentation available. """ name = "rule" @@ -1575,9 +1631,9 @@ class Rule(Query): def __init__( self, *, - ruleset_ids: List[str], - match_criteria: Any, - organic: Query, + ruleset_ids: Union[List[str], "NotSet"] = NOT_SET, + match_criteria: Any = NOT_SET, + organic: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any, ): super().__init__( @@ -1593,13 +1649,18 @@ class Script(Query): Filters documents based on a provided script. The script query is typically used in a filter context. - :arg script: Contains a script to run as a query. This script must - return a boolean value, `true` or `false`. + :arg script: (required)Contains a script to run as a query. This + script must return a boolean value, `true` or `false`. """ name = "script" - def __init__(self, *, script: "i.Script", **kwargs: Any): + def __init__( + self, + *, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(script=script, **kwargs) @@ -1607,9 +1668,9 @@ class ScriptScore(Query): """ Uses a script to provide a custom score for returned documents. - :arg query: Query used to return documents. - :arg script: Script used to compute the score of documents returned by - the query. Important: final relevance scores from the + :arg query: (required)Query used to return documents. + :arg script: (required)Script used to compute the score of documents + returned by the query. Important: final relevance scores from the `script_score` query cannot be negative. :arg min_score: Documents with a score lower than this floating point number are excluded from the search results. @@ -1623,8 +1684,8 @@ class ScriptScore(Query): def __init__( self, *, - query: Query, - script: "i.Script", + query: Union[Query, "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, min_score: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): @@ -1635,14 +1696,20 @@ class Semantic(Query): """ A semantic query to semantic_text field types - :arg query: The query text - :arg field: The field to query, which must be a semantic_text field - type + :arg query: (required)The query text + :arg field: (required)The field to query, which must be a + semantic_text field type """ name = "semantic" - def __init__(self, *, query: str, field: str, **kwargs: Any): + def __init__( + self, + *, + query: Union[str, "NotSet"] = NOT_SET, + field: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(query=query, field=field, **kwargs) @@ -1667,8 +1734,8 @@ class SimpleQueryString(Query): Returns documents based on a provided query string, using a parser with a limited but fault-tolerant syntax. - :arg query: Query string in the simple query string syntax you wish to - parse and use for search. + :arg query: (required)Query string in the simple query string syntax + you wish to parse and use for search. :arg analyzer: Analyzer used to convert text in the query string into tokens. :arg analyze_wildcard: If `true`, the query attempts to analyze @@ -1704,13 +1771,13 @@ class SimpleQueryString(Query): def __init__( self, *, - query: str, + query: Union[str, "NotSet"] = NOT_SET, analyzer: Union[str, "NotSet"] = NOT_SET, analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - flags: Union["i.PipeSeparatedFlags", "NotSet"] = NOT_SET, + flags: Union["i.PipeSeparatedFlags", Dict[str, Any], "NotSet"] = NOT_SET, fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, @@ -1741,15 +1808,21 @@ class SpanContaining(Query): """ Returns matches which enclose another span query. - :arg little: Can be any span query. Matching spans from `big` that - contain matches from `little` are returned. - :arg big: Can be any span query. Matching spans from `big` that - contain matches from `little` are returned. + :arg little: (required)Can be any span query. Matching spans from + `big` that contain matches from `little` are returned. + :arg big: (required)Can be any span query. Matching spans from `big` + that contain matches from `little` are returned. """ name = "span_containing" - def __init__(self, *, little: "i.SpanQuery", big: "i.SpanQuery", **kwargs: Any): + def __init__( + self, + *, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(little=little, big=big, **kwargs) @@ -1758,8 +1831,8 @@ class SpanFieldMasking(Query): Wrapper to allow span queries to participate in composite single-field span queries by _lying_ about their search field. - :arg query: None - :arg field: None + :arg query: (required)No documentation available. + :arg field: (required)No documentation available. """ name = "span_field_masking" @@ -1767,8 +1840,8 @@ class SpanFieldMasking(Query): def __init__( self, *, - query: "i.SpanQuery", - field: Union[str, "InstrumentedField"], + query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): super().__init__(query=query, field=field, **kwargs) @@ -1778,13 +1851,20 @@ class SpanFirst(Query): """ Matches spans near the beginning of a field. - :arg match: Can be any other span type query. - :arg end: Controls the maximum end position permitted in a match. + :arg match: (required)Can be any other span type query. + :arg end: (required)Controls the maximum end position permitted in a + match. """ name = "span_first" - def __init__(self, *, match: "i.SpanQuery", end: int, **kwargs: Any): + def __init__( + self, + *, + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + end: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(match=match, end=end, **kwargs) @@ -1794,8 +1874,8 @@ class SpanMulti(Query): `prefix`, `range`, or `regexp` query) as a `span` query, so it can be nested. - :arg match: Should be a multi term query (one of `wildcard`, `fuzzy`, - `prefix`, `range`, or `regexp` query). + :arg match: (required)Should be a multi term query (one of `wildcard`, + `fuzzy`, `prefix`, `range`, or `regexp` query). """ name = "span_multi" @@ -1803,7 +1883,7 @@ class SpanMulti(Query): "match": {"type": "query"}, } - def __init__(self, *, match: Query, **kwargs: Any): + def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): super().__init__(match=match, **kwargs) @@ -1813,7 +1893,7 @@ class SpanNear(Query): maximum number of intervening unmatched positions, as well as whether matches are required to be in-order. - :arg clauses: Array of one or more other span type queries. + :arg clauses: (required)Array of one or more other span type queries. :arg in_order: Controls whether matches are required to be in-order. :arg slop: Controls the maximum number of intervening unmatched positions permitted. @@ -1824,7 +1904,7 @@ class SpanNear(Query): def __init__( self, *, - clauses: List["i.SpanQuery"], + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, in_order: Union[bool, "NotSet"] = NOT_SET, slop: Union[int, "NotSet"] = NOT_SET, **kwargs: Any, @@ -1838,9 +1918,9 @@ class SpanNot(Query): within x tokens before (controlled by the parameter `pre`) or y tokens after (controlled by the parameter `post`) another span query. - :arg exclude: Span query whose matches must not overlap those - returned. - :arg include: Span query whose matches are filtered. + :arg exclude: (required)Span query whose matches must not overlap + those returned. + :arg include: (required)Span query whose matches are filtered. :arg dist: The number of tokens from within the include span that can’t have overlap with the exclude span. Equivalent to setting both `pre` and `post`. @@ -1855,8 +1935,8 @@ class SpanNot(Query): def __init__( self, *, - exclude: "i.SpanQuery", - include: "i.SpanQuery", + exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, dist: Union[int, "NotSet"] = NOT_SET, post: Union[int, "NotSet"] = NOT_SET, pre: Union[int, "NotSet"] = NOT_SET, @@ -1871,12 +1951,17 @@ class SpanOr(Query): """ Matches the union of its span clauses. - :arg clauses: Array of one or more other span type queries. + :arg clauses: (required)Array of one or more other span type queries. """ name = "span_or" - def __init__(self, *, clauses: List["i.SpanQuery"], **kwargs: Any): + def __init__( + self, + *, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(clauses=clauses, **kwargs) @@ -1905,15 +1990,21 @@ class SpanWithin(Query): """ Returns matches which are enclosed inside another span query. - :arg little: Can be any span query. Matching spans from `little` that - are enclosed within `big` are returned. - :arg big: Can be any span query. Matching spans from `little` that are - enclosed within `big` are returned. + :arg little: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg big: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. """ name = "span_within" - def __init__(self, *, little: "i.SpanQuery", big: "i.SpanQuery", **kwargs: Any): + def __init__( + self, + *, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): super().__init__(little=little, big=big, **kwargs) @@ -1923,9 +2014,9 @@ class SparseVector(Query): convert a query into a list of token-weight pairs, queries against a sparse vector field. - :arg field: The name of the field that contains the token-weight pairs - to be searched against. This field must be a mapped sparse_vector - field. + :arg field: (required)The name of the field that contains the token- + weight pairs to be searched against. This field must be a mapped + sparse_vector field. :arg query_vector: Dictionary of precomputed sparse vectors and their associated weights. Only one of inference_id or query_vector may be supplied in a request. @@ -1953,12 +2044,14 @@ class SparseVector(Query): def __init__( self, *, - field: Union[str, "InstrumentedField"], + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, query_vector: Union[Mapping[str, float], "NotSet"] = NOT_SET, inference_id: Union[str, "NotSet"] = NOT_SET, query: Union[str, "NotSet"] = NOT_SET, prune: Union[bool, "NotSet"] = NOT_SET, - pruning_config: Union["i.TokenPruningConfig", "NotSet"] = NOT_SET, + pruning_config: Union[ + "i.TokenPruningConfig", Dict[str, Any], "NotSet" + ] = NOT_SET, **kwargs: Any, ): super().__init__( @@ -2108,13 +2201,13 @@ class Wrapper(Query): """ A query that accepts any other query as base64 encoded string. - :arg query: A base64 encoded query. The binary data format can be any - of JSON, YAML, CBOR or SMILE encodings + :arg query: (required)A base64 encoded query. The binary data format + can be any of JSON, YAML, CBOR or SMILE encodings """ name = "wrapper" - def __init__(self, *, query: str, **kwargs: Any): + def __init__(self, *, query: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): super().__init__(query=query, **kwargs) @@ -2122,10 +2215,10 @@ class Type(Query): """ No documentation available. - :arg value: None + :arg value: (required)No documentation available. """ name = "type" - def __init__(self, *, value: str, **kwargs: Any): + def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): super().__init__(value=value, **kwargs) diff --git a/utils/generator.py b/utils/generator.py index 98439a6e..9fa48ed5 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -46,6 +46,15 @@ def wrapped_doc(text, width=70, initial_indent="", subsequent_indent=""): ) +def add_dict_type(type_): + """Add Dict[str, Any] to a Python type hint.""" + if type_.startswith("Union["): + type_ = f"{type_[:-1]}, Dict[str, Any]]" + else: + type_ = f"Union[{type_}, Dict[str, Any]]" + return type_ + + def add_not_set(type_): """Add NotSet to a Python type hint.""" if type_.startswith("Union["): @@ -118,7 +127,7 @@ def get_python_type(self, schema_type): elif schema_type["kind"] == "array_of": type_, param = self.get_python_type(schema_type["value"]) - return f"List[{type_}]", None + return f"List[{type_}]", {**param, "multi": True} if param else None elif schema_type["kind"] == "dictionary_of": key_type, key_param = self.get_python_type(schema_type["key"]) @@ -164,11 +173,11 @@ def get_python_type(self, schema_type): if schema_type["name"]["name"].endswith("RangeQuery"): return '"wrappers.Range"', None elif schema_type["name"]["name"].endswith("Function"): - return f"\"function.{schema_type['name']['name']}\"", None + return f"\"f.{schema_type['name']['name']}\"", None elif schema_type["name"]["namespace"] == "_types.analysis" and schema_type[ "name" ]["name"].endswith("Analyzer"): - return f"\"analysis.{schema_type['name']['name']}\"", None + return f"\"a.{schema_type['name']['name']}\"", None self.interfaces.add(schema_type["name"]["name"]) return f"\"i.{schema_type['name']['name']}\"", None elif schema_type["kind"] == "user_defined_value": @@ -176,108 +185,129 @@ def get_python_type(self, schema_type): raise RuntimeError(f"Cannot find Python type for {schema_type}") - -def generate_query_classes(schema, filename): - classes = [] - query_container = schema.find_type("QueryContainer", "_types.query_dsl") - for p in query_container["properties"]: - k = {"schema": p, "name": "".join([w.title() for w in p["name"].split("_")])} - k["docstring"] = wrapped_doc(p.get("description")) - kind = p["type"]["kind"] - if kind == "instance_of": - instance = schema.find_type( - p["type"]["type"]["name"], p["type"]["type"]["namespace"] - ) - if instance["kind"] == "interface": - k["kwargs"] = [] - k["params"] = [] - for arg in instance["properties"]: - type_, param = schema.get_python_type(arg["type"]) - if arg["required"] is False and type_ != "Any": - type_ = add_not_set(type_) - doc = wrapped_doc( - f":arg {arg['name']}: {arg.get('description')}", - subsequent_indent=" ", - ) - if arg["required"] is False: - k["kwargs"].append( - { - "name": RESERVED.get(arg["name"], arg["name"]), - "type": type_, - "doc": doc, - "required": False, - } - ) - else: - i = 0 - for i in range(len(k["kwargs"])): - if k["kwargs"][i]["required"] is False: - break - k["kwargs"].insert( - i, - { - "name": RESERVED.get(arg["name"], arg["name"]), - "type": type_, - "doc": doc, - "required": True, - }, - ) - if param is not None: - k["params"].append({"name": arg["name"], "param": param}) - - elif kind == "dictionary_of": - key_type, _ = schema.get_python_type(p["type"]["key"]) - if "InstrumentedField" in key_type: - value_type, _ = schema.get_python_type(p["type"]["value"]) - if p["type"]["singleKey"]: - k["kwargs"] = [ - { - "name": "_field", - "type": add_not_set(key_type), - "doc": [":arg _field: The field to use in this query."], - "required": False, - }, - { - "name": "_value", - "type": add_not_set(value_type), - "doc": [":arg _value: The query value for the field."], - "required": False, - }, - ] - k["has_field"] = True + def argument_to_python_type(self, arg): + try: + type_, param = schema.get_python_type(arg["type"]) + except RuntimeError: + type_ = "Any" + param = None + if type_ != "Any": + if "i." in type_: + type_ = add_dict_type(type_) + type_ = add_not_set(type_) + required = "(required)" if arg["required"] else "" + doc = wrapped_doc( + f":arg {arg['name']}: {required}{arg.get('description', 'No documentation available.')}", + subsequent_indent=" ", + ) + kwarg = { + "name": RESERVED.get(arg["name"], arg["name"]), + "type": type_, + "doc": doc, + "required": arg["required"], + } + if param is not None: + param = {"name": arg["name"], "param": param} + return kwarg, param + + def instance_of_to_python_class(self, p, k): + instance = schema.find_type( + p["type"]["type"]["name"], p["type"]["type"]["namespace"] + ) + if instance["kind"] == "interface": + k["kwargs"] = [] + k["params"] = [] + for p in instance["properties"]: + kwarg, param = self.argument_to_python_type(p) + if kwarg["required"]: + i = 0 + for i in range(len(k["kwargs"])): + if k["kwargs"][i]["required"] is False: + break + k["kwargs"].insert(i, kwarg) else: - k["kwargs"] = [ + k["kwargs"].append(kwarg) + if param: + k["params"].append(param) + elif instance["kind"] == "type_alias": + if ( + "codegenNames" in instance + and instance["type"]["kind"] == "union_of" + and len(instance["type"]["items"]) == len(instance["codegenNames"]) + ): + k["kwargs"] = [] + for name, type_ in zip( + instance["codegenNames"], instance["type"]["items"] + ): + python_type, _ = self.get_python_type(type_) + k["kwargs"].append( { - "name": "_fields", - "type": f"Optional[Mapping[{key_type}, {value_type}]]", + "name": name, + "type": f'Union[{python_type}, "NotSet"]', "doc": [ - ":arg _fields: A dictionary of fields with their values." + f":arg {name}: An instance of ``{python_type[3:-1]}``." ], "required": False, - }, - ] - k["has_fields"] = True + } + ) + k["has_type_alias"] = True else: - raise RuntimeError(f"Cannot generate code for type {p['type']}") - + raise RuntimeError("Cannot generate code for non-enum type aliases") else: - raise RuntimeError(f"Cannot generate code for type {p['type']}") - classes.append(k) - - with open(filename, "wt") as f: - f.write( - query_py.render( - classes=classes, parent="Query", interfaces=sorted(schema.interfaces) + raise RuntimeError( + f"Cannot generate code for instances of kind '{instance['kind']}'" ) - ) - print(f"Generated {filename}.") + return k + + def dictionary_of_to_python_class(self, p, k): + key_type, _ = schema.get_python_type(p["type"]["key"]) + if "InstrumentedField" in key_type: + value_type, _ = schema.get_python_type(p["type"]["value"]) + if p["type"]["singleKey"]: + k["kwargs"] = [ + { + "name": "_field", + "type": add_not_set(key_type), + "doc": [":arg _field: The field to use in this query."], + "required": False, + }, + { + "name": "_value", + "type": add_not_set(value_type), + "doc": [":arg _value: The query value for the field."], + "required": False, + }, + ] + k["has_field"] = True + else: + k["kwargs"] = [ + { + "name": "_fields", + "type": f"Optional[Mapping[{key_type}, {value_type}]]", + "doc": [ + ":arg _fields: A dictionary of fields with their values." + ], + "required": False, + }, + ] + k["has_fields"] = True + else: + raise RuntimeError(f"Cannot generate code for type {p['type']}") + return k + def property_to_python_class(self, p): + k = {"schema": p, "name": "".join([w.title() for w in p["name"].split("_")])} + k["docstring"] = wrapped_doc(p.get("description")) + kind = p["type"]["kind"] + if kind == "instance_of": + k = self.instance_of_to_python_class(p, k) + elif kind == "dictionary_of": + k = self.dictionary_of_to_python_class(p, k) + else: + raise RuntimeError(f"Cannot generate code for type {p['type']}") + return k -def generate_interfaces(schema, interfaces, filename): - classes = {} - for interface in interfaces: - if interface == "PipeSeparatedFlags": - continue # handled as a special case + def interface_to_python_class(self, interface, interfaces): type_ = schema.find_type(interface) if type_["kind"] != "interface": raise RuntimeError(f"Type {interface} is not an interface") @@ -294,12 +324,35 @@ def generate_interfaces(schema, interfaces, filename): else: parent = None k = {"name": interface, "parent": parent, "properties": []} - schema.reset_interfaces() - for p in type_["properties"]: - type_, param = schema.get_python_type(p["type"]) - k["properties"].append( - {"name": RESERVED.get(p["name"], p["name"]), "type": type_} + for arg in type_["properties"]: + arg_type, _ = schema.argument_to_python_type(arg) + k["properties"].append(arg_type) + return k + + +def generate_query_classes(schema, filename): + classes = [] + query_container = schema.find_type("QueryContainer", "_types.query_dsl") + for p in query_container["properties"]: + k = schema.property_to_python_class(p) + classes.append(k) + + with open(filename, "wt") as f: + f.write( + query_py.render( + classes=classes, parent="Query", interfaces=sorted(schema.interfaces) ) + ) + print(f"Generated {filename}.") + + +def generate_interfaces(schema, interfaces, filename): + classes = {} + for interface in interfaces: + if interface == "PipeSeparatedFlags": + continue # handled as a special case + schema.reset_interfaces() + k = schema.interface_to_python_class(interface, interfaces) for new_interface in schema.interfaces: if new_interface not in interfaces: interfaces.append(new_interface) diff --git a/utils/templates/dsl_classes.tpl b/utils/templates/dsl_classes.tpl index 44af7c4a..7339e471 100644 --- a/utils/templates/dsl_classes.tpl +++ b/utils/templates/dsl_classes.tpl @@ -19,6 +19,10 @@ class {{ k.name }}({{ parent }}): {% for param in k.params %} "{{ param.name }}": {{ param.param }}, {% endfor %} + {% if k.name == "FunctionScore" %} + "filter": {"type": "query"}, + "functions": {"type": "score_function", "multi": True}, + {% endif %} } {% endif %} @@ -28,12 +32,12 @@ class {{ k.name }}({{ parent }}): *, {% endif %} {% for kwarg in k.kwargs %} - {{ kwarg.name }}: {{ kwarg.type }}{% if not kwarg.required %} = NOT_SET{% endif %}, + {{ kwarg.name }}: {{ kwarg.type }} = NOT_SET, {% endfor %} **kwargs: Any ): {% if k.name == "FunctionScore" %} - if functions is None: + if functions == NOT_SET: functions = [] for name in ScoreFunction._classes: if name in kwargs: @@ -45,9 +49,18 @@ class {{ k.name }}({{ parent }}): if fields != NOT_SET: for field, value in _fields.items(): kwargs[str(field)] = value + {% elif k.has_type_alias %} + {% for kwarg in k.kwargs %} + {% if loop.index == 1 %} + if {{ kwarg.name }} != NOT_SET: + {% else %} + elif {{ kwarg.name }} != NOT_SET: + {% endif %} + kwargs = {{ kwarg.name }} + {% endfor %} {% endif %} super().__init__( - {% if not k.has_field and not k.has_fields %} + {% if not k.has_field and not k.has_fields and not k.has_type_alias %} {% for kwarg in k.kwargs %} {{ kwarg.name }}={{ kwarg.name }}, {% endfor %} diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index c68a594d..b6ee69cc 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -1,16 +1,42 @@ -from typing import Any, List, Literal, Mapping, TypedDict, Union -from elasticsearch_dsl.search_base import InstrumentedField -from elasticsearch_dsl import analysis, function, interfaces as i, Query +from typing import Any, Dict, List, Literal, Mapping, Union +from elasticsearch_dsl.document_base import InstrumentedField +from elasticsearch_dsl import analysis as a, function as f, interfaces as i, Query +from elasticsearch_dsl.utils import AttrDict, NotSet, NOT_SET PipeSeparatedFlags = str {% for k in classes %} -class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}TypedDict{% endif %}): +class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endif %}): {% if k.properties %} + """ {% for p in k.properties %} - {{ p.name }}: {{ p.type }} + {% for line in p.doc %} + {{ line }} {% endfor %} + {% endfor %} + """ + def __init__( + self, + *, + {% for p in k.properties %} + {{ p.name }}: {{ p.type }} = NOT_SET, + {% endfor %} + **kwargs: Any + ): + {% for p in k.properties %} + if {{ p.name }} != NOT_SET: + {% if "InstrumentedField" in p.type %} + kwargs["{{ p.name }}"] = str({{ p.name }}) + {% else %} + kwargs["{{ p.name }}"] = {{ p.name }} + {% endif %} + {% endfor %} + {% if k.parent %} + super().__init__(**kwargs) + {% else %} + super().__init__(kwargs) + {% endif %} {% else %} pass {% endif %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 5453db08..92557416 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -23,6 +23,7 @@ from typing import ( Any, Callable, ClassVar, + Dict, List, Literal, Mapping, From 33f2a7f68f7dd652f928a57324c4dcdb4d2ab79c Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 2 Sep 2024 17:54:02 +0100 Subject: [PATCH 06/27] address typing issues --- elasticsearch_dsl/faceted_search_base.py | 28 +- elasticsearch_dsl/function.py | 39 +- elasticsearch_dsl/interfaces.py | 2281 +++++++++++----------- elasticsearch_dsl/query.py | 96 +- tests/_async/test_search.py | 17 +- tests/_async/test_update_by_query.py | 17 +- tests/_sync/test_search.py | 17 +- tests/_sync/test_update_by_query.py | 17 +- tests/test_query.py | 2 +- utils/generator.py | 26 +- utils/templates/dsl_classes.tpl | 14 +- utils/templates/interfaces.py.tpl | 2 +- utils/templates/query.py.tpl | 3 +- 13 files changed, 1285 insertions(+), 1274 deletions(-) diff --git a/elasticsearch_dsl/faceted_search_base.py b/elasticsearch_dsl/faceted_search_base.py index b959b05a..7b370861 100644 --- a/elasticsearch_dsl/faceted_search_base.py +++ b/elasticsearch_dsl/faceted_search_base.py @@ -173,13 +173,13 @@ def __init__( def get_value_filter(self, filter_value: FilterValueType) -> Query: f, t = self._ranges[filter_value] - limits = {} + limits: Dict[str, Any] = {} if f is not None: limits["gte"] = f if t is not None: limits["lt"] = t - return Range(_expand__to_dot=False, **{self._params["field"]: limits}) + return Range(self._params["field"], limits, _expand__to_dot=False) class HistogramFacet(Facet[_R]): @@ -187,13 +187,12 @@ class HistogramFacet(Facet[_R]): def get_value_filter(self, filter_value: FilterValueType) -> Range: return Range( - _expand__to_dot=False, - **{ - self._params["field"]: { - "gte": filter_value, - "lt": filter_value + self._params["interval"], - } + self._params["field"], + { + "gte": filter_value, + "lt": filter_value + self._params["interval"], }, + _expand__to_dot=False, ) @@ -258,15 +257,12 @@ def get_value_filter(self, filter_value: Any) -> Range: interval_type = "interval" return Range( - _expand__to_dot=False, - **{ - self._params["field"]: { - "gte": filter_value, - "lt": self.DATE_INTERVALS[self._params[interval_type]]( - filter_value - ), - } + self._params["field"], + { + "gte": filter_value, + "lt": self.DATE_INTERVALS[self._params[interval_type]](filter_value), }, + _expand__to_dot=False, ) diff --git a/elasticsearch_dsl/function.py b/elasticsearch_dsl/function.py index 5da92f70..45f7c8ec 100644 --- a/elasticsearch_dsl/function.py +++ b/elasticsearch_dsl/function.py @@ -17,9 +17,18 @@ import collections.abc from copy import deepcopy -from typing import Any, ClassVar, Dict, MutableMapping, Optional, Union, overload +from typing import ( + Any, + ClassVar, + Dict, + Literal, + MutableMapping, + Optional, + Union, + overload, +) -from .utils import DslBase +from .utils import NOT_SET, AttrDict, DslBase, NotSet @overload @@ -137,3 +146,29 @@ class Gauss(ScoreFunction): class Exp(ScoreFunction): name = "exp" + + +class DecayFunction(AttrDict[Any]): + def __init__( + self, + *, + decay: Union[float, "NotSet"] = NOT_SET, + offset: Any = NOT_SET, + scale: Any = NOT_SET, + origin: Any = NOT_SET, + multi_value_mode: Union[ + Literal["min", "max", "avg", "sum"], "NotSet" + ] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(decay, NotSet): + kwargs["decay"] = decay + if not isinstance(offset, NotSet): + kwargs["offset"] = offset + if not isinstance(scale, NotSet): + kwargs["offset"] = scale + if not isinstance(origin, NotSet): + kwargs["offset"] = origin + if not isinstance(multi_value_mode, NotSet): + kwargs["offset"] = multi_value_mode + super().__init__(kwargs) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index bfb7ee2b..fbf9a757 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -18,7 +18,6 @@ from typing import Any, Dict, List, Literal, Mapping, Union from elasticsearch_dsl import Query -from elasticsearch_dsl import analysis as a from elasticsearch_dsl import function as f from elasticsearch_dsl import interfaces as i from elasticsearch_dsl.document_base import InstrumentedField @@ -27,6 +26,22 @@ PipeSeparatedFlags = str +class QueryVectorBuilder(AttrDict[Any]): + """ + :arg text_embedding: No documentation available. + """ + + def __init__( + self, + *, + text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if text_embedding != NOT_SET: + kwargs["text_embedding"] = text_embedding + super().__init__(kwargs) + + class QueryBase(AttrDict[Any]): """ :arg boost: Floating point number used to decrease or increase the @@ -51,71 +66,6 @@ def __init__( super().__init__(kwargs) -class TermQuery(QueryBase): - """ - :arg value: (required)Term you wish to find in the provided field. - :arg case_insensitive: Allows ASCII case insensitive matching of the - value with the indexed field values when set to `true`. When - `false`, the case sensitivity of matching depends on the - underlying field’s mapping. - """ - - def __init__( - self, - *, - value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if value != NOT_SET: - kwargs["value"] = value - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive - super().__init__(**kwargs) - - -class TextExpansionQuery(QueryBase): - """ - :arg model_id: (required)The text expansion NLP model to use - :arg model_text: (required)The query text - :arg pruning_config: Token pruning configurations - """ - - def __init__( - self, - *, - model_id: Union[str, "NotSet"] = NOT_SET, - model_text: Union[str, "NotSet"] = NOT_SET, - pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "NotSet" - ] = NOT_SET, - **kwargs: Any, - ): - if model_id != NOT_SET: - kwargs["model_id"] = model_id - if model_text != NOT_SET: - kwargs["model_text"] = model_text - if pruning_config != NOT_SET: - kwargs["pruning_config"] = pruning_config - super().__init__(**kwargs) - - -class QueryVectorBuilder(AttrDict[Any]): - """ - :arg text_embedding: No documentation available. - """ - - def __init__( - self, - *, - text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if text_embedding != NOT_SET: - kwargs["text_embedding"] = text_embedding - super().__init__(kwargs) - - class DistanceFeatureQueryBase(QueryBase): """ :arg origin: (required)Date or point of origin used to calculate @@ -154,105 +104,108 @@ def __init__( super().__init__(**kwargs) -class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): +class DateDistanceFeatureQuery(DistanceFeatureQueryBase): pass -class InnerHits(AttrDict[Any]): +class SpanQuery(AttrDict[Any]): """ - :arg name: The name for the particular inner hit definition in the - response. Useful when a search request contains multiple inner - hits. - :arg size: The maximum number of hits to return per `inner_hits`. - :arg from: Inner hit starting document offset. - :arg collapse: No documentation available. - :arg docvalue_fields: No documentation available. - :arg explain: No documentation available. - :arg highlight: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg script_fields: No documentation available. - :arg seq_no_primary_term: No documentation available. - :arg fields: No documentation available. - :arg sort: How the inner hits should be sorted per `inner_hits`. By - default, inner hits are sorted by score. - :arg _source: No documentation available. - :arg stored_fields: No documentation available. - :arg track_scores: No documentation available. - :arg version: No documentation available. + :arg span_containing: Accepts a list of span queries, but only returns + those spans which also match a second span query. + :arg span_field_masking: Allows queries like `span_near` or `span_or` + across different fields. + :arg span_first: Accepts another span query whose matches must appear + within the first N positions of the field. + :arg span_gap: No documentation available. + :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, + `regexp`, or `fuzzy` query. + :arg span_near: Accepts multiple span queries whose matches must be + within the specified distance of each other, and possibly in the + same order. + :arg span_not: Wraps another span query, and excludes any documents + which match that query. + :arg span_or: Combines multiple span queries and returns documents + which match any of the specified queries. + :arg span_term: The equivalent of the `term` query but for use with + other span queries. + :arg span_within: The result from a single span query is returned as + long is its span falls within the spans returned by a list of + other span queries. """ def __init__( self, *, - name: Union[str, "NotSet"] = NOT_SET, - size: Union[int, "NotSet"] = NOT_SET, - from_: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, - docvalue_fields: Union[ - List["i.FieldAndFormat"], Dict[str, Any], "NotSet" + span_containing: Union[ + "i.SpanContainingQuery", Dict[str, Any], "NotSet" ] = NOT_SET, - explain: Union[bool, "NotSet"] = NOT_SET, - highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], - Dict[str, Any], - "NotSet", + span_field_masking: Union[ + "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" ] = NOT_SET, - seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, - fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_gap: Union[ + Mapping[Union[str, "InstrumentedField"], int], "NotSet" ] = NOT_SET, - sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_term: Union[ + Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], Dict[str, Any], "NotSet", ] = NOT_SET, - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, - stored_fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - track_scores: Union[bool, "NotSet"] = NOT_SET, - version: Union[bool, "NotSet"] = NOT_SET, + span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if name != NOT_SET: - kwargs["name"] = name - if size != NOT_SET: - kwargs["size"] = size - if from_ != NOT_SET: - kwargs["from_"] = from_ - if collapse != NOT_SET: - kwargs["collapse"] = collapse - if docvalue_fields != NOT_SET: - kwargs["docvalue_fields"] = docvalue_fields - if explain != NOT_SET: - kwargs["explain"] = explain - if highlight != NOT_SET: - kwargs["highlight"] = highlight - if ignore_unmapped != NOT_SET: - kwargs["ignore_unmapped"] = ignore_unmapped - if script_fields != NOT_SET: - kwargs["script_fields"] = str(script_fields) - if seq_no_primary_term != NOT_SET: - kwargs["seq_no_primary_term"] = seq_no_primary_term - if fields != NOT_SET: - kwargs["fields"] = str(fields) - if sort != NOT_SET: - kwargs["sort"] = str(sort) - if _source != NOT_SET: - kwargs["_source"] = _source - if stored_fields != NOT_SET: - kwargs["stored_fields"] = str(stored_fields) - if track_scores != NOT_SET: - kwargs["track_scores"] = track_scores - if version != NOT_SET: - kwargs["version"] = version + if span_containing != NOT_SET: + kwargs["span_containing"] = span_containing + if span_field_masking != NOT_SET: + kwargs["span_field_masking"] = span_field_masking + if span_first != NOT_SET: + kwargs["span_first"] = span_first + if span_gap != NOT_SET: + kwargs["span_gap"] = str(span_gap) + if span_multi != NOT_SET: + kwargs["span_multi"] = span_multi + if span_near != NOT_SET: + kwargs["span_near"] = span_near + if span_not != NOT_SET: + kwargs["span_not"] = span_not + if span_or != NOT_SET: + kwargs["span_or"] = span_or + if span_term != NOT_SET: + kwargs["span_term"] = str(span_term) + if span_within != NOT_SET: + kwargs["span_within"] = span_within + super().__init__(kwargs) + + +class TokenPruningConfig(AttrDict[Any]): + """ + :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than + this threshold times the average frequency of all tokens in the + specified field are considered outliers and pruned. + :arg tokens_weight_threshold: Tokens whose weight is less than this + threshold are considered nonsignificant and pruned. + :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs + only scoring kept tokens. + """ + + def __init__( + self, + *, + tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, + tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, + only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if tokens_freq_ratio_threshold != NOT_SET: + kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold + if tokens_weight_threshold != NOT_SET: + kwargs["tokens_weight_threshold"] = tokens_weight_threshold + if only_score_pruned_tokens != NOT_SET: + kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens super().__init__(kwargs) @@ -271,163 +224,159 @@ def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): super().__init__(**kwargs) -class DateDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - -class PinnedDoc(AttrDict[Any]): +class FunctionScoreContainer(AttrDict[Any]): """ - :arg _id: (required)The unique document ID. - :arg _index: (required)The index that contains the document. + :arg exp: Function that scores a document with a exponential decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg gauss: Function that scores a document with a normal decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg linear: Function that scores a document with a linear decay, + depending on the distance of a numeric field value of the document + from an origin. + :arg field_value_factor: Function allows you to use a field from a + document to influence the score. It’s similar to using the + script_score function, however, it avoids the overhead of + scripting. + :arg random_score: Generates scores that are uniformly distributed + from 0 up to but not including 1. In case you want scores to be + reproducible, it is possible to provide a `seed` and `field`. + :arg script_score: Enables you to wrap another query and customize the + scoring of it optionally with a computation derived from other + numeric field values in the doc using a script expression. + :arg filter: No documentation available. + :arg weight: No documentation available. """ def __init__( self, *, - _id: Union[str, "NotSet"] = NOT_SET, - _index: Union[str, "NotSet"] = NOT_SET, + exp: Union["f.DecayFunction", "NotSet"] = NOT_SET, + gauss: Union["f.DecayFunction", "NotSet"] = NOT_SET, + linear: Union["f.DecayFunction", "NotSet"] = NOT_SET, + field_value_factor: Union["f.FieldValueFactor", "NotSet"] = NOT_SET, + random_score: Union["f.RandomScore", "NotSet"] = NOT_SET, + script_score: Union["f.ScriptScore", "NotSet"] = NOT_SET, + filter: Union[Query, "NotSet"] = NOT_SET, + weight: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): - if _id != NOT_SET: - kwargs["_id"] = _id - if _index != NOT_SET: - kwargs["_index"] = _index + if exp != NOT_SET: + kwargs["exp"] = exp + if gauss != NOT_SET: + kwargs["gauss"] = gauss + if linear != NOT_SET: + kwargs["linear"] = linear + if field_value_factor != NOT_SET: + kwargs["field_value_factor"] = field_value_factor + if random_score != NOT_SET: + kwargs["random_score"] = random_score + if script_score != NOT_SET: + kwargs["script_score"] = script_score + if filter != NOT_SET: + kwargs["filter"] = filter + if weight != NOT_SET: + kwargs["weight"] = weight super().__init__(kwargs) -class TermsSetQuery(QueryBase): - """ - :arg minimum_should_match_field: Numeric field containing the number - of matching terms required to return a document. - :arg minimum_should_match_script: Custom script containing the number - of matching terms required to return a document. - :arg terms: (required)Array of terms you wish to find in the provided - field. - """ - - def __init__( - self, - *, - minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - minimum_should_match_script: Union[ - "i.Script", Dict[str, Any], "NotSet" - ] = NOT_SET, - terms: Union[List[str], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if minimum_should_match_field != NOT_SET: - kwargs["minimum_should_match_field"] = str(minimum_should_match_field) - if minimum_should_match_script != NOT_SET: - kwargs["minimum_should_match_script"] = minimum_should_match_script - if terms != NOT_SET: - kwargs["terms"] = terms - super().__init__(**kwargs) - - -class RankFeatureFunction(AttrDict[Any]): - pass - - -class RankFeatureFunctionSaturation(RankFeatureFunction): - """ - :arg pivot: Configurable pivot value so that the result will be less - than 0.5. - """ - - def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): - if pivot != NOT_SET: - kwargs["pivot"] = pivot - super().__init__(**kwargs) - - -class RegexpQuery(QueryBase): +class MatchPhraseQuery(QueryBase): """ - :arg case_insensitive: Allows case insensitive matching of the regular - expression value with the indexed field values when set to `true`. - When `false`, case sensitivity of matching depends on the - underlying field’s mapping. - :arg flags: Enables optional operators for the regular expression. - :arg max_determinized_states: Maximum number of automaton states - required for the query. - :arg rewrite: Method used to rewrite the query. - :arg value: (required)Regular expression for terms you wish to find in - the provided field. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg query: (required)Query terms that are analyzed and turned into a + phrase query. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. """ def __init__( self, *, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, - flags: Union[str, "NotSet"] = NOT_SET, - max_determinized_states: Union[int, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive - if flags != NOT_SET: - kwargs["flags"] = flags - if max_determinized_states != NOT_SET: - kwargs["max_determinized_states"] = max_determinized_states - if rewrite != NOT_SET: - kwargs["rewrite"] = rewrite - if value != NOT_SET: - kwargs["value"] = value + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if query != NOT_SET: + kwargs["query"] = query + if slop != NOT_SET: + kwargs["slop"] = slop + if zero_terms_query != NOT_SET: + kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class MatchBoolPrefixQuery(QueryBase): +class MatchQuery(QueryBase): """ :arg analyzer: Analyzer used to convert the text in the query value into tokens. - :arg fuzziness: Maximum edit distance allowed for matching. Can be - applied to the term subqueries constructed for all terms but the - final term. - :arg fuzzy_rewrite: Method used to rewrite the query. Can be applied - to the term subqueries constructed for all terms but the final - term. + :arg auto_generate_synonyms_phrase_query: If `true`, match phrase + queries are automatically created for multi-term synonyms. + :arg cutoff_frequency: No documentation available. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg fuzzy_rewrite: Method used to rewrite the query. :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to - `ba`). Can be applied to the term subqueries constructed for all - terms but the final term. + `ba`). + :arg lenient: If `true`, format-based errors, such as providing a text + query value for a numeric field, are ignored. :arg max_expansions: Maximum number of terms to which the query will - expand. Can be applied to the term subqueries constructed for all - terms but the final term. + expand. :arg minimum_should_match: Minimum number of clauses that must match - for a document to be returned. Applied to the constructed bool - query. + for a document to be returned. :arg operator: Boolean logic used to interpret text in the query - value. Applied to the constructed bool query. + value. :arg prefix_length: Number of beginning characters left unchanged for - fuzzy matching. Can be applied to the term subqueries constructed - for all terms but the final term. - :arg query: (required)Terms you wish to find in the provided field. - The last term is used in a prefix query. + fuzzy matching. + :arg query: (required)Text, number, boolean value or date you wish to + find in the provided field. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. """ def __init__( self, *, analyzer: Union[str, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, fuzziness: Union[str, int, "NotSet"] = NOT_SET, fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, max_expansions: Union[int, "NotSet"] = NOT_SET, minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, + query: Union[str, float, bool, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, **kwargs: Any, ): if analyzer != NOT_SET: kwargs["analyzer"] = analyzer + if auto_generate_synonyms_phrase_query != NOT_SET: + kwargs["auto_generate_synonyms_phrase_query"] = ( + auto_generate_synonyms_phrase_query + ) + if cutoff_frequency != NOT_SET: + kwargs["cutoff_frequency"] = cutoff_frequency if fuzziness != NOT_SET: kwargs["fuzziness"] = fuzziness if fuzzy_rewrite != NOT_SET: kwargs["fuzzy_rewrite"] = fuzzy_rewrite if fuzzy_transpositions != NOT_SET: kwargs["fuzzy_transpositions"] = fuzzy_transpositions + if lenient != NOT_SET: + kwargs["lenient"] = lenient if max_expansions != NOT_SET: kwargs["max_expansions"] = max_expansions if minimum_should_match != NOT_SET: @@ -438,78 +387,110 @@ def __init__( kwargs["prefix_length"] = prefix_length if query != NOT_SET: kwargs["query"] = query + if zero_terms_query != NOT_SET: + kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class FuzzyQuery(QueryBase): +class RankFeatureFunction(AttrDict[Any]): + pass + + +class RankFeatureFunctionSigmoid(RankFeatureFunction): """ - :arg max_expansions: Maximum number of variations created. - :arg prefix_length: Number of beginning characters left unchanged when - creating expansions. - :arg rewrite: Number of beginning characters left unchanged when - creating expansions. - :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example `ab` to `ba`). - :arg fuzziness: Maximum edit distance allowed for matching. - :arg value: (required)Term you wish to find in the provided field. + :arg pivot: (required)Configurable pivot value so that the result will + be less than 0.5. + :arg exponent: (required)Configurable Exponent. """ def __init__( self, *, - max_expansions: Union[int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - value: Union[str, float, bool, "NotSet"] = NOT_SET, + pivot: Union[float, "NotSet"] = NOT_SET, + exponent: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): - if max_expansions != NOT_SET: - kwargs["max_expansions"] = max_expansions - if prefix_length != NOT_SET: - kwargs["prefix_length"] = prefix_length - if rewrite != NOT_SET: - kwargs["rewrite"] = rewrite - if transpositions != NOT_SET: - kwargs["transpositions"] = transpositions - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if value != NOT_SET: - kwargs["value"] = value + if pivot != NOT_SET: + kwargs["pivot"] = pivot + if exponent != NOT_SET: + kwargs["exponent"] = exponent super().__init__(**kwargs) -class MatchPhraseQuery(QueryBase): +class Script(AttrDict[Any]): """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. - :arg query: (required)Query terms that are analyzed and turned into a - phrase query. - :arg slop: Maximum number of positions allowed between matching - tokens. - :arg zero_terms_query: Indicates whether no documents are returned if - the `analyzer` removes all tokens, such as when using a `stop` - filter. + :arg source: The script source. + :arg id: The `id` for a stored script. + :arg params: Specifies any named parameters that are passed into the + script as variables. Use parameters instead of hard-coded values + to decrease compile time. + :arg lang: Specifies the language the script is written in. + :arg options: No documentation available. """ def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if query != NOT_SET: - kwargs["query"] = query - if slop != NOT_SET: - kwargs["slop"] = slop - if zero_terms_query != NOT_SET: - kwargs["zero_terms_query"] = zero_terms_query + source: Union[str, "NotSet"] = NOT_SET, + id: Union[str, "NotSet"] = NOT_SET, + params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + lang: Union[ + Literal["painless", "expression", "mustache", "java"], "NotSet" + ] = NOT_SET, + options: Union[Mapping[str, str], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if source != NOT_SET: + kwargs["source"] = source + if id != NOT_SET: + kwargs["id"] = id + if params != NOT_SET: + kwargs["params"] = params + if lang != NOT_SET: + kwargs["lang"] = lang + if options != NOT_SET: + kwargs["options"] = options + super().__init__(kwargs) + + +class PrefixQuery(QueryBase): + """ + :arg rewrite: Method used to rewrite the query. + :arg value: (required)Beginning characters of terms you wish to find + in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. Default is + `false` which means the case sensitivity of matching depends on + the underlying field’s mapping. + """ + + def __init__( + self, + *, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if value != NOT_SET: + kwargs["value"] = value + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) + + +class RankFeatureFunctionLogarithm(RankFeatureFunction): + """ + :arg scaling_factor: (required)Configurable scaling factor. + """ + + def __init__( + self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + ): + if scaling_factor != NOT_SET: + kwargs["scaling_factor"] = scaling_factor super().__init__(**kwargs) @@ -546,16 +527,68 @@ def __init__( super().__init__(**kwargs) -class RankFeatureFunctionLogarithm(RankFeatureFunction): +class CommonTermsQuery(QueryBase): """ - :arg scaling_factor: (required)Configurable scaling factor. + :arg analyzer: No documentation available. + :arg cutoff_frequency: No documentation available. + :arg high_freq_operator: No documentation available. + :arg low_freq_operator: No documentation available. + :arg minimum_should_match: No documentation available. + :arg query: (required)No documentation available. """ def __init__( - self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, ): - if scaling_factor != NOT_SET: - kwargs["scaling_factor"] = scaling_factor + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if cutoff_frequency != NOT_SET: + kwargs["cutoff_frequency"] = cutoff_frequency + if high_freq_operator != NOT_SET: + kwargs["high_freq_operator"] = high_freq_operator + if low_freq_operator != NOT_SET: + kwargs["low_freq_operator"] = low_freq_operator + if minimum_should_match != NOT_SET: + kwargs["minimum_should_match"] = minimum_should_match + if query != NOT_SET: + kwargs["query"] = query + super().__init__(**kwargs) + + +class TermsSetQuery(QueryBase): + """ + :arg minimum_should_match_field: Numeric field containing the number + of matching terms required to return a document. + :arg minimum_should_match_script: Custom script containing the number + of matching terms required to return a document. + :arg terms: (required)Array of terms you wish to find in the provided + field. + """ + + def __init__( + self, + *, + minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + minimum_should_match_script: Union[ + "i.Script", Dict[str, Any], "NotSet" + ] = NOT_SET, + terms: Union[List[str], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if minimum_should_match_field != NOT_SET: + kwargs["minimum_should_match_field"] = str(minimum_should_match_field) + if minimum_should_match_script != NOT_SET: + kwargs["minimum_should_match_script"] = minimum_should_match_script + if terms != NOT_SET: + kwargs["terms"] = terms super().__init__(**kwargs) @@ -596,108 +629,51 @@ def __init__( super().__init__(**kwargs) -class TokenPruningConfig(AttrDict[Any]): - """ - :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than - this threshold times the average frequency of all tokens in the - specified field are considered outliers and pruned. - :arg tokens_weight_threshold: Tokens whose weight is less than this - threshold are considered nonsignificant and pruned. - :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs - only scoring kept tokens. - """ - - def __init__( - self, - *, - tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, - tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, - only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if tokens_freq_ratio_threshold != NOT_SET: - kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold - if tokens_weight_threshold != NOT_SET: - kwargs["tokens_weight_threshold"] = tokens_weight_threshold - if only_score_pruned_tokens != NOT_SET: - kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens - super().__init__(kwargs) - - -class FunctionScoreContainer(AttrDict[Any]): +class LikeDocument(AttrDict[Any]): """ - :arg exp: Function that scores a document with a exponential decay, - depending on the distance of a numeric field value of the document - from an origin. - :arg gauss: Function that scores a document with a normal decay, - depending on the distance of a numeric field value of the document - from an origin. - :arg linear: Function that scores a document with a linear decay, - depending on the distance of a numeric field value of the document - from an origin. - :arg field_value_factor: Function allows you to use a field from a - document to influence the score. It’s similar to using the - script_score function, however, it avoids the overhead of - scripting. - :arg random_score: Generates scores that are uniformly distributed - from 0 up to but not including 1. In case you want scores to be - reproducible, it is possible to provide a `seed` and `field`. - :arg script_score: Enables you to wrap another query and customize the - scoring of it optionally with a computation derived from other - numeric field values in the doc using a script expression. - :arg filter: No documentation available. - :arg weight: No documentation available. + :arg doc: A document not present in the index. + :arg fields: No documentation available. + :arg _id: ID of a document. + :arg _index: Index of a document. + :arg per_field_analyzer: Overrides the default analyzer. + :arg routing: No documentation available. + :arg version: No documentation available. + :arg version_type: No documentation available. """ def __init__( self, *, - exp: Union[ - "f.UntypedDecayFunction", - "f.DateDecayFunction", - "f.NumericDecayFunction", - "f.GeoDecayFunction", - "NotSet", - ] = NOT_SET, - gauss: Union[ - "f.UntypedDecayFunction", - "f.DateDecayFunction", - "f.NumericDecayFunction", - "f.GeoDecayFunction", - "NotSet", - ] = NOT_SET, - linear: Union[ - "f.UntypedDecayFunction", - "f.DateDecayFunction", - "f.NumericDecayFunction", - "f.GeoDecayFunction", - "NotSet", + doc: Any = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + _id: Union[str, "NotSet"] = NOT_SET, + _index: Union[str, "NotSet"] = NOT_SET, + per_field_analyzer: Union[ + Mapping[Union[str, "InstrumentedField"], str], "NotSet" ] = NOT_SET, - field_value_factor: Union[ - "f.FieldValueFactorScoreFunction", "NotSet" + routing: Union[str, "NotSet"] = NOT_SET, + version: Union[int, "NotSet"] = NOT_SET, + version_type: Union[ + Literal["internal", "external", "external_gte", "force"], "NotSet" ] = NOT_SET, - random_score: Union["f.RandomScoreFunction", "NotSet"] = NOT_SET, - script_score: Union["f.ScriptScoreFunction", "NotSet"] = NOT_SET, - filter: Union[Query, "NotSet"] = NOT_SET, - weight: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): - if exp != NOT_SET: - kwargs["exp"] = exp - if gauss != NOT_SET: - kwargs["gauss"] = gauss - if linear != NOT_SET: - kwargs["linear"] = linear - if field_value_factor != NOT_SET: - kwargs["field_value_factor"] = field_value_factor - if random_score != NOT_SET: - kwargs["random_score"] = random_score - if script_score != NOT_SET: - kwargs["script_score"] = script_score - if filter != NOT_SET: - kwargs["filter"] = filter - if weight != NOT_SET: - kwargs["weight"] = weight + if doc != NOT_SET: + kwargs["doc"] = doc + if fields != NOT_SET: + kwargs["fields"] = str(fields) + if _id != NOT_SET: + kwargs["_id"] = _id + if _index != NOT_SET: + kwargs["_index"] = _index + if per_field_analyzer != NOT_SET: + kwargs["per_field_analyzer"] = str(per_field_analyzer) + if routing != NOT_SET: + kwargs["routing"] = routing + if version != NOT_SET: + kwargs["version"] = version + if version_type != NOT_SET: + kwargs["version_type"] = version_type super().__init__(kwargs) @@ -739,73 +715,119 @@ def __init__( super().__init__(**kwargs) -class RankFeatureFunctionLinear(RankFeatureFunction): - pass - - -class MatchQuery(QueryBase): +class TermQuery(QueryBase): """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. - :arg auto_generate_synonyms_phrase_query: If `true`, match phrase - queries are automatically created for multi-term synonyms. - :arg cutoff_frequency: No documentation available. - :arg fuzziness: Maximum edit distance allowed for matching. - :arg fuzzy_rewrite: Method used to rewrite the query. - :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include - transpositions of two adjacent characters (for example, `ab` to - `ba`). - :arg lenient: If `true`, format-based errors, such as providing a text - query value for a numeric field, are ignored. + :arg value: (required)Term you wish to find in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. When + `false`, the case sensitivity of matching depends on the + underlying field’s mapping. + """ + + def __init__( + self, + *, + value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if value != NOT_SET: + kwargs["value"] = value + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) + + +class FuzzyQuery(QueryBase): + """ + :arg max_expansions: Maximum number of variations created. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg rewrite: Number of beginning characters left unchanged when + creating expansions. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example `ab` to `ba`). + :arg fuzziness: Maximum edit distance allowed for matching. + :arg value: (required)Term you wish to find in the provided field. + """ + + def __init__( + self, + *, + max_expansions: Union[int, "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + value: Union[str, float, bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if max_expansions != NOT_SET: + kwargs["max_expansions"] = max_expansions + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if rewrite != NOT_SET: + kwargs["rewrite"] = rewrite + if transpositions != NOT_SET: + kwargs["transpositions"] = transpositions + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if value != NOT_SET: + kwargs["value"] = value + super().__init__(**kwargs) + + +class MatchBoolPrefixQuery(QueryBase): + """ + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg fuzziness: Maximum edit distance allowed for matching. Can be + applied to the term subqueries constructed for all terms but the + final term. + :arg fuzzy_rewrite: Method used to rewrite the query. Can be applied + to the term subqueries constructed for all terms but the final + term. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). Can be applied to the term subqueries constructed for all + terms but the final term. :arg max_expansions: Maximum number of terms to which the query will - expand. + expand. Can be applied to the term subqueries constructed for all + terms but the final term. :arg minimum_should_match: Minimum number of clauses that must match - for a document to be returned. + for a document to be returned. Applied to the constructed bool + query. :arg operator: Boolean logic used to interpret text in the query - value. + value. Applied to the constructed bool query. :arg prefix_length: Number of beginning characters left unchanged for - fuzzy matching. - :arg query: (required)Text, number, boolean value or date you wish to - find in the provided field. - :arg zero_terms_query: Indicates whether no documents are returned if - the `analyzer` removes all tokens, such as when using a `stop` - filter. + fuzzy matching. Can be applied to the term subqueries constructed + for all terms but the final term. + :arg query: (required)Terms you wish to find in the provided field. + The last term is used in a prefix query. """ def __init__( self, *, analyzer: Union[str, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, fuzziness: Union[str, int, "NotSet"] = NOT_SET, fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, max_expansions: Union[int, "NotSet"] = NOT_SET, minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, float, bool, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): if analyzer != NOT_SET: kwargs["analyzer"] = analyzer - if auto_generate_synonyms_phrase_query != NOT_SET: - kwargs["auto_generate_synonyms_phrase_query"] = ( - auto_generate_synonyms_phrase_query - ) - if cutoff_frequency != NOT_SET: - kwargs["cutoff_frequency"] = cutoff_frequency if fuzziness != NOT_SET: kwargs["fuzziness"] = fuzziness if fuzzy_rewrite != NOT_SET: kwargs["fuzzy_rewrite"] = fuzzy_rewrite if fuzzy_transpositions != NOT_SET: kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if lenient != NOT_SET: - kwargs["lenient"] = lenient if max_expansions != NOT_SET: kwargs["max_expansions"] = max_expansions if minimum_should_match != NOT_SET: @@ -816,273 +838,230 @@ def __init__( kwargs["prefix_length"] = prefix_length if query != NOT_SET: kwargs["query"] = query - if zero_terms_query != NOT_SET: - kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class WeightedTokensQuery(QueryBase): - """ - :arg tokens: (required)The tokens representing this query - :arg pruning_config: Token pruning configurations - """ - - def __init__( - self, - *, - tokens: Union[Mapping[str, float], "NotSet"] = NOT_SET, - pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "NotSet" - ] = NOT_SET, - **kwargs: Any, - ): - if tokens != NOT_SET: - kwargs["tokens"] = tokens - if pruning_config != NOT_SET: - kwargs["pruning_config"] = pruning_config - super().__init__(**kwargs) +class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): + pass -class LikeDocument(AttrDict[Any]): +class PinnedDoc(AttrDict[Any]): """ - :arg doc: A document not present in the index. - :arg fields: No documentation available. - :arg _id: ID of a document. - :arg _index: Index of a document. - :arg per_field_analyzer: Overrides the default analyzer. - :arg routing: No documentation available. - :arg version: No documentation available. - :arg version_type: No documentation available. + :arg _id: (required)The unique document ID. + :arg _index: (required)The index that contains the document. """ def __init__( self, *, - doc: Any = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, _id: Union[str, "NotSet"] = NOT_SET, _index: Union[str, "NotSet"] = NOT_SET, - per_field_analyzer: Union[ - Mapping[Union[str, "InstrumentedField"], str], "NotSet" - ] = NOT_SET, - routing: Union[str, "NotSet"] = NOT_SET, - version: Union[int, "NotSet"] = NOT_SET, - version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "NotSet" - ] = NOT_SET, **kwargs: Any, ): - if doc != NOT_SET: - kwargs["doc"] = doc - if fields != NOT_SET: - kwargs["fields"] = str(fields) if _id != NOT_SET: kwargs["_id"] = _id if _index != NOT_SET: kwargs["_index"] = _index - if per_field_analyzer != NOT_SET: - kwargs["per_field_analyzer"] = str(per_field_analyzer) - if routing != NOT_SET: - kwargs["routing"] = routing - if version != NOT_SET: - kwargs["version"] = version - if version_type != NOT_SET: - kwargs["version_type"] = version_type super().__init__(kwargs) -class SpanQuery(AttrDict[Any]): +class InnerHits(AttrDict[Any]): """ - :arg span_containing: Accepts a list of span queries, but only returns - those spans which also match a second span query. - :arg span_field_masking: Allows queries like `span_near` or `span_or` - across different fields. - :arg span_first: Accepts another span query whose matches must appear - within the first N positions of the field. - :arg span_gap: No documentation available. - :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, - `regexp`, or `fuzzy` query. - :arg span_near: Accepts multiple span queries whose matches must be - within the specified distance of each other, and possibly in the - same order. - :arg span_not: Wraps another span query, and excludes any documents - which match that query. - :arg span_or: Combines multiple span queries and returns documents - which match any of the specified queries. - :arg span_term: The equivalent of the `term` query but for use with - other span queries. - :arg span_within: The result from a single span query is returned as - long is its span falls within the spans returned by a list of - other span queries. + :arg name: The name for the particular inner hit definition in the + response. Useful when a search request contains multiple inner + hits. + :arg size: The maximum number of hits to return per `inner_hits`. + :arg from: Inner hit starting document offset. + :arg collapse: No documentation available. + :arg docvalue_fields: No documentation available. + :arg explain: No documentation available. + :arg highlight: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg script_fields: No documentation available. + :arg seq_no_primary_term: No documentation available. + :arg fields: No documentation available. + :arg sort: How the inner hits should be sorted per `inner_hits`. By + default, inner hits are sorted by score. + :arg _source: No documentation available. + :arg stored_fields: No documentation available. + :arg track_scores: No documentation available. + :arg version: No documentation available. """ def __init__( self, *, - span_containing: Union[ - "i.SpanContainingQuery", Dict[str, Any], "NotSet" + name: Union[str, "NotSet"] = NOT_SET, + size: Union[int, "NotSet"] = NOT_SET, + from_: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + docvalue_fields: Union[ + List["i.FieldAndFormat"], Dict[str, Any], "NotSet" ] = NOT_SET, - span_field_masking: Union[ - "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" + explain: Union[bool, "NotSet"] = NOT_SET, + highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + script_fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Dict[str, Any], + "NotSet", ] = NOT_SET, - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_gap: Union[ - Mapping[Union[str, "InstrumentedField"], int], "NotSet" + seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, + fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", ] = NOT_SET, - span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], Dict[str, Any], "NotSet", ] = NOT_SET, - span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, + stored_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + track_scores: Union[bool, "NotSet"] = NOT_SET, + version: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if span_containing != NOT_SET: - kwargs["span_containing"] = span_containing - if span_field_masking != NOT_SET: - kwargs["span_field_masking"] = span_field_masking - if span_first != NOT_SET: - kwargs["span_first"] = span_first - if span_gap != NOT_SET: - kwargs["span_gap"] = str(span_gap) - if span_multi != NOT_SET: - kwargs["span_multi"] = span_multi - if span_near != NOT_SET: - kwargs["span_near"] = span_near - if span_not != NOT_SET: - kwargs["span_not"] = span_not - if span_or != NOT_SET: - kwargs["span_or"] = span_or - if span_term != NOT_SET: - kwargs["span_term"] = str(span_term) - if span_within != NOT_SET: - kwargs["span_within"] = span_within + if name != NOT_SET: + kwargs["name"] = name + if size != NOT_SET: + kwargs["size"] = size + if from_ != NOT_SET: + kwargs["from_"] = from_ + if collapse != NOT_SET: + kwargs["collapse"] = collapse + if docvalue_fields != NOT_SET: + kwargs["docvalue_fields"] = docvalue_fields + if explain != NOT_SET: + kwargs["explain"] = explain + if highlight != NOT_SET: + kwargs["highlight"] = highlight + if ignore_unmapped != NOT_SET: + kwargs["ignore_unmapped"] = ignore_unmapped + if script_fields != NOT_SET: + kwargs["script_fields"] = str(script_fields) + if seq_no_primary_term != NOT_SET: + kwargs["seq_no_primary_term"] = seq_no_primary_term + if fields != NOT_SET: + kwargs["fields"] = str(fields) + if sort != NOT_SET: + kwargs["sort"] = str(sort) + if _source != NOT_SET: + kwargs["_source"] = _source + if stored_fields != NOT_SET: + kwargs["stored_fields"] = str(stored_fields) + if track_scores != NOT_SET: + kwargs["track_scores"] = track_scores + if version != NOT_SET: + kwargs["version"] = version super().__init__(kwargs) -class PrefixQuery(QueryBase): +class RegexpQuery(QueryBase): """ + :arg case_insensitive: Allows case insensitive matching of the regular + expression value with the indexed field values when set to `true`. + When `false`, case sensitivity of matching depends on the + underlying field’s mapping. + :arg flags: Enables optional operators for the regular expression. + :arg max_determinized_states: Maximum number of automaton states + required for the query. :arg rewrite: Method used to rewrite the query. - :arg value: (required)Beginning characters of terms you wish to find - in the provided field. - :arg case_insensitive: Allows ASCII case insensitive matching of the - value with the indexed field values when set to `true`. Default is - `false` which means the case sensitivity of matching depends on - the underlying field’s mapping. + :arg value: (required)Regular expression for terms you wish to find in + the provided field. """ def __init__( self, *, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + flags: Union[str, "NotSet"] = NOT_SET, + max_determinized_states: Union[int, "NotSet"] = NOT_SET, rewrite: Union[str, "NotSet"] = NOT_SET, value: Union[str, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): + if case_insensitive != NOT_SET: + kwargs["case_insensitive"] = case_insensitive + if flags != NOT_SET: + kwargs["flags"] = flags + if max_determinized_states != NOT_SET: + kwargs["max_determinized_states"] = max_determinized_states if rewrite != NOT_SET: kwargs["rewrite"] = rewrite if value != NOT_SET: kwargs["value"] = value - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive super().__init__(**kwargs) -class RankFeatureFunctionSigmoid(RankFeatureFunction): +class TextExpansionQuery(QueryBase): """ - :arg pivot: (required)Configurable pivot value so that the result will - be less than 0.5. - :arg exponent: (required)Configurable Exponent. + :arg model_id: (required)The text expansion NLP model to use + :arg model_text: (required)The query text + :arg pruning_config: Token pruning configurations """ def __init__( self, *, - pivot: Union[float, "NotSet"] = NOT_SET, - exponent: Union[float, "NotSet"] = NOT_SET, + model_id: Union[str, "NotSet"] = NOT_SET, + model_text: Union[str, "NotSet"] = NOT_SET, + pruning_config: Union[ + "i.TokenPruningConfig", Dict[str, Any], "NotSet" + ] = NOT_SET, **kwargs: Any, ): - if pivot != NOT_SET: - kwargs["pivot"] = pivot - if exponent != NOT_SET: - kwargs["exponent"] = exponent + if model_id != NOT_SET: + kwargs["model_id"] = model_id + if model_text != NOT_SET: + kwargs["model_text"] = model_text + if pruning_config != NOT_SET: + kwargs["pruning_config"] = pruning_config super().__init__(**kwargs) -class CommonTermsQuery(QueryBase): +class RankFeatureFunctionLinear(RankFeatureFunction): + pass + + +class RankFeatureFunctionSaturation(RankFeatureFunction): """ - :arg analyzer: No documentation available. - :arg cutoff_frequency: No documentation available. - :arg high_freq_operator: No documentation available. - :arg low_freq_operator: No documentation available. - :arg minimum_should_match: No documentation available. - :arg query: (required)No documentation available. + :arg pivot: Configurable pivot value so that the result will be less + than 0.5. """ - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if cutoff_frequency != NOT_SET: - kwargs["cutoff_frequency"] = cutoff_frequency - if high_freq_operator != NOT_SET: - kwargs["high_freq_operator"] = high_freq_operator - if low_freq_operator != NOT_SET: - kwargs["low_freq_operator"] = low_freq_operator - if minimum_should_match != NOT_SET: - kwargs["minimum_should_match"] = minimum_should_match - if query != NOT_SET: - kwargs["query"] = query + def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): + if pivot != NOT_SET: + kwargs["pivot"] = pivot super().__init__(**kwargs) -class Script(AttrDict[Any]): +class WeightedTokensQuery(QueryBase): """ - :arg source: The script source. - :arg id: The `id` for a stored script. - :arg params: Specifies any named parameters that are passed into the - script as variables. Use parameters instead of hard-coded values - to decrease compile time. - :arg lang: Specifies the language the script is written in. - :arg options: No documentation available. + :arg tokens: (required)The tokens representing this query + :arg pruning_config: Token pruning configurations """ def __init__( self, *, - source: Union[str, "NotSet"] = NOT_SET, - id: Union[str, "NotSet"] = NOT_SET, - params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, - lang: Union[ - Literal["painless", "expression", "mustache", "java"], "NotSet" + tokens: Union[Mapping[str, float], "NotSet"] = NOT_SET, + pruning_config: Union[ + "i.TokenPruningConfig", Dict[str, Any], "NotSet" ] = NOT_SET, - options: Union[Mapping[str, str], "NotSet"] = NOT_SET, **kwargs: Any, ): - if source != NOT_SET: - kwargs["source"] = source - if id != NOT_SET: - kwargs["id"] = id - if params != NOT_SET: - kwargs["params"] = params - if lang != NOT_SET: - kwargs["lang"] = lang - if options != NOT_SET: - kwargs["options"] = options - super().__init__(kwargs) + if tokens != NOT_SET: + kwargs["tokens"] = tokens + if pruning_config != NOT_SET: + kwargs["pruning_config"] = pruning_config + super().__init__(**kwargs) class TextEmbedding(AttrDict[Any]): @@ -1105,348 +1084,184 @@ def __init__( super().__init__(kwargs) -class HighlightBase(AttrDict[Any]): +class SpanOrQuery(QueryBase): """ - :arg type: No documentation available. - :arg boundary_chars: A string that contains each boundary character. - :arg boundary_max_scan: How far to scan for boundary characters. - :arg boundary_scanner: Specifies how to break the highlighted - fragments: chars, sentence, or word. Only valid for the unified - and fvh highlighters. Defaults to `sentence` for the `unified` - highlighter. Defaults to `chars` for the `fvh` highlighter. - :arg boundary_scanner_locale: Controls which locale is used to search - for sentence and word boundaries. This parameter takes a form of a - language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. - :arg force_source: No documentation available. - :arg fragmenter: Specifies how text should be broken up in highlight - snippets: `simple` or `span`. Only valid for the `plain` - highlighter. - :arg fragment_size: The size of the highlighted fragment in - characters. - :arg highlight_filter: No documentation available. - :arg highlight_query: Highlight matches for a query other than the - search query. This is especially useful if you use a rescore query - because those are not taken into account by highlighting by - default. - :arg max_fragment_length: No documentation available. - :arg max_analyzed_offset: If set to a non-negative value, highlighting - stops at this defined maximum limit. The rest of the text is not - processed, thus not highlighted and no error is returned The - `max_analyzed_offset` query setting does not override the - `index.highlight.max_analyzed_offset` setting, which prevails when - it’s set to lower value than the query setting. - :arg no_match_size: The amount of text you want to return from the - beginning of the field if there are no matching fragments to - highlight. - :arg number_of_fragments: The maximum number of fragments to return. - If the number of fragments is set to `0`, no fragments are - returned. Instead, the entire field contents are highlighted and - returned. This can be handy when you need to highlight short texts - such as a title or address, but fragmentation is not required. If - `number_of_fragments` is `0`, `fragment_size` is ignored. - :arg options: No documentation available. - :arg order: Sorts highlighted fragments by score when set to `score`. - By default, fragments will be output in the order they appear in - the field (order: `none`). Setting this option to `score` will - output the most relevant fragments first. Each highlighter applies - its own logic to compute relevancy scores. - :arg phrase_limit: Controls the number of matching phrases in a - document that are considered. Prevents the `fvh` highlighter from - analyzing too many phrases and consuming too much memory. When - using `matched_fields`, `phrase_limit` phrases per matched field - are considered. Raising the limit increases query time and - consumes more memory. Only supported by the `fvh` highlighter. - :arg post_tags: Use in conjunction with `pre_tags` to define the HTML - tags to use for the highlighted text. By default, highlighted text - is wrapped in `` and `` tags. - :arg pre_tags: Use in conjunction with `post_tags` to define the HTML - tags to use for the highlighted text. By default, highlighted text - is wrapped in `` and `` tags. - :arg require_field_match: By default, only fields that contains a - query match are highlighted. Set to `false` to highlight all - fields. - :arg tags_schema: Set to `styled` to use the built-in tag schema. + :arg clauses: (required)Array of one or more other span type queries. """ def __init__( self, *, - type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, - boundary_chars: Union[str, "NotSet"] = NOT_SET, - boundary_max_scan: Union[int, "NotSet"] = NOT_SET, - boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "NotSet" - ] = NOT_SET, - boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, - force_source: Union[bool, "NotSet"] = NOT_SET, - fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, - fragment_size: Union[int, "NotSet"] = NOT_SET, - highlight_filter: Union[bool, "NotSet"] = NOT_SET, - highlight_query: Union[Query, "NotSet"] = NOT_SET, - max_fragment_length: Union[int, "NotSet"] = NOT_SET, - max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, - no_match_size: Union[int, "NotSet"] = NOT_SET, - number_of_fragments: Union[int, "NotSet"] = NOT_SET, - options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, - order: Union[Literal["score"], "NotSet"] = NOT_SET, - phrase_limit: Union[int, "NotSet"] = NOT_SET, - post_tags: Union[List[str], "NotSet"] = NOT_SET, - pre_tags: Union[List[str], "NotSet"] = NOT_SET, - require_field_match: Union[bool, "NotSet"] = NOT_SET, - tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if type != NOT_SET: - kwargs["type"] = type - if boundary_chars != NOT_SET: - kwargs["boundary_chars"] = boundary_chars - if boundary_max_scan != NOT_SET: - kwargs["boundary_max_scan"] = boundary_max_scan - if boundary_scanner != NOT_SET: - kwargs["boundary_scanner"] = boundary_scanner - if boundary_scanner_locale != NOT_SET: - kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if force_source != NOT_SET: - kwargs["force_source"] = force_source - if fragmenter != NOT_SET: - kwargs["fragmenter"] = fragmenter - if fragment_size != NOT_SET: - kwargs["fragment_size"] = fragment_size - if highlight_filter != NOT_SET: - kwargs["highlight_filter"] = highlight_filter - if highlight_query != NOT_SET: - kwargs["highlight_query"] = highlight_query - if max_fragment_length != NOT_SET: - kwargs["max_fragment_length"] = max_fragment_length - if max_analyzed_offset != NOT_SET: - kwargs["max_analyzed_offset"] = max_analyzed_offset - if no_match_size != NOT_SET: - kwargs["no_match_size"] = no_match_size - if number_of_fragments != NOT_SET: - kwargs["number_of_fragments"] = number_of_fragments - if options != NOT_SET: - kwargs["options"] = options - if order != NOT_SET: - kwargs["order"] = order - if phrase_limit != NOT_SET: - kwargs["phrase_limit"] = phrase_limit - if post_tags != NOT_SET: - kwargs["post_tags"] = post_tags - if pre_tags != NOT_SET: - kwargs["pre_tags"] = pre_tags - if require_field_match != NOT_SET: - kwargs["require_field_match"] = require_field_match - if tags_schema != NOT_SET: - kwargs["tags_schema"] = tags_schema - super().__init__(kwargs) + if clauses != NOT_SET: + kwargs["clauses"] = clauses + super().__init__(**kwargs) -class Highlight(HighlightBase): +class SpanMultiTermQuery(QueryBase): """ - :arg encoder: No documentation available. - :arg fields: (required)No documentation available. + :arg match: (required)Should be a multi term query (one of `wildcard`, + `fuzzy`, `prefix`, `range`, or `regexp` query). """ - def __init__( - self, - *, - encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, - fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], - Dict[str, Any], - "NotSet", - ] = NOT_SET, - **kwargs: Any, - ): - if encoder != NOT_SET: - kwargs["encoder"] = encoder - if fields != NOT_SET: - kwargs["fields"] = str(fields) + def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): + if match != NOT_SET: + kwargs["match"] = match super().__init__(**kwargs) -class FieldCollapse(AttrDict[Any]): +class SpanContainingQuery(QueryBase): """ - :arg field: (required)The field to collapse the result set on - :arg inner_hits: The number of inner hits and their sort order - :arg max_concurrent_group_searches: The number of concurrent requests - allowed to retrieve the inner_hits per group - :arg collapse: No documentation available. + :arg big: (required)Can be any span query. Matching spans from `big` + that contain matches from `little` are returned. + :arg little: (required)Can be any span query. Matching spans from + `big` that contain matches from `little` are returned. """ def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - inner_hits: Union[ - "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs["field"] = str(field) - if inner_hits != NOT_SET: - kwargs["inner_hits"] = inner_hits - if max_concurrent_group_searches != NOT_SET: - kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches - if collapse != NOT_SET: - kwargs["collapse"] = collapse - super().__init__(kwargs) + if big != NOT_SET: + kwargs["big"] = big + if little != NOT_SET: + kwargs["little"] = little + super().__init__(**kwargs) -class FieldAndFormat(AttrDict[Any]): +class SpanFirstQuery(QueryBase): """ - :arg field: (required)Wildcard pattern. The request returns values for - field names matching this pattern. - :arg format: Format in which the values are returned. - :arg include_unmapped: No documentation available. + :arg end: (required)Controls the maximum end position permitted in a + match. + :arg match: (required)Can be any other span type query. """ def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - format: Union[str, "NotSet"] = NOT_SET, - include_unmapped: Union[bool, "NotSet"] = NOT_SET, + end: Union[int, "NotSet"] = NOT_SET, + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs["field"] = str(field) - if format != NOT_SET: - kwargs["format"] = format - if include_unmapped != NOT_SET: - kwargs["include_unmapped"] = include_unmapped - super().__init__(kwargs) + if end != NOT_SET: + kwargs["end"] = end + if match != NOT_SET: + kwargs["match"] = match + super().__init__(**kwargs) -class SourceFilter(AttrDict[Any]): +class SpanNotQuery(QueryBase): """ - :arg excludes: No documentation available. - :arg includes: No documentation available. + :arg dist: The number of tokens from within the include span that + can’t have overlap with the exclude span. Equivalent to setting + both `pre` and `post`. + :arg exclude: (required)Span query whose matches must not overlap + those returned. + :arg include: (required)Span query whose matches are filtered. + :arg post: The number of tokens after the include span that can’t have + overlap with the exclude span. + :arg pre: The number of tokens before the include span that can’t have + overlap with the exclude span. """ def __init__( self, *, - excludes: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - includes: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, + dist: Union[int, "NotSet"] = NOT_SET, + exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + post: Union[int, "NotSet"] = NOT_SET, + pre: Union[int, "NotSet"] = NOT_SET, **kwargs: Any, ): - if excludes != NOT_SET: - kwargs["excludes"] = str(excludes) - if includes != NOT_SET: - kwargs["includes"] = str(includes) - super().__init__(kwargs) + if dist != NOT_SET: + kwargs["dist"] = dist + if exclude != NOT_SET: + kwargs["exclude"] = exclude + if include != NOT_SET: + kwargs["include"] = include + if post != NOT_SET: + kwargs["post"] = post + if pre != NOT_SET: + kwargs["pre"] = pre + super().__init__(**kwargs) -class ScriptField(AttrDict[Any]): +class SpanWithinQuery(QueryBase): """ - :arg script: (required)No documentation available. - :arg ignore_failure: No documentation available. + :arg big: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg little: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. """ def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_failure: Union[bool, "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if script != NOT_SET: - kwargs["script"] = script - if ignore_failure != NOT_SET: - kwargs["ignore_failure"] = ignore_failure - super().__init__(kwargs) + if big != NOT_SET: + kwargs["big"] = big + if little != NOT_SET: + kwargs["little"] = little + super().__init__(**kwargs) -class SortOptions(AttrDict[Any]): +class SpanNearQuery(QueryBase): """ - :arg _score: No documentation available. - :arg _doc: No documentation available. - :arg _geo_distance: No documentation available. - :arg _script: No documentation available. + :arg clauses: (required)Array of one or more other span type queries. + :arg in_order: Controls whether matches are required to be in-order. + :arg slop: Controls the maximum number of intervening unmatched + positions permitted. """ def __init__( self, *, - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + in_order: Union[bool, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, **kwargs: Any, ): - if _score != NOT_SET: - kwargs["_score"] = _score - if _doc != NOT_SET: - kwargs["_doc"] = _doc - if _geo_distance != NOT_SET: - kwargs["_geo_distance"] = _geo_distance - if _script != NOT_SET: - kwargs["_script"] = _script - super().__init__(kwargs) + if clauses != NOT_SET: + kwargs["clauses"] = clauses + if in_order != NOT_SET: + kwargs["in_order"] = in_order + if slop != NOT_SET: + kwargs["slop"] = slop + super().__init__(**kwargs) -class IntervalsFuzzy(AttrDict[Any]): +class SpanFieldMaskingQuery(QueryBase): """ - :arg analyzer: Analyzer used to normalize the term. - :arg fuzziness: Maximum edit distance allowed for matching. - :arg prefix_length: Number of beginning characters left unchanged when - creating expansions. - :arg term: (required)The term to match. - :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example, `ab` to `ba`). - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `term` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. + :arg field: (required)No documentation available. + :arg query: (required)No documentation available. """ def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - term: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if prefix_length != NOT_SET: - kwargs["prefix_length"] = prefix_length - if term != NOT_SET: - kwargs["term"] = term - if transpositions != NOT_SET: - kwargs["transpositions"] = transpositions - if use_field != NOT_SET: - kwargs["use_field"] = str(use_field) - super().__init__(kwargs) + if field != NOT_SET: + kwargs["field"] = str(field) + if query != NOT_SET: + kwargs["query"] = query + super().__init__(**kwargs) -class IntervalsAllOf(AttrDict[Any]): +class IntervalsAnyOf(AttrDict[Any]): """ - :arg intervals: (required)An array of rules to combine. All rules must - produce a match in a document for the overall source to match. - :arg max_gaps: Maximum number of positions between the matching terms. - Intervals produced by the rules further apart than this are not - considered matches. - :arg ordered: If `true`, intervals produced by the rules should appear - in the order in which they are specified. + :arg intervals: (required)An array of rules to match. :arg filter: Rule used to filter returned intervals. """ @@ -1456,22 +1271,44 @@ def __init__( intervals: Union[ List["i.IntervalsContainer"], Dict[str, Any], "NotSet" ] = NOT_SET, - max_gaps: Union[int, "NotSet"] = NOT_SET, - ordered: Union[bool, "NotSet"] = NOT_SET, filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): if intervals != NOT_SET: kwargs["intervals"] = intervals - if max_gaps != NOT_SET: - kwargs["max_gaps"] = max_gaps - if ordered != NOT_SET: - kwargs["ordered"] = ordered if filter != NOT_SET: kwargs["filter"] = filter super().__init__(kwargs) +class IntervalsWildcard(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the + top-level field's analyzer. + :arg pattern: (required)Wildcard pattern used to find matching terms. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `pattern` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. + """ + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + pattern: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if pattern != NOT_SET: + kwargs["pattern"] = pattern + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + class IntervalsMatch(AttrDict[Any]): """ :arg analyzer: Analyzer used to analyze terms in the query. @@ -1513,41 +1350,17 @@ def __init__( super().__init__(kwargs) -class IntervalsPrefix(AttrDict[Any]): - """ - :arg analyzer: Analyzer used to analyze the `prefix`. - :arg prefix: (required)Beginning characters of terms you wish to find - in the top-level field. - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `prefix` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. - """ - - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - prefix: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if prefix != NOT_SET: - kwargs["prefix"] = prefix - if use_field != NOT_SET: - kwargs["use_field"] = str(use_field) - super().__init__(kwargs) - - -class IntervalsWildcard(AttrDict[Any]): +class IntervalsFuzzy(AttrDict[Any]): """ - :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the - top-level field's analyzer. - :arg pattern: (required)Wildcard pattern used to find matching terms. + :arg analyzer: Analyzer used to normalize the term. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg term: (required)The term to match. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example, `ab` to `ba`). :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `pattern` is normalized using the + than the top-level field. The `term` is normalized using the search analyzer from this field, unless `analyzer` is specified separately. """ @@ -1556,341 +1369,380 @@ def __init__( self, *, analyzer: Union[str, "NotSet"] = NOT_SET, - pattern: Union[str, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + term: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): if analyzer != NOT_SET: kwargs["analyzer"] = analyzer - if pattern != NOT_SET: - kwargs["pattern"] = pattern + if fuzziness != NOT_SET: + kwargs["fuzziness"] = fuzziness + if prefix_length != NOT_SET: + kwargs["prefix_length"] = prefix_length + if term != NOT_SET: + kwargs["term"] = term + if transpositions != NOT_SET: + kwargs["transpositions"] = transpositions if use_field != NOT_SET: kwargs["use_field"] = str(use_field) super().__init__(kwargs) -class IntervalsAnyOf(AttrDict[Any]): - """ - :arg intervals: (required)An array of rules to match. - :arg filter: Rule used to filter returned intervals. - """ - - def __init__( - self, - *, - intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if intervals != NOT_SET: - kwargs["intervals"] = intervals - if filter != NOT_SET: - kwargs["filter"] = filter - super().__init__(kwargs) - - -class SpanFieldMaskingQuery(QueryBase): - """ - :arg field: (required)No documentation available. - :arg query: (required)No documentation available. - """ - - def __init__( - self, - *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if field != NOT_SET: - kwargs["field"] = str(field) - if query != NOT_SET: - kwargs["query"] = query - super().__init__(**kwargs) - - -class SpanNearQuery(QueryBase): - """ - :arg clauses: (required)Array of one or more other span type queries. - :arg in_order: Controls whether matches are required to be in-order. - :arg slop: Controls the maximum number of intervening unmatched - positions permitted. - """ - - def __init__( - self, - *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, - in_order: Union[bool, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if clauses != NOT_SET: - kwargs["clauses"] = clauses - if in_order != NOT_SET: - kwargs["in_order"] = in_order - if slop != NOT_SET: - kwargs["slop"] = slop - super().__init__(**kwargs) - - -class SpanMultiTermQuery(QueryBase): - """ - :arg match: (required)Should be a multi term query (one of `wildcard`, - `fuzzy`, `prefix`, `range`, or `regexp` query). +class IntervalsAllOf(AttrDict[Any]): + """ + :arg intervals: (required)An array of rules to combine. All rules must + produce a match in a document for the overall source to match. + :arg max_gaps: Maximum number of positions between the matching terms. + Intervals produced by the rules further apart than this are not + considered matches. + :arg ordered: If `true`, intervals produced by the rules should appear + in the order in which they are specified. + :arg filter: Rule used to filter returned intervals. """ - def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): - if match != NOT_SET: - kwargs["match"] = match - super().__init__(**kwargs) + def __init__( + self, + *, + intervals: Union[ + List["i.IntervalsContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_gaps: Union[int, "NotSet"] = NOT_SET, + ordered: Union[bool, "NotSet"] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if intervals != NOT_SET: + kwargs["intervals"] = intervals + if max_gaps != NOT_SET: + kwargs["max_gaps"] = max_gaps + if ordered != NOT_SET: + kwargs["ordered"] = ordered + if filter != NOT_SET: + kwargs["filter"] = filter + super().__init__(kwargs) -class SpanContainingQuery(QueryBase): +class IntervalsPrefix(AttrDict[Any]): """ - :arg big: (required)Can be any span query. Matching spans from `big` - that contain matches from `little` are returned. - :arg little: (required)Can be any span query. Matching spans from - `big` that contain matches from `little` are returned. + :arg analyzer: Analyzer used to analyze the `prefix`. + :arg prefix: (required)Beginning characters of terms you wish to find + in the top-level field. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `prefix` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. """ def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + prefix: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if big != NOT_SET: - kwargs["big"] = big - if little != NOT_SET: - kwargs["little"] = little - super().__init__(**kwargs) + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + if prefix != NOT_SET: + kwargs["prefix"] = prefix + if use_field != NOT_SET: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) -class SpanFirstQuery(QueryBase): +class FieldCollapse(AttrDict[Any]): """ - :arg end: (required)Controls the maximum end position permitted in a - match. - :arg match: (required)Can be any other span type query. + :arg field: (required)The field to collapse the result set on + :arg inner_hits: The number of inner hits and their sort order + :arg max_concurrent_group_searches: The number of concurrent requests + allowed to retrieve the inner_hits per group + :arg collapse: No documentation available. """ def __init__( self, *, - end: Union[int, "NotSet"] = NOT_SET, - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + inner_hits: Union[ + "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if end != NOT_SET: - kwargs["end"] = end - if match != NOT_SET: - kwargs["match"] = match - super().__init__(**kwargs) + if field != NOT_SET: + kwargs["field"] = str(field) + if inner_hits != NOT_SET: + kwargs["inner_hits"] = inner_hits + if max_concurrent_group_searches != NOT_SET: + kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches + if collapse != NOT_SET: + kwargs["collapse"] = collapse + super().__init__(kwargs) -class SpanNotQuery(QueryBase): +class FieldAndFormat(AttrDict[Any]): """ - :arg dist: The number of tokens from within the include span that - can’t have overlap with the exclude span. Equivalent to setting - both `pre` and `post`. - :arg exclude: (required)Span query whose matches must not overlap - those returned. - :arg include: (required)Span query whose matches are filtered. - :arg post: The number of tokens after the include span that can’t have - overlap with the exclude span. - :arg pre: The number of tokens before the include span that can’t have - overlap with the exclude span. + :arg field: (required)Wildcard pattern. The request returns values for + field names matching this pattern. + :arg format: Format in which the values are returned. + :arg include_unmapped: No documentation available. """ def __init__( self, *, - dist: Union[int, "NotSet"] = NOT_SET, - exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - post: Union[int, "NotSet"] = NOT_SET, - pre: Union[int, "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + format: Union[str, "NotSet"] = NOT_SET, + include_unmapped: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if dist != NOT_SET: - kwargs["dist"] = dist - if exclude != NOT_SET: - kwargs["exclude"] = exclude - if include != NOT_SET: - kwargs["include"] = include - if post != NOT_SET: - kwargs["post"] = post - if pre != NOT_SET: - kwargs["pre"] = pre - super().__init__(**kwargs) + if field != NOT_SET: + kwargs["field"] = str(field) + if format != NOT_SET: + kwargs["format"] = format + if include_unmapped != NOT_SET: + kwargs["include_unmapped"] = include_unmapped + super().__init__(kwargs) -class SpanWithinQuery(QueryBase): +class ScriptField(AttrDict[Any]): """ - :arg big: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. - :arg little: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. + :arg script: (required)No documentation available. + :arg ignore_failure: No documentation available. """ def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_failure: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if big != NOT_SET: - kwargs["big"] = big - if little != NOT_SET: - kwargs["little"] = little - super().__init__(**kwargs) + if script != NOT_SET: + kwargs["script"] = script + if ignore_failure != NOT_SET: + kwargs["ignore_failure"] = ignore_failure + super().__init__(kwargs) -class SpanOrQuery(QueryBase): +class SortOptions(AttrDict[Any]): """ - :arg clauses: (required)Array of one or more other span type queries. + :arg _score: No documentation available. + :arg _doc: No documentation available. + :arg _geo_distance: No documentation available. + :arg _script: No documentation available. """ def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if clauses != NOT_SET: - kwargs["clauses"] = clauses - super().__init__(**kwargs) + if _score != NOT_SET: + kwargs["_score"] = _score + if _doc != NOT_SET: + kwargs["_doc"] = _doc + if _geo_distance != NOT_SET: + kwargs["_geo_distance"] = _geo_distance + if _script != NOT_SET: + kwargs["_script"] = _script + super().__init__(kwargs) -class HighlightField(HighlightBase): +class SourceFilter(AttrDict[Any]): """ - :arg fragment_offset: No documentation available. - :arg matched_fields: No documentation available. - :arg analyzer: No documentation available. + :arg excludes: No documentation available. + :arg includes: No documentation available. """ def __init__( self, *, - fragment_offset: Union[int, "NotSet"] = NOT_SET, - matched_fields: Union[ + excludes: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet", ] = NOT_SET, - analyzer: Union[ - "a.CustomAnalyzer", - "a.FingerprintAnalyzer", - "a.KeywordAnalyzer", - "a.LanguageAnalyzer", - "a.NoriAnalyzer", - "a.PatternAnalyzer", - "a.SimpleAnalyzer", - "a.StandardAnalyzer", - "a.StopAnalyzer", - "a.WhitespaceAnalyzer", - "a.IcuAnalyzer", - "a.KuromojiAnalyzer", - "a.SnowballAnalyzer", - "a.DutchAnalyzer", + includes: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], "NotSet", ] = NOT_SET, **kwargs: Any, ): - if fragment_offset != NOT_SET: - kwargs["fragment_offset"] = fragment_offset - if matched_fields != NOT_SET: - kwargs["matched_fields"] = str(matched_fields) - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - super().__init__(**kwargs) + if excludes != NOT_SET: + kwargs["excludes"] = str(excludes) + if includes != NOT_SET: + kwargs["includes"] = str(includes) + super().__init__(kwargs) -class ScriptSort(AttrDict[Any]): +class HighlightBase(AttrDict[Any]): """ - :arg order: No documentation available. - :arg script: (required)No documentation available. :arg type: No documentation available. - :arg mode: No documentation available. - :arg nested: No documentation available. + :arg boundary_chars: A string that contains each boundary character. + :arg boundary_max_scan: How far to scan for boundary characters. + :arg boundary_scanner: Specifies how to break the highlighted + fragments: chars, sentence, or word. Only valid for the unified + and fvh highlighters. Defaults to `sentence` for the `unified` + highlighter. Defaults to `chars` for the `fvh` highlighter. + :arg boundary_scanner_locale: Controls which locale is used to search + for sentence and word boundaries. This parameter takes a form of a + language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + :arg force_source: No documentation available. + :arg fragmenter: Specifies how text should be broken up in highlight + snippets: `simple` or `span`. Only valid for the `plain` + highlighter. + :arg fragment_size: The size of the highlighted fragment in + characters. + :arg highlight_filter: No documentation available. + :arg highlight_query: Highlight matches for a query other than the + search query. This is especially useful if you use a rescore query + because those are not taken into account by highlighting by + default. + :arg max_fragment_length: No documentation available. + :arg max_analyzed_offset: If set to a non-negative value, highlighting + stops at this defined maximum limit. The rest of the text is not + processed, thus not highlighted and no error is returned The + `max_analyzed_offset` query setting does not override the + `index.highlight.max_analyzed_offset` setting, which prevails when + it’s set to lower value than the query setting. + :arg no_match_size: The amount of text you want to return from the + beginning of the field if there are no matching fragments to + highlight. + :arg number_of_fragments: The maximum number of fragments to return. + If the number of fragments is set to `0`, no fragments are + returned. Instead, the entire field contents are highlighted and + returned. This can be handy when you need to highlight short texts + such as a title or address, but fragmentation is not required. If + `number_of_fragments` is `0`, `fragment_size` is ignored. + :arg options: No documentation available. + :arg order: Sorts highlighted fragments by score when set to `score`. + By default, fragments will be output in the order they appear in + the field (order: `none`). Setting this option to `score` will + output the most relevant fragments first. Each highlighter applies + its own logic to compute relevancy scores. + :arg phrase_limit: Controls the number of matching phrases in a + document that are considered. Prevents the `fvh` highlighter from + analyzing too many phrases and consuming too much memory. When + using `matched_fields`, `phrase_limit` phrases per matched field + are considered. Raising the limit increases query time and + consumes more memory. Only supported by the `fvh` highlighter. + :arg post_tags: Use in conjunction with `pre_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg pre_tags: Use in conjunction with `post_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg require_field_match: By default, only fields that contains a + query match are highlighted. Set to `false` to highlight all + fields. + :arg tags_schema: Set to `styled` to use the built-in tag schema. """ def __init__( self, *, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, + boundary_chars: Union[str, "NotSet"] = NOT_SET, + boundary_max_scan: Union[int, "NotSet"] = NOT_SET, + boundary_scanner: Union[ + Literal["chars", "sentence", "word"], "NotSet" + ] = NOT_SET, + boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, + force_source: Union[bool, "NotSet"] = NOT_SET, + fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, + fragment_size: Union[int, "NotSet"] = NOT_SET, + highlight_filter: Union[bool, "NotSet"] = NOT_SET, + highlight_query: Union[Query, "NotSet"] = NOT_SET, + max_fragment_length: Union[int, "NotSet"] = NOT_SET, + max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, + no_match_size: Union[int, "NotSet"] = NOT_SET, + number_of_fragments: Union[int, "NotSet"] = NOT_SET, + options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + order: Union[Literal["score"], "NotSet"] = NOT_SET, + phrase_limit: Union[int, "NotSet"] = NOT_SET, + post_tags: Union[List[str], "NotSet"] = NOT_SET, + pre_tags: Union[List[str], "NotSet"] = NOT_SET, + require_field_match: Union[bool, "NotSet"] = NOT_SET, + tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if order != NOT_SET: - kwargs["order"] = order - if script != NOT_SET: - kwargs["script"] = script if type != NOT_SET: kwargs["type"] = type - if mode != NOT_SET: - kwargs["mode"] = mode - if nested != NOT_SET: - kwargs["nested"] = nested + if boundary_chars != NOT_SET: + kwargs["boundary_chars"] = boundary_chars + if boundary_max_scan != NOT_SET: + kwargs["boundary_max_scan"] = boundary_max_scan + if boundary_scanner != NOT_SET: + kwargs["boundary_scanner"] = boundary_scanner + if boundary_scanner_locale != NOT_SET: + kwargs["boundary_scanner_locale"] = boundary_scanner_locale + if force_source != NOT_SET: + kwargs["force_source"] = force_source + if fragmenter != NOT_SET: + kwargs["fragmenter"] = fragmenter + if fragment_size != NOT_SET: + kwargs["fragment_size"] = fragment_size + if highlight_filter != NOT_SET: + kwargs["highlight_filter"] = highlight_filter + if highlight_query != NOT_SET: + kwargs["highlight_query"] = highlight_query + if max_fragment_length != NOT_SET: + kwargs["max_fragment_length"] = max_fragment_length + if max_analyzed_offset != NOT_SET: + kwargs["max_analyzed_offset"] = max_analyzed_offset + if no_match_size != NOT_SET: + kwargs["no_match_size"] = no_match_size + if number_of_fragments != NOT_SET: + kwargs["number_of_fragments"] = number_of_fragments + if options != NOT_SET: + kwargs["options"] = options + if order != NOT_SET: + kwargs["order"] = order + if phrase_limit != NOT_SET: + kwargs["phrase_limit"] = phrase_limit + if post_tags != NOT_SET: + kwargs["post_tags"] = post_tags + if pre_tags != NOT_SET: + kwargs["pre_tags"] = pre_tags + if require_field_match != NOT_SET: + kwargs["require_field_match"] = require_field_match + if tags_schema != NOT_SET: + kwargs["tags_schema"] = tags_schema super().__init__(kwargs) -class GeoDistanceSort(AttrDict[Any]): +class Highlight(HighlightBase): """ - :arg mode: No documentation available. - :arg distance_type: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg order: No documentation available. - :arg unit: No documentation available. - :arg nested: No documentation available. + :arg encoder: No documentation available. + :arg fields: (required)No documentation available. """ def __init__( self, *, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - unit: Union[ - Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" + encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, + fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Dict[str, Any], + "NotSet", ] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if mode != NOT_SET: - kwargs["mode"] = mode - if distance_type != NOT_SET: - kwargs["distance_type"] = distance_type - if ignore_unmapped != NOT_SET: - kwargs["ignore_unmapped"] = ignore_unmapped - if order != NOT_SET: - kwargs["order"] = order - if unit != NOT_SET: - kwargs["unit"] = unit - if nested != NOT_SET: - kwargs["nested"] = nested - super().__init__(kwargs) - - -class ScoreSort(AttrDict[Any]): - """ - :arg order: No documentation available. - """ - - def __init__( - self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any - ): - if order != NOT_SET: - kwargs["order"] = order - super().__init__(kwargs) + if encoder != NOT_SET: + kwargs["encoder"] = encoder + if fields != NOT_SET: + kwargs["fields"] = str(fields) + super().__init__(**kwargs) class IntervalsContainer(AttrDict[Any]): @@ -1993,6 +1845,117 @@ def __init__( super().__init__(kwargs) +class ScoreSort(AttrDict[Any]): + """ + :arg order: No documentation available. + """ + + def __init__( + self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + ): + if order != NOT_SET: + kwargs["order"] = order + super().__init__(kwargs) + + +class GeoDistanceSort(AttrDict[Any]): + """ + :arg mode: No documentation available. + :arg distance_type: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg order: No documentation available. + :arg unit: No documentation available. + :arg nested: No documentation available. + """ + + def __init__( + self, + *, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + unit: Union[ + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" + ] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if mode != NOT_SET: + kwargs["mode"] = mode + if distance_type != NOT_SET: + kwargs["distance_type"] = distance_type + if ignore_unmapped != NOT_SET: + kwargs["ignore_unmapped"] = ignore_unmapped + if order != NOT_SET: + kwargs["order"] = order + if unit != NOT_SET: + kwargs["unit"] = unit + if nested != NOT_SET: + kwargs["nested"] = nested + super().__init__(kwargs) + + +class ScriptSort(AttrDict[Any]): + """ + :arg order: No documentation available. + :arg script: (required)No documentation available. + :arg type: No documentation available. + :arg mode: No documentation available. + :arg nested: No documentation available. + """ + + def __init__( + self, + *, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if order != NOT_SET: + kwargs["order"] = order + if script != NOT_SET: + kwargs["script"] = script + if type != NOT_SET: + kwargs["type"] = type + if mode != NOT_SET: + kwargs["mode"] = mode + if nested != NOT_SET: + kwargs["nested"] = nested + super().__init__(kwargs) + + +class HighlightField(HighlightBase): + """ + :arg fragment_offset: No documentation available. + :arg matched_fields: No documentation available. + :arg analyzer: No documentation available. + """ + + def __init__( + self, + *, + fragment_offset: Union[int, "NotSet"] = NOT_SET, + matched_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if fragment_offset != NOT_SET: + kwargs["fragment_offset"] = fragment_offset + if matched_fields != NOT_SET: + kwargs["matched_fields"] = str(matched_fields) + if analyzer != NOT_SET: + kwargs["analyzer"] = analyzer + super().__init__(**kwargs) + + class NestedSortValue(AttrDict[Any]): """ :arg filter: No documentation available. diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index b5fb307e..aafe9065 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -40,14 +40,13 @@ # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import NOT_SET, DslBase +from .utils import NOT_SET, DslBase, NotSet if TYPE_CHECKING: from elasticsearch_dsl import interfaces as i from elasticsearch_dsl import wrappers from .document_base import InstrumentedField - from .utils import NotSet _T = TypeVar("_T") _M = TypeVar("_M", bound=Mapping[str, Any]) @@ -346,10 +345,10 @@ class Common(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.CommonTermsQuery", "NotSet"] = NOT_SET, + _value: Union["i.CommonTermsQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -472,12 +471,19 @@ def __init__( date: Union["i.DateDistanceFeatureQuery", "NotSet"] = NOT_SET, **kwargs: Any, ): - if untyped != NOT_SET: - kwargs = untyped - elif geo != NOT_SET: - kwargs = geo - elif date != NOT_SET: - kwargs = date + if not isinstance(untyped, NotSet): + kwargs = cast( + Dict[str, Any], + untyped.to_dict() if hasattr(untyped, "to_dict") else untyped, + ) + elif not isinstance(geo, NotSet): + kwargs = cast( + Dict[str, Any], geo.to_dict() if hasattr(geo, "to_dict") else geo + ) + elif not isinstance(date, NotSet): + kwargs = cast( + Dict[str, Any], date.to_dict() if hasattr(date, "to_dict") else date + ) super().__init__(**kwargs) @@ -541,11 +547,11 @@ def __init__( ] = NOT_SET, **kwargs: Any, ): - if functions == NOT_SET: + if isinstance(functions, NotSet): functions = [] for name in ScoreFunction._classes: if name in kwargs: - functions.append({name: kwargs.pop(name)}) + functions.append({name: kwargs.pop(name)}) # type: ignore super().__init__( boost_mode=boost_mode, functions=functions, @@ -571,10 +577,10 @@ class Fuzzy(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.FuzzyQuery", "NotSet"] = NOT_SET, + _value: Union["i.FuzzyQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -826,10 +832,10 @@ class Intervals(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.IntervalsQuery", "NotSet"] = NOT_SET, + _value: Union["i.IntervalsQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -897,10 +903,10 @@ class Match(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchQuery", "NotSet"] = NOT_SET, + _value: Union["i.MatchQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -947,10 +953,10 @@ class MatchBoolPrefix(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchBoolPrefixQuery", "NotSet"] = NOT_SET, + _value: Union["i.MatchBoolPrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -992,10 +998,10 @@ class MatchPhrase(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchPhraseQuery", "NotSet"] = NOT_SET, + _value: Union["i.MatchPhraseQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1015,10 +1021,10 @@ class MatchPhrasePrefix(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchPhrasePrefixQuery", "NotSet"] = NOT_SET, + _value: Union["i.MatchPhrasePrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1383,10 +1389,10 @@ class Prefix(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.PrefixQuery", "NotSet"] = NOT_SET, + _value: Union["i.PrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1532,16 +1538,10 @@ class Range(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union[ - "wrappers.Range", - "wrappers.Range", - "wrappers.Range", - "wrappers.Range", - "NotSet", - ] = NOT_SET, + _value: Union["wrappers.Range[Any]", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1606,10 +1606,10 @@ class Regexp(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.RegexpQuery", "NotSet"] = NOT_SET, + _value: Union["i.RegexpQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1978,10 +1978,10 @@ class SpanTerm(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.SpanTermQuery", "NotSet"] = NOT_SET, + _value: Union["i.SpanTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2080,10 +2080,10 @@ class Term(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TermQuery", "NotSet"] = NOT_SET, + _value: Union["i.TermQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2123,10 +2123,10 @@ class TermsSet(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TermsSetQuery", "NotSet"] = NOT_SET, + _value: Union["i.TermsSetQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2146,10 +2146,10 @@ class TextExpansion(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TextExpansionQuery", "NotSet"] = NOT_SET, + _value: Union["i.TextExpansionQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2168,10 +2168,10 @@ class WeightedTokens(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.WeightedTokensQuery", "NotSet"] = NOT_SET, + _value: Union["i.WeightedTokensQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2189,10 +2189,10 @@ class Wildcard(Query): def __init__( self, _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.WildcardQuery", "NotSet"] = NOT_SET, + _value: Union["i.WildcardQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value super().__init__(**kwargs) diff --git a/tests/_async/test_search.py b/tests/_async/test_search.py index 008246ab..a932c9f2 100644 --- a/tests/_async/test_search.py +++ b/tests/_async/test_search.py @@ -480,14 +480,16 @@ def test_reverse() -> None: d = { "query": { "bool": { - "filter": { - "bool": { - "should": [ - {"term": {"category": "meetup"}}, - {"term": {"category": "conference"}}, - ] + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": "meetup"}}, + {"term": {"category": "conference"}}, + ] + } } - }, + ], "must": [ { "bool": { @@ -525,7 +527,6 @@ def test_reverse() -> None: # make sure we haven't modified anything in place assert d == d2 assert {"size": 5} == s._extra - d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == s.to_dict() diff --git a/tests/_async/test_update_by_query.py b/tests/_async/test_update_by_query.py index beae2249..a7dba6ab 100644 --- a/tests/_async/test_update_by_query.py +++ b/tests/_async/test_update_by_query.py @@ -102,14 +102,16 @@ def test_reverse() -> None: d = { "query": { "bool": { - "filter": { - "bool": { - "should": [ - {"term": {"category": "meetup"}}, - {"term": {"category": "conference"}}, - ] + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": "meetup"}}, + {"term": {"category": "conference"}}, + ] + } } - }, + ], "must": [ { "bool": { @@ -133,7 +135,6 @@ def test_reverse() -> None: ubq = AsyncUpdateByQuery.from_dict(d) assert d == d2 - d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == ubq.to_dict() diff --git a/tests/_sync/test_search.py b/tests/_sync/test_search.py index 272b8a90..fefa0ee2 100644 --- a/tests/_sync/test_search.py +++ b/tests/_sync/test_search.py @@ -480,14 +480,16 @@ def test_reverse() -> None: d = { "query": { "bool": { - "filter": { - "bool": { - "should": [ - {"term": {"category": "meetup"}}, - {"term": {"category": "conference"}}, - ] + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": "meetup"}}, + {"term": {"category": "conference"}}, + ] + } } - }, + ], "must": [ { "bool": { @@ -525,7 +527,6 @@ def test_reverse() -> None: # make sure we haven't modified anything in place assert d == d2 assert {"size": 5} == s._extra - d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == s.to_dict() diff --git a/tests/_sync/test_update_by_query.py b/tests/_sync/test_update_by_query.py index bc4db61e..47ccb301 100644 --- a/tests/_sync/test_update_by_query.py +++ b/tests/_sync/test_update_by_query.py @@ -102,14 +102,16 @@ def test_reverse() -> None: d = { "query": { "bool": { - "filter": { - "bool": { - "should": [ - {"term": {"category": "meetup"}}, - {"term": {"category": "conference"}}, - ] + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": "meetup"}}, + {"term": {"category": "conference"}}, + ] + } } - }, + ], "must": [ { "bool": { @@ -133,7 +135,6 @@ def test_reverse() -> None: ubq = UpdateByQuery.from_dict(d) assert d == d2 - d["query"]["bool"]["filter"] = [d["query"]["bool"]["filter"]] assert d == ubq.to_dict() diff --git a/tests/test_query.py b/tests/test_query.py index 64d8ba2f..6be9a80d 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -124,7 +124,7 @@ def test_query_clone() -> None: def test_bool_converts_its_init_args_to_queries() -> None: - q = query.Bool(must=[{"match": {"f": "value"}}]) + q = query.Bool(must=[{"match": {"f": "value"}}]) # type: ignore assert len(q.must) == 1 assert q.must[0] == query.Match(f="value") diff --git a/utils/generator.py b/utils/generator.py index 9fa48ed5..e8eb852d 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -127,6 +127,8 @@ def get_python_type(self, schema_type): elif schema_type["kind"] == "array_of": type_, param = self.get_python_type(schema_type["value"]) + if type_.startswith("Union["): + types = type_[6:-1].split(",") return f"List[{type_}]", {**param, "multi": True} if param else None elif schema_type["kind"] == "dictionary_of": @@ -142,8 +144,9 @@ def get_python_type(self, schema_type): and schema_type["items"][0] == schema_type["items"][1]["value"] ): type_, param = self.get_python_type(schema_type["items"][0]) - return f"Union[{type_}, List[{type_}]]", ( - {"type": param["type"], "multi": True} if param else None + return ( + f"Union[{type_}, List[{type_}]]", + ({"type": param["type"], "multi": True} if param else None), ) elif ( len(schema_type["items"]) == 2 @@ -155,7 +158,11 @@ def get_python_type(self, schema_type): self.interfaces.add("PipeSeparatedFlags") return '"i.PipeSeparatedFlags"', None else: - types = [self.get_python_type(t) for t in schema_type["items"]] + types = list( + dict.fromkeys( + [self.get_python_type(t) for t in schema_type["items"]] + ) + ) return "Union[" + ", ".join([type_ for type_, _ in types]) + "]", None elif schema_type["kind"] == "enum": @@ -171,13 +178,20 @@ def get_python_type(self, schema_type): elif schema_type["kind"] == "interface": if schema_type["name"]["namespace"] == "_types.query_dsl": if schema_type["name"]["name"].endswith("RangeQuery"): - return '"wrappers.Range"', None + return '"wrappers.Range[Any]"', None + elif schema_type["name"]["name"].endswith("ScoreFunction"): + name = schema_type["name"]["name"][:-8] + if name == "FieldValueFactorScore": + name = "FieldValueFactor" # naming exception + return f'"f.{name}"', None + elif schema_type["name"]["name"].endswith("DecayFunction"): + return '"f.DecayFunction"', None elif schema_type["name"]["name"].endswith("Function"): return f"\"f.{schema_type['name']['name']}\"", None elif schema_type["name"]["namespace"] == "_types.analysis" and schema_type[ "name" ]["name"].endswith("Analyzer"): - return f"\"a.{schema_type['name']['name']}\"", None + return "str", None self.interfaces.add(schema_type["name"]["name"]) return f"\"i.{schema_type['name']['name']}\"", None elif schema_type["kind"] == "user_defined_value": @@ -273,7 +287,7 @@ def dictionary_of_to_python_class(self, p, k): }, { "name": "_value", - "type": add_not_set(value_type), + "type": add_not_set(add_dict_type(value_type)), "doc": [":arg _value: The query value for the field."], "required": False, }, diff --git a/utils/templates/dsl_classes.tpl b/utils/templates/dsl_classes.tpl index 7339e471..84d0566c 100644 --- a/utils/templates/dsl_classes.tpl +++ b/utils/templates/dsl_classes.tpl @@ -37,26 +37,26 @@ class {{ k.name }}({{ parent }}): **kwargs: Any ): {% if k.name == "FunctionScore" %} - if functions == NOT_SET: + if isinstance(functions, NotSet): functions = [] for name in ScoreFunction._classes: if name in kwargs: - functions.append({name: kwargs.pop(name)}) + functions.append({name: kwargs.pop(name)}) # type: ignore {% elif k.has_field %} - if _field != NOT_SET: + if not isinstance(_field, NotSet): kwargs[str(_field)] = _value {% elif k.has_fields %} - if fields != NOT_SET: + if not isinstance(fields, NotSet): for field, value in _fields.items(): kwargs[str(field)] = value {% elif k.has_type_alias %} {% for kwarg in k.kwargs %} {% if loop.index == 1 %} - if {{ kwarg.name }} != NOT_SET: + if not isinstance({{ kwarg.name }}, NotSet): {% else %} - elif {{ kwarg.name }} != NOT_SET: + elif not isinstance({{ kwarg.name }}, NotSet): {% endif %} - kwargs = {{ kwarg.name }} + kwargs = cast(Dict[str, Any], {{ kwarg.name }}.to_dict() if hasattr({{ kwarg.name }}, "to_dict") else {{ kwarg.name }}) {% endfor %} {% endif %} super().__init__( diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index b6ee69cc..52121d24 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Literal, Mapping, Union from elasticsearch_dsl.document_base import InstrumentedField -from elasticsearch_dsl import analysis as a, function as f, interfaces as i, Query +from elasticsearch_dsl import function as f, interfaces as i, Query from elasticsearch_dsl.utils import AttrDict, NotSet, NOT_SET PipeSeparatedFlags = str diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 92557416..f1f32d34 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -40,11 +40,10 @@ from typing import ( # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import DslBase, NOT_SET +from .utils import DslBase, NotSet, NOT_SET if TYPE_CHECKING: from .document_base import InstrumentedField - from .utils import NotSet from elasticsearch_dsl import interfaces as i, wrappers _T = TypeVar("_T") From a4760b36bb8c86cb5b15655c7b6d4384487183a2 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 2 Sep 2024 19:05:59 +0100 Subject: [PATCH 07/27] clean up code generation templates --- elasticsearch_dsl/interfaces.py | 2790 ++++++++++++++++------------- elasticsearch_dsl/utils.py | 2 +- utils/generator.py | 2 +- utils/templates/dsl_classes.tpl | 217 --- utils/templates/interfaces.py.tpl | 6 +- utils/templates/query.py.tpl | 218 ++- 6 files changed, 1787 insertions(+), 1448 deletions(-) delete mode 100644 utils/templates/dsl_classes.tpl diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index fbf9a757..dd7817de 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -26,22 +26,6 @@ PipeSeparatedFlags = str -class QueryVectorBuilder(AttrDict[Any]): - """ - :arg text_embedding: No documentation available. - """ - - def __init__( - self, - *, - text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if text_embedding != NOT_SET: - kwargs["text_embedding"] = text_embedding - super().__init__(kwargs) - - class QueryBase(AttrDict[Any]): """ :arg boost: Floating point number used to decrease or increase the @@ -52,6 +36,9 @@ class QueryBase(AttrDict[Any]): :arg _name: No documentation available. """ + boost: Union[float, "NotSet"] + _name: Union[str, "NotSet"] + def __init__( self, *, @@ -59,13 +46,56 @@ def __init__( _name: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if boost != NOT_SET: + if not isinstance(boost, NotSet): kwargs["boost"] = boost - if _name != NOT_SET: + if not isinstance(_name, NotSet): kwargs["_name"] = _name super().__init__(kwargs) +class CommonTermsQuery(QueryBase): + """ + :arg analyzer: No documentation available. + :arg cutoff_frequency: No documentation available. + :arg high_freq_operator: No documentation available. + :arg low_freq_operator: No documentation available. + :arg minimum_should_match: No documentation available. + :arg query: (required)No documentation available. + """ + + analyzer: Union[str, "NotSet"] + cutoff_frequency: Union[float, "NotSet"] + high_freq_operator: Union[Literal["and", "or"], "NotSet"] + low_freq_operator: Union[Literal["and", "or"], "NotSet"] + minimum_should_match: Union[int, str, "NotSet"] + query: Union[str, "NotSet"] + + def __init__( + self, + *, + analyzer: Union[str, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(cutoff_frequency, NotSet): + kwargs["cutoff_frequency"] = cutoff_frequency + if not isinstance(high_freq_operator, NotSet): + kwargs["high_freq_operator"] = high_freq_operator + if not isinstance(low_freq_operator, NotSet): + kwargs["low_freq_operator"] = low_freq_operator + if not isinstance(minimum_should_match, NotSet): + kwargs["minimum_should_match"] = minimum_should_match + if not isinstance(query, NotSet): + kwargs["query"] = query + super().__init__(**kwargs) + + class DistanceFeatureQueryBase(QueryBase): """ :arg origin: (required)Date or point of origin used to calculate @@ -87,6 +117,10 @@ class DistanceFeatureQueryBase(QueryBase): default. """ + origin: Any + pivot: Any + field: Union[str, "InstrumentedField", "NotSet"] + def __init__( self, *, @@ -95,11 +129,11 @@ def __init__( field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if origin != NOT_SET: + if not isinstance(origin, NotSet): kwargs["origin"] = origin - if pivot != NOT_SET: + if not isinstance(pivot, NotSet): kwargs["pivot"] = pivot - if field != NOT_SET: + if not isinstance(field, NotSet): kwargs["field"] = str(field) super().__init__(**kwargs) @@ -108,122 +142,6 @@ class DateDistanceFeatureQuery(DistanceFeatureQueryBase): pass -class SpanQuery(AttrDict[Any]): - """ - :arg span_containing: Accepts a list of span queries, but only returns - those spans which also match a second span query. - :arg span_field_masking: Allows queries like `span_near` or `span_or` - across different fields. - :arg span_first: Accepts another span query whose matches must appear - within the first N positions of the field. - :arg span_gap: No documentation available. - :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, - `regexp`, or `fuzzy` query. - :arg span_near: Accepts multiple span queries whose matches must be - within the specified distance of each other, and possibly in the - same order. - :arg span_not: Wraps another span query, and excludes any documents - which match that query. - :arg span_or: Combines multiple span queries and returns documents - which match any of the specified queries. - :arg span_term: The equivalent of the `term` query but for use with - other span queries. - :arg span_within: The result from a single span query is returned as - long is its span falls within the spans returned by a list of - other span queries. - """ - - def __init__( - self, - *, - span_containing: Union[ - "i.SpanContainingQuery", Dict[str, Any], "NotSet" - ] = NOT_SET, - span_field_masking: Union[ - "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" - ] = NOT_SET, - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_gap: Union[ - Mapping[Union[str, "InstrumentedField"], int], "NotSet" - ] = NOT_SET, - span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], - Dict[str, Any], - "NotSet", - ] = NOT_SET, - span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if span_containing != NOT_SET: - kwargs["span_containing"] = span_containing - if span_field_masking != NOT_SET: - kwargs["span_field_masking"] = span_field_masking - if span_first != NOT_SET: - kwargs["span_first"] = span_first - if span_gap != NOT_SET: - kwargs["span_gap"] = str(span_gap) - if span_multi != NOT_SET: - kwargs["span_multi"] = span_multi - if span_near != NOT_SET: - kwargs["span_near"] = span_near - if span_not != NOT_SET: - kwargs["span_not"] = span_not - if span_or != NOT_SET: - kwargs["span_or"] = span_or - if span_term != NOT_SET: - kwargs["span_term"] = str(span_term) - if span_within != NOT_SET: - kwargs["span_within"] = span_within - super().__init__(kwargs) - - -class TokenPruningConfig(AttrDict[Any]): - """ - :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than - this threshold times the average frequency of all tokens in the - specified field are considered outliers and pruned. - :arg tokens_weight_threshold: Tokens whose weight is less than this - threshold are considered nonsignificant and pruned. - :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs - only scoring kept tokens. - """ - - def __init__( - self, - *, - tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, - tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, - only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if tokens_freq_ratio_threshold != NOT_SET: - kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold - if tokens_weight_threshold != NOT_SET: - kwargs["tokens_weight_threshold"] = tokens_weight_threshold - if only_score_pruned_tokens != NOT_SET: - kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens - super().__init__(kwargs) - - -class GeoDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - -class SpanTermQuery(QueryBase): - """ - :arg value: (required)No documentation available. - """ - - def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): - if value != NOT_SET: - kwargs["value"] = value - super().__init__(**kwargs) - - class FunctionScoreContainer(AttrDict[Any]): """ :arg exp: Function that scores a document with a exponential decay, @@ -249,6 +167,15 @@ class FunctionScoreContainer(AttrDict[Any]): :arg weight: No documentation available. """ + exp: Union["f.DecayFunction", "NotSet"] + gauss: Union["f.DecayFunction", "NotSet"] + linear: Union["f.DecayFunction", "NotSet"] + field_value_factor: Union["f.FieldValueFactor", "NotSet"] + random_score: Union["f.RandomScore", "NotSet"] + script_score: Union["f.ScriptScore", "NotSet"] + filter: Union[Query, "NotSet"] + weight: Union[float, "NotSet"] + def __init__( self, *, @@ -262,741 +189,930 @@ def __init__( weight: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): - if exp != NOT_SET: + if not isinstance(exp, NotSet): kwargs["exp"] = exp - if gauss != NOT_SET: + if not isinstance(gauss, NotSet): kwargs["gauss"] = gauss - if linear != NOT_SET: + if not isinstance(linear, NotSet): kwargs["linear"] = linear - if field_value_factor != NOT_SET: + if not isinstance(field_value_factor, NotSet): kwargs["field_value_factor"] = field_value_factor - if random_score != NOT_SET: + if not isinstance(random_score, NotSet): kwargs["random_score"] = random_score - if script_score != NOT_SET: + if not isinstance(script_score, NotSet): kwargs["script_score"] = script_score - if filter != NOT_SET: + if not isinstance(filter, NotSet): kwargs["filter"] = filter - if weight != NOT_SET: + if not isinstance(weight, NotSet): kwargs["weight"] = weight super().__init__(kwargs) -class MatchPhraseQuery(QueryBase): - """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. - :arg query: (required)Query terms that are analyzed and turned into a - phrase query. - :arg slop: Maximum number of positions allowed between matching - tokens. - :arg zero_terms_query: Indicates whether no documents are returned if - the `analyzer` removes all tokens, such as when using a `stop` - filter. - """ - - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if query != NOT_SET: - kwargs["query"] = query - if slop != NOT_SET: - kwargs["slop"] = slop - if zero_terms_query != NOT_SET: - kwargs["zero_terms_query"] = zero_terms_query - super().__init__(**kwargs) - - -class MatchQuery(QueryBase): +class FuzzyQuery(QueryBase): """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. - :arg auto_generate_synonyms_phrase_query: If `true`, match phrase - queries are automatically created for multi-term synonyms. - :arg cutoff_frequency: No documentation available. + :arg max_expansions: Maximum number of variations created. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg rewrite: Number of beginning characters left unchanged when + creating expansions. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example `ab` to `ba`). :arg fuzziness: Maximum edit distance allowed for matching. - :arg fuzzy_rewrite: Method used to rewrite the query. - :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include - transpositions of two adjacent characters (for example, `ab` to - `ba`). - :arg lenient: If `true`, format-based errors, such as providing a text - query value for a numeric field, are ignored. - :arg max_expansions: Maximum number of terms to which the query will - expand. - :arg minimum_should_match: Minimum number of clauses that must match - for a document to be returned. - :arg operator: Boolean logic used to interpret text in the query - value. - :arg prefix_length: Number of beginning characters left unchanged for - fuzzy matching. - :arg query: (required)Text, number, boolean value or date you wish to - find in the provided field. - :arg zero_terms_query: Indicates whether no documents are returned if - the `analyzer` removes all tokens, such as when using a `stop` - filter. + :arg value: (required)Term you wish to find in the provided field. """ + max_expansions: Union[int, "NotSet"] + prefix_length: Union[int, "NotSet"] + rewrite: Union[str, "NotSet"] + transpositions: Union[bool, "NotSet"] + fuzziness: Union[str, int, "NotSet"] + value: Union[str, float, bool, "NotSet"] + def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, max_expansions: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, float, bool, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + value: Union[str, float, bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if auto_generate_synonyms_phrase_query != NOT_SET: - kwargs["auto_generate_synonyms_phrase_query"] = ( - auto_generate_synonyms_phrase_query - ) - if cutoff_frequency != NOT_SET: - kwargs["cutoff_frequency"] = cutoff_frequency - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if fuzzy_rewrite != NOT_SET: - kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if fuzzy_transpositions != NOT_SET: - kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if lenient != NOT_SET: - kwargs["lenient"] = lenient - if max_expansions != NOT_SET: + if not isinstance(max_expansions, NotSet): kwargs["max_expansions"] = max_expansions - if minimum_should_match != NOT_SET: - kwargs["minimum_should_match"] = minimum_should_match - if operator != NOT_SET: - kwargs["operator"] = operator - if prefix_length != NOT_SET: + if not isinstance(prefix_length, NotSet): kwargs["prefix_length"] = prefix_length - if query != NOT_SET: - kwargs["query"] = query - if zero_terms_query != NOT_SET: - kwargs["zero_terms_query"] = zero_terms_query + if not isinstance(rewrite, NotSet): + kwargs["rewrite"] = rewrite + if not isinstance(transpositions, NotSet): + kwargs["transpositions"] = transpositions + if not isinstance(fuzziness, NotSet): + kwargs["fuzziness"] = fuzziness + if not isinstance(value, NotSet): + kwargs["value"] = value super().__init__(**kwargs) -class RankFeatureFunction(AttrDict[Any]): +class GeoDistanceFeatureQuery(DistanceFeatureQueryBase): pass -class RankFeatureFunctionSigmoid(RankFeatureFunction): - """ - :arg pivot: (required)Configurable pivot value so that the result will - be less than 0.5. - :arg exponent: (required)Configurable Exponent. +class InnerHits(AttrDict[Any]): """ - - def __init__( - self, - *, - pivot: Union[float, "NotSet"] = NOT_SET, - exponent: Union[float, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if pivot != NOT_SET: - kwargs["pivot"] = pivot - if exponent != NOT_SET: - kwargs["exponent"] = exponent - super().__init__(**kwargs) - - -class Script(AttrDict[Any]): - """ - :arg source: The script source. - :arg id: The `id` for a stored script. - :arg params: Specifies any named parameters that are passed into the - script as variables. Use parameters instead of hard-coded values - to decrease compile time. - :arg lang: Specifies the language the script is written in. - :arg options: No documentation available. + :arg name: The name for the particular inner hit definition in the + response. Useful when a search request contains multiple inner + hits. + :arg size: The maximum number of hits to return per `inner_hits`. + :arg from: Inner hit starting document offset. + :arg collapse: No documentation available. + :arg docvalue_fields: No documentation available. + :arg explain: No documentation available. + :arg highlight: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg script_fields: No documentation available. + :arg seq_no_primary_term: No documentation available. + :arg fields: No documentation available. + :arg sort: How the inner hits should be sorted per `inner_hits`. By + default, inner hits are sorted by score. + :arg _source: No documentation available. + :arg stored_fields: No documentation available. + :arg track_scores: No documentation available. + :arg version: No documentation available. """ + name: Union[str, "NotSet"] + size: Union[int, "NotSet"] + from_: Union[int, "NotSet"] + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] + docvalue_fields: Union[List["i.FieldAndFormat"], Dict[str, Any], "NotSet"] + explain: Union[bool, "NotSet"] + highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] + ignore_unmapped: Union[bool, "NotSet"] + script_fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Dict[str, Any], + "NotSet", + ] + seq_no_primary_term: Union[bool, "NotSet"] + fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Dict[str, Any], + "NotSet", + ] + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] + stored_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + track_scores: Union[bool, "NotSet"] + version: Union[bool, "NotSet"] + def __init__( self, *, - source: Union[str, "NotSet"] = NOT_SET, - id: Union[str, "NotSet"] = NOT_SET, - params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, - lang: Union[ - Literal["painless", "expression", "mustache", "java"], "NotSet" + name: Union[str, "NotSet"] = NOT_SET, + size: Union[int, "NotSet"] = NOT_SET, + from_: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + docvalue_fields: Union[ + List["i.FieldAndFormat"], Dict[str, Any], "NotSet" ] = NOT_SET, - options: Union[Mapping[str, str], "NotSet"] = NOT_SET, + explain: Union[bool, "NotSet"] = NOT_SET, + highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + script_fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, + fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + sort: Union[ + Union[Union[str, "InstrumentedField"], "i.SortOptions"], + List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Dict[str, Any], + "NotSet", + ] = NOT_SET, + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, + stored_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + track_scores: Union[bool, "NotSet"] = NOT_SET, + version: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if source != NOT_SET: - kwargs["source"] = source - if id != NOT_SET: - kwargs["id"] = id - if params != NOT_SET: - kwargs["params"] = params - if lang != NOT_SET: - kwargs["lang"] = lang - if options != NOT_SET: - kwargs["options"] = options + if not isinstance(name, NotSet): + kwargs["name"] = name + if not isinstance(size, NotSet): + kwargs["size"] = size + if not isinstance(from_, NotSet): + kwargs["from_"] = from_ + if not isinstance(collapse, NotSet): + kwargs["collapse"] = collapse + if not isinstance(docvalue_fields, NotSet): + kwargs["docvalue_fields"] = docvalue_fields + if not isinstance(explain, NotSet): + kwargs["explain"] = explain + if not isinstance(highlight, NotSet): + kwargs["highlight"] = highlight + if not isinstance(ignore_unmapped, NotSet): + kwargs["ignore_unmapped"] = ignore_unmapped + if not isinstance(script_fields, NotSet): + kwargs["script_fields"] = str(script_fields) + if not isinstance(seq_no_primary_term, NotSet): + kwargs["seq_no_primary_term"] = seq_no_primary_term + if not isinstance(fields, NotSet): + kwargs["fields"] = str(fields) + if not isinstance(sort, NotSet): + kwargs["sort"] = str(sort) + if not isinstance(_source, NotSet): + kwargs["_source"] = _source + if not isinstance(stored_fields, NotSet): + kwargs["stored_fields"] = str(stored_fields) + if not isinstance(track_scores, NotSet): + kwargs["track_scores"] = track_scores + if not isinstance(version, NotSet): + kwargs["version"] = version super().__init__(kwargs) -class PrefixQuery(QueryBase): +class IntervalsQuery(QueryBase): """ - :arg rewrite: Method used to rewrite the query. - :arg value: (required)Beginning characters of terms you wish to find - in the provided field. - :arg case_insensitive: Allows ASCII case insensitive matching of the - value with the indexed field values when set to `true`. Default is - `false` which means the case sensitivity of matching depends on - the underlying field’s mapping. + :arg all_of: Returns matches that span a combination of other rules. + :arg any_of: Returns intervals produced by any of its sub-rules. + :arg fuzzy: Matches terms that are similar to the provided term, + within an edit distance defined by `fuzziness`. + :arg match: Matches analyzed text. + :arg prefix: Matches terms that start with a specified set of + characters. + :arg wildcard: Matches terms using a wildcard pattern. """ + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] + match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] + def __init__( self, *, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, + match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if rewrite != NOT_SET: - kwargs["rewrite"] = rewrite - if value != NOT_SET: - kwargs["value"] = value - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive + if not isinstance(all_of, NotSet): + kwargs["all_of"] = all_of + if not isinstance(any_of, NotSet): + kwargs["any_of"] = any_of + if not isinstance(fuzzy, NotSet): + kwargs["fuzzy"] = fuzzy + if not isinstance(match, NotSet): + kwargs["match"] = match + if not isinstance(prefix, NotSet): + kwargs["prefix"] = prefix + if not isinstance(wildcard, NotSet): + kwargs["wildcard"] = wildcard super().__init__(**kwargs) -class RankFeatureFunctionLogarithm(RankFeatureFunction): +class LikeDocument(AttrDict[Any]): """ - :arg scaling_factor: (required)Configurable scaling factor. + :arg doc: A document not present in the index. + :arg fields: No documentation available. + :arg _id: ID of a document. + :arg _index: Index of a document. + :arg per_field_analyzer: Overrides the default analyzer. + :arg routing: No documentation available. + :arg version: No documentation available. + :arg version_type: No documentation available. """ + doc: Any + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] + _id: Union[str, "NotSet"] + _index: Union[str, "NotSet"] + per_field_analyzer: Union[Mapping[Union[str, "InstrumentedField"], str], "NotSet"] + routing: Union[str, "NotSet"] + version: Union[int, "NotSet"] + version_type: Union[ + Literal["internal", "external", "external_gte", "force"], "NotSet" + ] + def __init__( - self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + self, + *, + doc: Any = NOT_SET, + fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, + _id: Union[str, "NotSet"] = NOT_SET, + _index: Union[str, "NotSet"] = NOT_SET, + per_field_analyzer: Union[ + Mapping[Union[str, "InstrumentedField"], str], "NotSet" + ] = NOT_SET, + routing: Union[str, "NotSet"] = NOT_SET, + version: Union[int, "NotSet"] = NOT_SET, + version_type: Union[ + Literal["internal", "external", "external_gte", "force"], "NotSet" + ] = NOT_SET, + **kwargs: Any, ): - if scaling_factor != NOT_SET: - kwargs["scaling_factor"] = scaling_factor - super().__init__(**kwargs) + if not isinstance(doc, NotSet): + kwargs["doc"] = doc + if not isinstance(fields, NotSet): + kwargs["fields"] = str(fields) + if not isinstance(_id, NotSet): + kwargs["_id"] = _id + if not isinstance(_index, NotSet): + kwargs["_index"] = _index + if not isinstance(per_field_analyzer, NotSet): + kwargs["per_field_analyzer"] = str(per_field_analyzer) + if not isinstance(routing, NotSet): + kwargs["routing"] = routing + if not isinstance(version, NotSet): + kwargs["version"] = version + if not isinstance(version_type, NotSet): + kwargs["version_type"] = version_type + super().__init__(kwargs) -class WildcardQuery(QueryBase): +class MatchBoolPrefixQuery(QueryBase): """ - :arg case_insensitive: Allows case insensitive matching of the pattern - with the indexed field values when set to true. Default is false - which means the case sensitivity of matching depends on the - underlying field’s mapping. - :arg rewrite: Method used to rewrite the query. - :arg value: Wildcard pattern for terms you wish to find in the - provided field. Required, when wildcard is not set. - :arg wildcard: Wildcard pattern for terms you wish to find in the - provided field. Required, when value is not set. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg fuzziness: Maximum edit distance allowed for matching. Can be + applied to the term subqueries constructed for all terms but the + final term. + :arg fuzzy_rewrite: Method used to rewrite the query. Can be applied + to the term subqueries constructed for all terms but the final + term. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). Can be applied to the term subqueries constructed for all + terms but the final term. + :arg max_expansions: Maximum number of terms to which the query will + expand. Can be applied to the term subqueries constructed for all + terms but the final term. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. Applied to the constructed bool + query. + :arg operator: Boolean logic used to interpret text in the query + value. Applied to the constructed bool query. + :arg prefix_length: Number of beginning characters left unchanged for + fuzzy matching. Can be applied to the term subqueries constructed + for all terms but the final term. + :arg query: (required)Terms you wish to find in the provided field. + The last term is used in a prefix query. """ + analyzer: Union[str, "NotSet"] + fuzziness: Union[str, int, "NotSet"] + fuzzy_rewrite: Union[str, "NotSet"] + fuzzy_transpositions: Union[bool, "NotSet"] + max_expansions: Union[int, "NotSet"] + minimum_should_match: Union[int, str, "NotSet"] + operator: Union[Literal["and", "or"], "NotSet"] + prefix_length: Union[int, "NotSet"] + query: Union[str, "NotSet"] + def __init__( self, *, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, - wildcard: Union[str, "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive - if rewrite != NOT_SET: - kwargs["rewrite"] = rewrite - if value != NOT_SET: - kwargs["value"] = value - if wildcard != NOT_SET: - kwargs["wildcard"] = wildcard + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(fuzziness, NotSet): + kwargs["fuzziness"] = fuzziness + if not isinstance(fuzzy_rewrite, NotSet): + kwargs["fuzzy_rewrite"] = fuzzy_rewrite + if not isinstance(fuzzy_transpositions, NotSet): + kwargs["fuzzy_transpositions"] = fuzzy_transpositions + if not isinstance(max_expansions, NotSet): + kwargs["max_expansions"] = max_expansions + if not isinstance(minimum_should_match, NotSet): + kwargs["minimum_should_match"] = minimum_should_match + if not isinstance(operator, NotSet): + kwargs["operator"] = operator + if not isinstance(prefix_length, NotSet): + kwargs["prefix_length"] = prefix_length + if not isinstance(query, NotSet): + kwargs["query"] = query super().__init__(**kwargs) -class CommonTermsQuery(QueryBase): +class MatchPhrasePrefixQuery(QueryBase): """ - :arg analyzer: No documentation available. - :arg cutoff_frequency: No documentation available. - :arg high_freq_operator: No documentation available. - :arg low_freq_operator: No documentation available. - :arg minimum_should_match: No documentation available. - :arg query: (required)No documentation available. + :arg analyzer: Analyzer used to convert text in the query value into + tokens. + :arg max_expansions: Maximum number of terms to which the last + provided term of the query value will expand. + :arg query: (required)Text you wish to find in the provided field. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg zero_terms_query: Indicates whether no documents are returned if + the analyzer removes all tokens, such as when using a `stop` + filter. """ + analyzer: Union[str, "NotSet"] + max_expansions: Union[int, "NotSet"] + query: Union[str, "NotSet"] + slop: Union[int, "NotSet"] + zero_terms_query: Union[Literal["all", "none"], "NotSet"] + def __init__( self, *, analyzer: Union[str, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + max_expansions: Union[int, "NotSet"] = NOT_SET, query: Union[str, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: + if not isinstance(analyzer, NotSet): kwargs["analyzer"] = analyzer - if cutoff_frequency != NOT_SET: - kwargs["cutoff_frequency"] = cutoff_frequency - if high_freq_operator != NOT_SET: - kwargs["high_freq_operator"] = high_freq_operator - if low_freq_operator != NOT_SET: - kwargs["low_freq_operator"] = low_freq_operator - if minimum_should_match != NOT_SET: - kwargs["minimum_should_match"] = minimum_should_match - if query != NOT_SET: + if not isinstance(max_expansions, NotSet): + kwargs["max_expansions"] = max_expansions + if not isinstance(query, NotSet): kwargs["query"] = query + if not isinstance(slop, NotSet): + kwargs["slop"] = slop + if not isinstance(zero_terms_query, NotSet): + kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class TermsSetQuery(QueryBase): +class MatchPhraseQuery(QueryBase): """ - :arg minimum_should_match_field: Numeric field containing the number - of matching terms required to return a document. - :arg minimum_should_match_script: Custom script containing the number - of matching terms required to return a document. - :arg terms: (required)Array of terms you wish to find in the provided - field. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg query: (required)Query terms that are analyzed and turned into a + phrase query. + :arg slop: Maximum number of positions allowed between matching + tokens. + :arg zero_terms_query: Indicates whether no documents are returned if + the `analyzer` removes all tokens, such as when using a `stop` + filter. """ + analyzer: Union[str, "NotSet"] + query: Union[str, "NotSet"] + slop: Union[int, "NotSet"] + zero_terms_query: Union[Literal["all", "none"], "NotSet"] + def __init__( self, *, - minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - minimum_should_match_script: Union[ - "i.Script", Dict[str, Any], "NotSet" - ] = NOT_SET, - terms: Union[List[str], "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, + zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if minimum_should_match_field != NOT_SET: - kwargs["minimum_should_match_field"] = str(minimum_should_match_field) - if minimum_should_match_script != NOT_SET: - kwargs["minimum_should_match_script"] = minimum_should_match_script - if terms != NOT_SET: - kwargs["terms"] = terms + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(query, NotSet): + kwargs["query"] = query + if not isinstance(slop, NotSet): + kwargs["slop"] = slop + if not isinstance(zero_terms_query, NotSet): + kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class MatchPhrasePrefixQuery(QueryBase): +class MatchQuery(QueryBase): """ - :arg analyzer: Analyzer used to convert text in the query value into - tokens. - :arg max_expansions: Maximum number of terms to which the last - provided term of the query value will expand. - :arg query: (required)Text you wish to find in the provided field. - :arg slop: Maximum number of positions allowed between matching - tokens. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. + :arg auto_generate_synonyms_phrase_query: If `true`, match phrase + queries are automatically created for multi-term synonyms. + :arg cutoff_frequency: No documentation available. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg fuzzy_rewrite: Method used to rewrite the query. + :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include + transpositions of two adjacent characters (for example, `ab` to + `ba`). + :arg lenient: If `true`, format-based errors, such as providing a text + query value for a numeric field, are ignored. + :arg max_expansions: Maximum number of terms to which the query will + expand. + :arg minimum_should_match: Minimum number of clauses that must match + for a document to be returned. + :arg operator: Boolean logic used to interpret text in the query + value. + :arg prefix_length: Number of beginning characters left unchanged for + fuzzy matching. + :arg query: (required)Text, number, boolean value or date you wish to + find in the provided field. :arg zero_terms_query: Indicates whether no documents are returned if - the analyzer removes all tokens, such as when using a `stop` + the `analyzer` removes all tokens, such as when using a `stop` filter. """ + analyzer: Union[str, "NotSet"] + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] + cutoff_frequency: Union[float, "NotSet"] + fuzziness: Union[str, int, "NotSet"] + fuzzy_rewrite: Union[str, "NotSet"] + fuzzy_transpositions: Union[bool, "NotSet"] + lenient: Union[bool, "NotSet"] + max_expansions: Union[int, "NotSet"] + minimum_should_match: Union[int, str, "NotSet"] + operator: Union[Literal["and", "or"], "NotSet"] + prefix_length: Union[int, "NotSet"] + query: Union[str, float, bool, "NotSet"] + zero_terms_query: Union[Literal["all", "none"], "NotSet"] + def __init__( self, *, analyzer: Union[str, "NotSet"] = NOT_SET, + auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, + cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, + fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, + lenient: Union[bool, "NotSet"] = NOT_SET, max_expansions: Union[int, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, + minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, + operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + query: Union[str, float, bool, "NotSet"] = NOT_SET, zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: + if not isinstance(analyzer, NotSet): kwargs["analyzer"] = analyzer - if max_expansions != NOT_SET: + if not isinstance(auto_generate_synonyms_phrase_query, NotSet): + kwargs["auto_generate_synonyms_phrase_query"] = ( + auto_generate_synonyms_phrase_query + ) + if not isinstance(cutoff_frequency, NotSet): + kwargs["cutoff_frequency"] = cutoff_frequency + if not isinstance(fuzziness, NotSet): + kwargs["fuzziness"] = fuzziness + if not isinstance(fuzzy_rewrite, NotSet): + kwargs["fuzzy_rewrite"] = fuzzy_rewrite + if not isinstance(fuzzy_transpositions, NotSet): + kwargs["fuzzy_transpositions"] = fuzzy_transpositions + if not isinstance(lenient, NotSet): + kwargs["lenient"] = lenient + if not isinstance(max_expansions, NotSet): kwargs["max_expansions"] = max_expansions - if query != NOT_SET: + if not isinstance(minimum_should_match, NotSet): + kwargs["minimum_should_match"] = minimum_should_match + if not isinstance(operator, NotSet): + kwargs["operator"] = operator + if not isinstance(prefix_length, NotSet): + kwargs["prefix_length"] = prefix_length + if not isinstance(query, NotSet): kwargs["query"] = query - if slop != NOT_SET: - kwargs["slop"] = slop - if zero_terms_query != NOT_SET: + if not isinstance(zero_terms_query, NotSet): kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) -class LikeDocument(AttrDict[Any]): +class PinnedDoc(AttrDict[Any]): """ - :arg doc: A document not present in the index. - :arg fields: No documentation available. - :arg _id: ID of a document. - :arg _index: Index of a document. - :arg per_field_analyzer: Overrides the default analyzer. - :arg routing: No documentation available. - :arg version: No documentation available. - :arg version_type: No documentation available. + :arg _id: (required)The unique document ID. + :arg _index: (required)The index that contains the document. """ + _id: Union[str, "NotSet"] + _index: Union[str, "NotSet"] + def __init__( self, *, - doc: Any = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, _id: Union[str, "NotSet"] = NOT_SET, _index: Union[str, "NotSet"] = NOT_SET, - per_field_analyzer: Union[ - Mapping[Union[str, "InstrumentedField"], str], "NotSet" - ] = NOT_SET, - routing: Union[str, "NotSet"] = NOT_SET, - version: Union[int, "NotSet"] = NOT_SET, - version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "NotSet" - ] = NOT_SET, **kwargs: Any, ): - if doc != NOT_SET: - kwargs["doc"] = doc - if fields != NOT_SET: - kwargs["fields"] = str(fields) - if _id != NOT_SET: + if not isinstance(_id, NotSet): kwargs["_id"] = _id - if _index != NOT_SET: + if not isinstance(_index, NotSet): kwargs["_index"] = _index - if per_field_analyzer != NOT_SET: - kwargs["per_field_analyzer"] = str(per_field_analyzer) - if routing != NOT_SET: - kwargs["routing"] = routing - if version != NOT_SET: - kwargs["version"] = version - if version_type != NOT_SET: - kwargs["version_type"] = version_type super().__init__(kwargs) -class IntervalsQuery(QueryBase): +class PrefixQuery(QueryBase): """ - :arg all_of: Returns matches that span a combination of other rules. - :arg any_of: Returns intervals produced by any of its sub-rules. - :arg fuzzy: Matches terms that are similar to the provided term, - within an edit distance defined by `fuzziness`. - :arg match: Matches analyzed text. - :arg prefix: Matches terms that start with a specified set of - characters. - :arg wildcard: Matches terms using a wildcard pattern. + :arg rewrite: Method used to rewrite the query. + :arg value: (required)Beginning characters of terms you wish to find + in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. Default is + `false` which means the case sensitivity of matching depends on + the underlying field’s mapping. """ + rewrite: Union[str, "NotSet"] + value: Union[str, "NotSet"] + case_insensitive: Union[bool, "NotSet"] + def __init__( self, *, - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, - match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if all_of != NOT_SET: - kwargs["all_of"] = all_of - if any_of != NOT_SET: - kwargs["any_of"] = any_of - if fuzzy != NOT_SET: - kwargs["fuzzy"] = fuzzy - if match != NOT_SET: - kwargs["match"] = match - if prefix != NOT_SET: - kwargs["prefix"] = prefix - if wildcard != NOT_SET: - kwargs["wildcard"] = wildcard + if not isinstance(rewrite, NotSet): + kwargs["rewrite"] = rewrite + if not isinstance(value, NotSet): + kwargs["value"] = value + if not isinstance(case_insensitive, NotSet): + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) + + +class QueryVectorBuilder(AttrDict[Any]): + """ + :arg text_embedding: No documentation available. + """ + + text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(text_embedding, NotSet): + kwargs["text_embedding"] = text_embedding + super().__init__(kwargs) + + +class RankFeatureFunction(AttrDict[Any]): + pass + + +class RankFeatureFunctionLinear(RankFeatureFunction): + pass + + +class RankFeatureFunctionLogarithm(RankFeatureFunction): + """ + :arg scaling_factor: (required)Configurable scaling factor. + """ + + scaling_factor: Union[float, "NotSet"] + + def __init__( + self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + ): + if not isinstance(scaling_factor, NotSet): + kwargs["scaling_factor"] = scaling_factor + super().__init__(**kwargs) + + +class RankFeatureFunctionSaturation(RankFeatureFunction): + """ + :arg pivot: Configurable pivot value so that the result will be less + than 0.5. + """ + + pivot: Union[float, "NotSet"] + + def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): + if not isinstance(pivot, NotSet): + kwargs["pivot"] = pivot super().__init__(**kwargs) -class TermQuery(QueryBase): +class RankFeatureFunctionSigmoid(RankFeatureFunction): """ - :arg value: (required)Term you wish to find in the provided field. - :arg case_insensitive: Allows ASCII case insensitive matching of the - value with the indexed field values when set to `true`. When - `false`, the case sensitivity of matching depends on the - underlying field’s mapping. + :arg pivot: (required)Configurable pivot value so that the result will + be less than 0.5. + :arg exponent: (required)Configurable Exponent. """ + pivot: Union[float, "NotSet"] + exponent: Union[float, "NotSet"] + def __init__( self, *, - value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, + pivot: Union[float, "NotSet"] = NOT_SET, + exponent: Union[float, "NotSet"] = NOT_SET, **kwargs: Any, ): - if value != NOT_SET: - kwargs["value"] = value - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive + if not isinstance(pivot, NotSet): + kwargs["pivot"] = pivot + if not isinstance(exponent, NotSet): + kwargs["exponent"] = exponent super().__init__(**kwargs) -class FuzzyQuery(QueryBase): +class RegexpQuery(QueryBase): """ - :arg max_expansions: Maximum number of variations created. - :arg prefix_length: Number of beginning characters left unchanged when - creating expansions. - :arg rewrite: Number of beginning characters left unchanged when - creating expansions. - :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example `ab` to `ba`). - :arg fuzziness: Maximum edit distance allowed for matching. - :arg value: (required)Term you wish to find in the provided field. + :arg case_insensitive: Allows case insensitive matching of the regular + expression value with the indexed field values when set to `true`. + When `false`, case sensitivity of matching depends on the + underlying field’s mapping. + :arg flags: Enables optional operators for the regular expression. + :arg max_determinized_states: Maximum number of automaton states + required for the query. + :arg rewrite: Method used to rewrite the query. + :arg value: (required)Regular expression for terms you wish to find in + the provided field. """ + case_insensitive: Union[bool, "NotSet"] + flags: Union[str, "NotSet"] + max_determinized_states: Union[int, "NotSet"] + rewrite: Union[str, "NotSet"] + value: Union[str, "NotSet"] + def __init__( self, *, - max_expansions: Union[int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + flags: Union[str, "NotSet"] = NOT_SET, + max_determinized_states: Union[int, "NotSet"] = NOT_SET, rewrite: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - value: Union[str, float, bool, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if max_expansions != NOT_SET: - kwargs["max_expansions"] = max_expansions - if prefix_length != NOT_SET: - kwargs["prefix_length"] = prefix_length - if rewrite != NOT_SET: + if not isinstance(case_insensitive, NotSet): + kwargs["case_insensitive"] = case_insensitive + if not isinstance(flags, NotSet): + kwargs["flags"] = flags + if not isinstance(max_determinized_states, NotSet): + kwargs["max_determinized_states"] = max_determinized_states + if not isinstance(rewrite, NotSet): kwargs["rewrite"] = rewrite - if transpositions != NOT_SET: - kwargs["transpositions"] = transpositions - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if value != NOT_SET: + if not isinstance(value, NotSet): kwargs["value"] = value super().__init__(**kwargs) -class MatchBoolPrefixQuery(QueryBase): +class Script(AttrDict[Any]): """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. - :arg fuzziness: Maximum edit distance allowed for matching. Can be - applied to the term subqueries constructed for all terms but the - final term. - :arg fuzzy_rewrite: Method used to rewrite the query. Can be applied - to the term subqueries constructed for all terms but the final - term. - :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include - transpositions of two adjacent characters (for example, `ab` to - `ba`). Can be applied to the term subqueries constructed for all - terms but the final term. - :arg max_expansions: Maximum number of terms to which the query will - expand. Can be applied to the term subqueries constructed for all - terms but the final term. - :arg minimum_should_match: Minimum number of clauses that must match - for a document to be returned. Applied to the constructed bool - query. - :arg operator: Boolean logic used to interpret text in the query - value. Applied to the constructed bool query. - :arg prefix_length: Number of beginning characters left unchanged for - fuzzy matching. Can be applied to the term subqueries constructed - for all terms but the final term. - :arg query: (required)Terms you wish to find in the provided field. - The last term is used in a prefix query. + :arg source: The script source. + :arg id: The `id` for a stored script. + :arg params: Specifies any named parameters that are passed into the + script as variables. Use parameters instead of hard-coded values + to decrease compile time. + :arg lang: Specifies the language the script is written in. + :arg options: No documentation available. """ - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - max_expansions: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if fuzzy_rewrite != NOT_SET: - kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if fuzzy_transpositions != NOT_SET: - kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if max_expansions != NOT_SET: - kwargs["max_expansions"] = max_expansions - if minimum_should_match != NOT_SET: - kwargs["minimum_should_match"] = minimum_should_match - if operator != NOT_SET: - kwargs["operator"] = operator - if prefix_length != NOT_SET: - kwargs["prefix_length"] = prefix_length - if query != NOT_SET: - kwargs["query"] = query - super().__init__(**kwargs) - - -class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - -class PinnedDoc(AttrDict[Any]): - """ - :arg _id: (required)The unique document ID. - :arg _index: (required)The index that contains the document. - """ + source: Union[str, "NotSet"] + id: Union[str, "NotSet"] + params: Union[Mapping[str, Any], "NotSet"] + lang: Union[Literal["painless", "expression", "mustache", "java"], "NotSet"] + options: Union[Mapping[str, str], "NotSet"] def __init__( self, *, - _id: Union[str, "NotSet"] = NOT_SET, - _index: Union[str, "NotSet"] = NOT_SET, + source: Union[str, "NotSet"] = NOT_SET, + id: Union[str, "NotSet"] = NOT_SET, + params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + lang: Union[ + Literal["painless", "expression", "mustache", "java"], "NotSet" + ] = NOT_SET, + options: Union[Mapping[str, str], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _id != NOT_SET: - kwargs["_id"] = _id - if _index != NOT_SET: - kwargs["_index"] = _index + if not isinstance(source, NotSet): + kwargs["source"] = source + if not isinstance(id, NotSet): + kwargs["id"] = id + if not isinstance(params, NotSet): + kwargs["params"] = params + if not isinstance(lang, NotSet): + kwargs["lang"] = lang + if not isinstance(options, NotSet): + kwargs["options"] = options super().__init__(kwargs) -class InnerHits(AttrDict[Any]): +class SpanQuery(AttrDict[Any]): """ - :arg name: The name for the particular inner hit definition in the - response. Useful when a search request contains multiple inner - hits. - :arg size: The maximum number of hits to return per `inner_hits`. - :arg from: Inner hit starting document offset. - :arg collapse: No documentation available. - :arg docvalue_fields: No documentation available. - :arg explain: No documentation available. - :arg highlight: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg script_fields: No documentation available. - :arg seq_no_primary_term: No documentation available. - :arg fields: No documentation available. - :arg sort: How the inner hits should be sorted per `inner_hits`. By - default, inner hits are sorted by score. - :arg _source: No documentation available. - :arg stored_fields: No documentation available. - :arg track_scores: No documentation available. - :arg version: No documentation available. + :arg span_containing: Accepts a list of span queries, but only returns + those spans which also match a second span query. + :arg span_field_masking: Allows queries like `span_near` or `span_or` + across different fields. + :arg span_first: Accepts another span query whose matches must appear + within the first N positions of the field. + :arg span_gap: No documentation available. + :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, + `regexp`, or `fuzzy` query. + :arg span_near: Accepts multiple span queries whose matches must be + within the specified distance of each other, and possibly in the + same order. + :arg span_not: Wraps another span query, and excludes any documents + which match that query. + :arg span_or: Combines multiple span queries and returns documents + which match any of the specified queries. + :arg span_term: The equivalent of the `term` query but for use with + other span queries. + :arg span_within: The result from a single span query is returned as + long is its span falls within the spans returned by a list of + other span queries. """ + span_containing: Union["i.SpanContainingQuery", Dict[str, Any], "NotSet"] + span_field_masking: Union["i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet"] + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] + span_gap: Union[Mapping[Union[str, "InstrumentedField"], int], "NotSet"] + span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] + span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] + span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] + span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] + span_term: Union[ + Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], + Dict[str, Any], + "NotSet", + ] + span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] + def __init__( self, *, - name: Union[str, "NotSet"] = NOT_SET, - size: Union[int, "NotSet"] = NOT_SET, - from_: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, - docvalue_fields: Union[ - List["i.FieldAndFormat"], Dict[str, Any], "NotSet" + span_containing: Union[ + "i.SpanContainingQuery", Dict[str, Any], "NotSet" ] = NOT_SET, - explain: Union[bool, "NotSet"] = NOT_SET, - highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], - Dict[str, Any], - "NotSet", + span_field_masking: Union[ + "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" ] = NOT_SET, - seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, - fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_gap: Union[ + Mapping[Union[str, "InstrumentedField"], int], "NotSet" ] = NOT_SET, - sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, + span_term: Union[ + Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], Dict[str, Any], "NotSet", ] = NOT_SET, - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, - stored_fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - track_scores: Union[bool, "NotSet"] = NOT_SET, - version: Union[bool, "NotSet"] = NOT_SET, + span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if name != NOT_SET: - kwargs["name"] = name - if size != NOT_SET: - kwargs["size"] = size - if from_ != NOT_SET: - kwargs["from_"] = from_ - if collapse != NOT_SET: - kwargs["collapse"] = collapse - if docvalue_fields != NOT_SET: - kwargs["docvalue_fields"] = docvalue_fields - if explain != NOT_SET: - kwargs["explain"] = explain - if highlight != NOT_SET: - kwargs["highlight"] = highlight - if ignore_unmapped != NOT_SET: - kwargs["ignore_unmapped"] = ignore_unmapped - if script_fields != NOT_SET: - kwargs["script_fields"] = str(script_fields) - if seq_no_primary_term != NOT_SET: - kwargs["seq_no_primary_term"] = seq_no_primary_term - if fields != NOT_SET: - kwargs["fields"] = str(fields) - if sort != NOT_SET: - kwargs["sort"] = str(sort) - if _source != NOT_SET: - kwargs["_source"] = _source - if stored_fields != NOT_SET: - kwargs["stored_fields"] = str(stored_fields) - if track_scores != NOT_SET: - kwargs["track_scores"] = track_scores - if version != NOT_SET: - kwargs["version"] = version + if not isinstance(span_containing, NotSet): + kwargs["span_containing"] = span_containing + if not isinstance(span_field_masking, NotSet): + kwargs["span_field_masking"] = span_field_masking + if not isinstance(span_first, NotSet): + kwargs["span_first"] = span_first + if not isinstance(span_gap, NotSet): + kwargs["span_gap"] = str(span_gap) + if not isinstance(span_multi, NotSet): + kwargs["span_multi"] = span_multi + if not isinstance(span_near, NotSet): + kwargs["span_near"] = span_near + if not isinstance(span_not, NotSet): + kwargs["span_not"] = span_not + if not isinstance(span_or, NotSet): + kwargs["span_or"] = span_or + if not isinstance(span_term, NotSet): + kwargs["span_term"] = str(span_term) + if not isinstance(span_within, NotSet): + kwargs["span_within"] = span_within super().__init__(kwargs) -class RegexpQuery(QueryBase): +class SpanTermQuery(QueryBase): """ - :arg case_insensitive: Allows case insensitive matching of the regular - expression value with the indexed field values when set to `true`. - When `false`, case sensitivity of matching depends on the + :arg value: (required)No documentation available. + """ + + value: Union[str, "NotSet"] + + def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): + if not isinstance(value, NotSet): + kwargs["value"] = value + super().__init__(**kwargs) + + +class TermQuery(QueryBase): + """ + :arg value: (required)Term you wish to find in the provided field. + :arg case_insensitive: Allows ASCII case insensitive matching of the + value with the indexed field values when set to `true`. When + `false`, the case sensitivity of matching depends on the underlying field’s mapping. - :arg flags: Enables optional operators for the regular expression. - :arg max_determinized_states: Maximum number of automaton states - required for the query. - :arg rewrite: Method used to rewrite the query. - :arg value: (required)Regular expression for terms you wish to find in - the provided field. """ + value: Union[int, float, str, bool, None, Any, "NotSet"] + case_insensitive: Union[bool, "NotSet"] + def __init__( self, *, + value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, case_insensitive: Union[bool, "NotSet"] = NOT_SET, - flags: Union[str, "NotSet"] = NOT_SET, - max_determinized_states: Union[int, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if case_insensitive != NOT_SET: - kwargs["case_insensitive"] = case_insensitive - if flags != NOT_SET: - kwargs["flags"] = flags - if max_determinized_states != NOT_SET: - kwargs["max_determinized_states"] = max_determinized_states - if rewrite != NOT_SET: - kwargs["rewrite"] = rewrite - if value != NOT_SET: + if not isinstance(value, NotSet): kwargs["value"] = value + if not isinstance(case_insensitive, NotSet): + kwargs["case_insensitive"] = case_insensitive + super().__init__(**kwargs) + + +class TermsSetQuery(QueryBase): + """ + :arg minimum_should_match_field: Numeric field containing the number + of matching terms required to return a document. + :arg minimum_should_match_script: Custom script containing the number + of matching terms required to return a document. + :arg terms: (required)Array of terms you wish to find in the provided + field. + """ + + minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] + minimum_should_match_script: Union["i.Script", Dict[str, Any], "NotSet"] + terms: Union[List[str], "NotSet"] + + def __init__( + self, + *, + minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + minimum_should_match_script: Union[ + "i.Script", Dict[str, Any], "NotSet" + ] = NOT_SET, + terms: Union[List[str], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(minimum_should_match_field, NotSet): + kwargs["minimum_should_match_field"] = str(minimum_should_match_field) + if not isinstance(minimum_should_match_script, NotSet): + kwargs["minimum_should_match_script"] = minimum_should_match_script + if not isinstance(terms, NotSet): + kwargs["terms"] = terms super().__init__(**kwargs) @@ -1007,6 +1123,10 @@ class TextExpansionQuery(QueryBase): :arg pruning_config: Token pruning configurations """ + model_id: Union[str, "NotSet"] + model_text: Union[str, "NotSet"] + pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "NotSet"] + def __init__( self, *, @@ -1017,29 +1137,49 @@ def __init__( ] = NOT_SET, **kwargs: Any, ): - if model_id != NOT_SET: + if not isinstance(model_id, NotSet): kwargs["model_id"] = model_id - if model_text != NOT_SET: + if not isinstance(model_text, NotSet): kwargs["model_text"] = model_text - if pruning_config != NOT_SET: + if not isinstance(pruning_config, NotSet): kwargs["pruning_config"] = pruning_config super().__init__(**kwargs) -class RankFeatureFunctionLinear(RankFeatureFunction): - pass - - -class RankFeatureFunctionSaturation(RankFeatureFunction): +class TokenPruningConfig(AttrDict[Any]): """ - :arg pivot: Configurable pivot value so that the result will be less - than 0.5. + :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than + this threshold times the average frequency of all tokens in the + specified field are considered outliers and pruned. + :arg tokens_weight_threshold: Tokens whose weight is less than this + threshold are considered nonsignificant and pruned. + :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs + only scoring kept tokens. """ - def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): - if pivot != NOT_SET: - kwargs["pivot"] = pivot - super().__init__(**kwargs) + tokens_freq_ratio_threshold: Union[int, "NotSet"] + tokens_weight_threshold: Union[float, "NotSet"] + only_score_pruned_tokens: Union[bool, "NotSet"] + + def __init__( + self, + *, + tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, + tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, + only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(tokens_freq_ratio_threshold, NotSet): + kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold + if not isinstance(tokens_weight_threshold, NotSet): + kwargs["tokens_weight_threshold"] = tokens_weight_threshold + if not isinstance(only_score_pruned_tokens, NotSet): + kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens + super().__init__(kwargs) + + +class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): + pass class WeightedTokensQuery(QueryBase): @@ -1048,6 +1188,9 @@ class WeightedTokensQuery(QueryBase): :arg pruning_config: Token pruning configurations """ + tokens: Union[Mapping[str, float], "NotSet"] + pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "NotSet"] + def __init__( self, *, @@ -1057,227 +1200,537 @@ def __init__( ] = NOT_SET, **kwargs: Any, ): - if tokens != NOT_SET: + if not isinstance(tokens, NotSet): kwargs["tokens"] = tokens - if pruning_config != NOT_SET: + if not isinstance(pruning_config, NotSet): kwargs["pruning_config"] = pruning_config super().__init__(**kwargs) -class TextEmbedding(AttrDict[Any]): +class WildcardQuery(QueryBase): """ - :arg model_id: (required)No documentation available. - :arg model_text: (required)No documentation available. + :arg case_insensitive: Allows case insensitive matching of the pattern + with the indexed field values when set to true. Default is false + which means the case sensitivity of matching depends on the + underlying field’s mapping. + :arg rewrite: Method used to rewrite the query. + :arg value: Wildcard pattern for terms you wish to find in the + provided field. Required, when wildcard is not set. + :arg wildcard: Wildcard pattern for terms you wish to find in the + provided field. Required, when value is not set. """ + case_insensitive: Union[bool, "NotSet"] + rewrite: Union[str, "NotSet"] + value: Union[str, "NotSet"] + wildcard: Union[str, "NotSet"] + def __init__( self, *, - model_id: Union[str, "NotSet"] = NOT_SET, - model_text: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "NotSet"] = NOT_SET, + rewrite: Union[str, "NotSet"] = NOT_SET, + value: Union[str, "NotSet"] = NOT_SET, + wildcard: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if model_id != NOT_SET: - kwargs["model_id"] = model_id - if model_text != NOT_SET: - kwargs["model_text"] = model_text + if not isinstance(case_insensitive, NotSet): + kwargs["case_insensitive"] = case_insensitive + if not isinstance(rewrite, NotSet): + kwargs["rewrite"] = rewrite + if not isinstance(value, NotSet): + kwargs["value"] = value + if not isinstance(wildcard, NotSet): + kwargs["wildcard"] = wildcard + super().__init__(**kwargs) + + +class ScriptField(AttrDict[Any]): + """ + :arg script: (required)No documentation available. + :arg ignore_failure: No documentation available. + """ + + script: Union["i.Script", Dict[str, Any], "NotSet"] + ignore_failure: Union[bool, "NotSet"] + + def __init__( + self, + *, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_failure: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(script, NotSet): + kwargs["script"] = script + if not isinstance(ignore_failure, NotSet): + kwargs["ignore_failure"] = ignore_failure super().__init__(kwargs) -class SpanOrQuery(QueryBase): +class FieldAndFormat(AttrDict[Any]): """ - :arg clauses: (required)Array of one or more other span type queries. + :arg field: (required)Wildcard pattern. The request returns values for + field names matching this pattern. + :arg format: Format in which the values are returned. + :arg include_unmapped: No documentation available. + """ + + field: Union[str, "InstrumentedField", "NotSet"] + format: Union[str, "NotSet"] + include_unmapped: Union[bool, "NotSet"] + + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + format: Union[str, "NotSet"] = NOT_SET, + include_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(field, NotSet): + kwargs["field"] = str(field) + if not isinstance(format, NotSet): + kwargs["format"] = format + if not isinstance(include_unmapped, NotSet): + kwargs["include_unmapped"] = include_unmapped + super().__init__(kwargs) + + +class SortOptions(AttrDict[Any]): + """ + :arg _score: No documentation available. + :arg _doc: No documentation available. + :arg _geo_distance: No documentation available. + :arg _script: No documentation available. + """ + + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(_score, NotSet): + kwargs["_score"] = _score + if not isinstance(_doc, NotSet): + kwargs["_doc"] = _doc + if not isinstance(_geo_distance, NotSet): + kwargs["_geo_distance"] = _geo_distance + if not isinstance(_script, NotSet): + kwargs["_script"] = _script + super().__init__(kwargs) + + +class HighlightBase(AttrDict[Any]): + """ + :arg type: No documentation available. + :arg boundary_chars: A string that contains each boundary character. + :arg boundary_max_scan: How far to scan for boundary characters. + :arg boundary_scanner: Specifies how to break the highlighted + fragments: chars, sentence, or word. Only valid for the unified + and fvh highlighters. Defaults to `sentence` for the `unified` + highlighter. Defaults to `chars` for the `fvh` highlighter. + :arg boundary_scanner_locale: Controls which locale is used to search + for sentence and word boundaries. This parameter takes a form of a + language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + :arg force_source: No documentation available. + :arg fragmenter: Specifies how text should be broken up in highlight + snippets: `simple` or `span`. Only valid for the `plain` + highlighter. + :arg fragment_size: The size of the highlighted fragment in + characters. + :arg highlight_filter: No documentation available. + :arg highlight_query: Highlight matches for a query other than the + search query. This is especially useful if you use a rescore query + because those are not taken into account by highlighting by + default. + :arg max_fragment_length: No documentation available. + :arg max_analyzed_offset: If set to a non-negative value, highlighting + stops at this defined maximum limit. The rest of the text is not + processed, thus not highlighted and no error is returned The + `max_analyzed_offset` query setting does not override the + `index.highlight.max_analyzed_offset` setting, which prevails when + it’s set to lower value than the query setting. + :arg no_match_size: The amount of text you want to return from the + beginning of the field if there are no matching fragments to + highlight. + :arg number_of_fragments: The maximum number of fragments to return. + If the number of fragments is set to `0`, no fragments are + returned. Instead, the entire field contents are highlighted and + returned. This can be handy when you need to highlight short texts + such as a title or address, but fragmentation is not required. If + `number_of_fragments` is `0`, `fragment_size` is ignored. + :arg options: No documentation available. + :arg order: Sorts highlighted fragments by score when set to `score`. + By default, fragments will be output in the order they appear in + the field (order: `none`). Setting this option to `score` will + output the most relevant fragments first. Each highlighter applies + its own logic to compute relevancy scores. + :arg phrase_limit: Controls the number of matching phrases in a + document that are considered. Prevents the `fvh` highlighter from + analyzing too many phrases and consuming too much memory. When + using `matched_fields`, `phrase_limit` phrases per matched field + are considered. Raising the limit increases query time and + consumes more memory. Only supported by the `fvh` highlighter. + :arg post_tags: Use in conjunction with `pre_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg pre_tags: Use in conjunction with `post_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg require_field_match: By default, only fields that contains a + query match are highlighted. Set to `false` to highlight all + fields. + :arg tags_schema: Set to `styled` to use the built-in tag schema. """ + type: Union[Literal["plain", "fvh", "unified"], "NotSet"] + boundary_chars: Union[str, "NotSet"] + boundary_max_scan: Union[int, "NotSet"] + boundary_scanner: Union[Literal["chars", "sentence", "word"], "NotSet"] + boundary_scanner_locale: Union[str, "NotSet"] + force_source: Union[bool, "NotSet"] + fragmenter: Union[Literal["simple", "span"], "NotSet"] + fragment_size: Union[int, "NotSet"] + highlight_filter: Union[bool, "NotSet"] + highlight_query: Union[Query, "NotSet"] + max_fragment_length: Union[int, "NotSet"] + max_analyzed_offset: Union[int, "NotSet"] + no_match_size: Union[int, "NotSet"] + number_of_fragments: Union[int, "NotSet"] + options: Union[Mapping[str, Any], "NotSet"] + order: Union[Literal["score"], "NotSet"] + phrase_limit: Union[int, "NotSet"] + post_tags: Union[List[str], "NotSet"] + pre_tags: Union[List[str], "NotSet"] + require_field_match: Union[bool, "NotSet"] + tags_schema: Union[Literal["styled"], "NotSet"] + def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, + boundary_chars: Union[str, "NotSet"] = NOT_SET, + boundary_max_scan: Union[int, "NotSet"] = NOT_SET, + boundary_scanner: Union[ + Literal["chars", "sentence", "word"], "NotSet" + ] = NOT_SET, + boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, + force_source: Union[bool, "NotSet"] = NOT_SET, + fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, + fragment_size: Union[int, "NotSet"] = NOT_SET, + highlight_filter: Union[bool, "NotSet"] = NOT_SET, + highlight_query: Union[Query, "NotSet"] = NOT_SET, + max_fragment_length: Union[int, "NotSet"] = NOT_SET, + max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, + no_match_size: Union[int, "NotSet"] = NOT_SET, + number_of_fragments: Union[int, "NotSet"] = NOT_SET, + options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + order: Union[Literal["score"], "NotSet"] = NOT_SET, + phrase_limit: Union[int, "NotSet"] = NOT_SET, + post_tags: Union[List[str], "NotSet"] = NOT_SET, + pre_tags: Union[List[str], "NotSet"] = NOT_SET, + require_field_match: Union[bool, "NotSet"] = NOT_SET, + tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, **kwargs: Any, ): - if clauses != NOT_SET: - kwargs["clauses"] = clauses - super().__init__(**kwargs) + if not isinstance(type, NotSet): + kwargs["type"] = type + if not isinstance(boundary_chars, NotSet): + kwargs["boundary_chars"] = boundary_chars + if not isinstance(boundary_max_scan, NotSet): + kwargs["boundary_max_scan"] = boundary_max_scan + if not isinstance(boundary_scanner, NotSet): + kwargs["boundary_scanner"] = boundary_scanner + if not isinstance(boundary_scanner_locale, NotSet): + kwargs["boundary_scanner_locale"] = boundary_scanner_locale + if not isinstance(force_source, NotSet): + kwargs["force_source"] = force_source + if not isinstance(fragmenter, NotSet): + kwargs["fragmenter"] = fragmenter + if not isinstance(fragment_size, NotSet): + kwargs["fragment_size"] = fragment_size + if not isinstance(highlight_filter, NotSet): + kwargs["highlight_filter"] = highlight_filter + if not isinstance(highlight_query, NotSet): + kwargs["highlight_query"] = highlight_query + if not isinstance(max_fragment_length, NotSet): + kwargs["max_fragment_length"] = max_fragment_length + if not isinstance(max_analyzed_offset, NotSet): + kwargs["max_analyzed_offset"] = max_analyzed_offset + if not isinstance(no_match_size, NotSet): + kwargs["no_match_size"] = no_match_size + if not isinstance(number_of_fragments, NotSet): + kwargs["number_of_fragments"] = number_of_fragments + if not isinstance(options, NotSet): + kwargs["options"] = options + if not isinstance(order, NotSet): + kwargs["order"] = order + if not isinstance(phrase_limit, NotSet): + kwargs["phrase_limit"] = phrase_limit + if not isinstance(post_tags, NotSet): + kwargs["post_tags"] = post_tags + if not isinstance(pre_tags, NotSet): + kwargs["pre_tags"] = pre_tags + if not isinstance(require_field_match, NotSet): + kwargs["require_field_match"] = require_field_match + if not isinstance(tags_schema, NotSet): + kwargs["tags_schema"] = tags_schema + super().__init__(kwargs) -class SpanMultiTermQuery(QueryBase): +class Highlight(HighlightBase): """ - :arg match: (required)Should be a multi term query (one of `wildcard`, - `fuzzy`, `prefix`, `range`, or `regexp` query). + :arg encoder: No documentation available. + :arg fields: (required)No documentation available. """ - def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): - if match != NOT_SET: - kwargs["match"] = match - super().__init__(**kwargs) - - -class SpanContainingQuery(QueryBase): - """ - :arg big: (required)Can be any span query. Matching spans from `big` - that contain matches from `little` are returned. - :arg little: (required)Can be any span query. Matching spans from - `big` that contain matches from `little` are returned. - """ + encoder: Union[Literal["default", "html"], "NotSet"] + fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Dict[str, Any], + "NotSet", + ] def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, + fields: Union[ + Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Dict[str, Any], + "NotSet", + ] = NOT_SET, **kwargs: Any, ): - if big != NOT_SET: - kwargs["big"] = big - if little != NOT_SET: - kwargs["little"] = little + if not isinstance(encoder, NotSet): + kwargs["encoder"] = encoder + if not isinstance(fields, NotSet): + kwargs["fields"] = str(fields) super().__init__(**kwargs) -class SpanFirstQuery(QueryBase): +class FieldCollapse(AttrDict[Any]): """ - :arg end: (required)Controls the maximum end position permitted in a - match. - :arg match: (required)Can be any other span type query. + :arg field: (required)The field to collapse the result set on + :arg inner_hits: The number of inner hits and their sort order + :arg max_concurrent_group_searches: The number of concurrent requests + allowed to retrieve the inner_hits per group + :arg collapse: No documentation available. """ + field: Union[str, "InstrumentedField", "NotSet"] + inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet"] + max_concurrent_group_searches: Union[int, "NotSet"] + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] + def __init__( self, *, - end: Union[int, "NotSet"] = NOT_SET, - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + inner_hits: Union[ + "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if end != NOT_SET: - kwargs["end"] = end - if match != NOT_SET: - kwargs["match"] = match - super().__init__(**kwargs) + if not isinstance(field, NotSet): + kwargs["field"] = str(field) + if not isinstance(inner_hits, NotSet): + kwargs["inner_hits"] = inner_hits + if not isinstance(max_concurrent_group_searches, NotSet): + kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches + if not isinstance(collapse, NotSet): + kwargs["collapse"] = collapse + super().__init__(kwargs) -class SpanNotQuery(QueryBase): +class SourceFilter(AttrDict[Any]): """ - :arg dist: The number of tokens from within the include span that - can’t have overlap with the exclude span. Equivalent to setting - both `pre` and `post`. - :arg exclude: (required)Span query whose matches must not overlap - those returned. - :arg include: (required)Span query whose matches are filtered. - :arg post: The number of tokens after the include span that can’t have - overlap with the exclude span. - :arg pre: The number of tokens before the include span that can’t have - overlap with the exclude span. + :arg excludes: No documentation available. + :arg includes: No documentation available. """ + excludes: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + includes: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + def __init__( self, *, - dist: Union[int, "NotSet"] = NOT_SET, - exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - post: Union[int, "NotSet"] = NOT_SET, - pre: Union[int, "NotSet"] = NOT_SET, + excludes: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + includes: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, **kwargs: Any, ): - if dist != NOT_SET: - kwargs["dist"] = dist - if exclude != NOT_SET: - kwargs["exclude"] = exclude - if include != NOT_SET: - kwargs["include"] = include - if post != NOT_SET: - kwargs["post"] = post - if pre != NOT_SET: - kwargs["pre"] = pre - super().__init__(**kwargs) + if not isinstance(excludes, NotSet): + kwargs["excludes"] = str(excludes) + if not isinstance(includes, NotSet): + kwargs["includes"] = str(includes) + super().__init__(kwargs) -class SpanWithinQuery(QueryBase): +class IntervalsPrefix(AttrDict[Any]): """ - :arg big: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. - :arg little: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. + :arg analyzer: Analyzer used to analyze the `prefix`. + :arg prefix: (required)Beginning characters of terms you wish to find + in the top-level field. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `prefix` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. """ + analyzer: Union[str, "NotSet"] + prefix: Union[str, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] + def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + prefix: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if big != NOT_SET: - kwargs["big"] = big - if little != NOT_SET: - kwargs["little"] = little - super().__init__(**kwargs) + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(prefix, NotSet): + kwargs["prefix"] = prefix + if not isinstance(use_field, NotSet): + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) -class SpanNearQuery(QueryBase): +class IntervalsAnyOf(AttrDict[Any]): """ - :arg clauses: (required)Array of one or more other span type queries. - :arg in_order: Controls whether matches are required to be in-order. - :arg slop: Controls the maximum number of intervening unmatched - positions permitted. + :arg intervals: (required)An array of rules to match. + :arg filter: Rule used to filter returned intervals. """ + intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, - in_order: Union[bool, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, + intervals: Union[ + List["i.IntervalsContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if clauses != NOT_SET: - kwargs["clauses"] = clauses - if in_order != NOT_SET: - kwargs["in_order"] = in_order - if slop != NOT_SET: - kwargs["slop"] = slop - super().__init__(**kwargs) + if not isinstance(intervals, NotSet): + kwargs["intervals"] = intervals + if not isinstance(filter, NotSet): + kwargs["filter"] = filter + super().__init__(kwargs) -class SpanFieldMaskingQuery(QueryBase): +class IntervalsAllOf(AttrDict[Any]): """ - :arg field: (required)No documentation available. - :arg query: (required)No documentation available. + :arg intervals: (required)An array of rules to combine. All rules must + produce a match in a document for the overall source to match. + :arg max_gaps: Maximum number of positions between the matching terms. + Intervals produced by the rules further apart than this are not + considered matches. + :arg ordered: If `true`, intervals produced by the rules should appear + in the order in which they are specified. + :arg filter: Rule used to filter returned intervals. """ + intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] + max_gaps: Union[int, "NotSet"] + ordered: Union[bool, "NotSet"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + intervals: Union[ + List["i.IntervalsContainer"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_gaps: Union[int, "NotSet"] = NOT_SET, + ordered: Union[bool, "NotSet"] = NOT_SET, + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs["field"] = str(field) - if query != NOT_SET: - kwargs["query"] = query - super().__init__(**kwargs) + if not isinstance(intervals, NotSet): + kwargs["intervals"] = intervals + if not isinstance(max_gaps, NotSet): + kwargs["max_gaps"] = max_gaps + if not isinstance(ordered, NotSet): + kwargs["ordered"] = ordered + if not isinstance(filter, NotSet): + kwargs["filter"] = filter + super().__init__(kwargs) -class IntervalsAnyOf(AttrDict[Any]): +class IntervalsFuzzy(AttrDict[Any]): """ - :arg intervals: (required)An array of rules to match. - :arg filter: Rule used to filter returned intervals. + :arg analyzer: Analyzer used to normalize the term. + :arg fuzziness: Maximum edit distance allowed for matching. + :arg prefix_length: Number of beginning characters left unchanged when + creating expansions. + :arg term: (required)The term to match. + :arg transpositions: Indicates whether edits include transpositions of + two adjacent characters (for example, `ab` to `ba`). + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `term` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. """ + analyzer: Union[str, "NotSet"] + fuzziness: Union[str, int, "NotSet"] + prefix_length: Union[int, "NotSet"] + term: Union[str, "NotSet"] + transpositions: Union[bool, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] + def __init__( self, *, - intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + fuzziness: Union[str, int, "NotSet"] = NOT_SET, + prefix_length: Union[int, "NotSet"] = NOT_SET, + term: Union[str, "NotSet"] = NOT_SET, + transpositions: Union[bool, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if intervals != NOT_SET: - kwargs["intervals"] = intervals - if filter != NOT_SET: - kwargs["filter"] = filter + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(fuzziness, NotSet): + kwargs["fuzziness"] = fuzziness + if not isinstance(prefix_length, NotSet): + kwargs["prefix_length"] = prefix_length + if not isinstance(term, NotSet): + kwargs["term"] = term + if not isinstance(transpositions, NotSet): + kwargs["transpositions"] = transpositions + if not isinstance(use_field, NotSet): + kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -1292,6 +1745,10 @@ class IntervalsWildcard(AttrDict[Any]): separately. """ + analyzer: Union[str, "NotSet"] + pattern: Union[str, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] + def __init__( self, *, @@ -1300,11 +1757,11 @@ def __init__( use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: + if not isinstance(analyzer, NotSet): kwargs["analyzer"] = analyzer - if pattern != NOT_SET: + if not isinstance(pattern, NotSet): kwargs["pattern"] = pattern - if use_field != NOT_SET: + if not isinstance(use_field, NotSet): kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -1324,6 +1781,13 @@ class IntervalsMatch(AttrDict[Any]): :arg filter: An optional interval filter. """ + analyzer: Union[str, "NotSet"] + max_gaps: Union[int, "NotSet"] + ordered: Union[bool, "NotSet"] + query: Union[str, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + def __init__( self, *, @@ -1335,413 +1799,374 @@ def __init__( filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: + if not isinstance(analyzer, NotSet): kwargs["analyzer"] = analyzer - if max_gaps != NOT_SET: + if not isinstance(max_gaps, NotSet): kwargs["max_gaps"] = max_gaps - if ordered != NOT_SET: + if not isinstance(ordered, NotSet): kwargs["ordered"] = ordered - if query != NOT_SET: + if not isinstance(query, NotSet): kwargs["query"] = query - if use_field != NOT_SET: + if not isinstance(use_field, NotSet): kwargs["use_field"] = str(use_field) - if filter != NOT_SET: + if not isinstance(filter, NotSet): kwargs["filter"] = filter super().__init__(kwargs) -class IntervalsFuzzy(AttrDict[Any]): +class TextEmbedding(AttrDict[Any]): """ - :arg analyzer: Analyzer used to normalize the term. - :arg fuzziness: Maximum edit distance allowed for matching. - :arg prefix_length: Number of beginning characters left unchanged when - creating expansions. - :arg term: (required)The term to match. - :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example, `ab` to `ba`). - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `term` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. + :arg model_id: (required)No documentation available. + :arg model_text: (required)No documentation available. """ + model_id: Union[str, "NotSet"] + model_text: Union[str, "NotSet"] + def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - term: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + model_id: Union[str, "NotSet"] = NOT_SET, + model_text: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if fuzziness != NOT_SET: - kwargs["fuzziness"] = fuzziness - if prefix_length != NOT_SET: - kwargs["prefix_length"] = prefix_length - if term != NOT_SET: - kwargs["term"] = term - if transpositions != NOT_SET: - kwargs["transpositions"] = transpositions - if use_field != NOT_SET: - kwargs["use_field"] = str(use_field) + if not isinstance(model_id, NotSet): + kwargs["model_id"] = model_id + if not isinstance(model_text, NotSet): + kwargs["model_text"] = model_text super().__init__(kwargs) -class IntervalsAllOf(AttrDict[Any]): +class SpanFirstQuery(QueryBase): """ - :arg intervals: (required)An array of rules to combine. All rules must - produce a match in a document for the overall source to match. - :arg max_gaps: Maximum number of positions between the matching terms. - Intervals produced by the rules further apart than this are not - considered matches. - :arg ordered: If `true`, intervals produced by the rules should appear - in the order in which they are specified. - :arg filter: Rule used to filter returned intervals. + :arg end: (required)Controls the maximum end position permitted in a + match. + :arg match: (required)Can be any other span type query. """ + end: Union[int, "NotSet"] + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + def __init__( self, *, - intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_gaps: Union[int, "NotSet"] = NOT_SET, - ordered: Union[bool, "NotSet"] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + end: Union[int, "NotSet"] = NOT_SET, + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if intervals != NOT_SET: - kwargs["intervals"] = intervals - if max_gaps != NOT_SET: - kwargs["max_gaps"] = max_gaps - if ordered != NOT_SET: - kwargs["ordered"] = ordered - if filter != NOT_SET: - kwargs["filter"] = filter - super().__init__(kwargs) + if not isinstance(end, NotSet): + kwargs["end"] = end + if not isinstance(match, NotSet): + kwargs["match"] = match + super().__init__(**kwargs) -class IntervalsPrefix(AttrDict[Any]): +class SpanContainingQuery(QueryBase): """ - :arg analyzer: Analyzer used to analyze the `prefix`. - :arg prefix: (required)Beginning characters of terms you wish to find - in the top-level field. - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `prefix` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. + :arg big: (required)Can be any span query. Matching spans from `big` + that contain matches from `little` are returned. + :arg little: (required)Can be any span query. Matching spans from + `big` that contain matches from `little` are returned. """ + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - prefix: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - if prefix != NOT_SET: - kwargs["prefix"] = prefix - if use_field != NOT_SET: - kwargs["use_field"] = str(use_field) - super().__init__(kwargs) + if not isinstance(big, NotSet): + kwargs["big"] = big + if not isinstance(little, NotSet): + kwargs["little"] = little + super().__init__(**kwargs) -class FieldCollapse(AttrDict[Any]): +class SpanFieldMaskingQuery(QueryBase): """ - :arg field: (required)The field to collapse the result set on - :arg inner_hits: The number of inner hits and their sort order - :arg max_concurrent_group_searches: The number of concurrent requests - allowed to retrieve the inner_hits per group - :arg collapse: No documentation available. + :arg field: (required)No documentation available. + :arg query: (required)No documentation available. """ + field: Union[str, "InstrumentedField", "NotSet"] + query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + def __init__( self, *, field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - inner_hits: Union[ - "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: + if not isinstance(field, NotSet): kwargs["field"] = str(field) - if inner_hits != NOT_SET: - kwargs["inner_hits"] = inner_hits - if max_concurrent_group_searches != NOT_SET: - kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches - if collapse != NOT_SET: - kwargs["collapse"] = collapse - super().__init__(kwargs) + if not isinstance(query, NotSet): + kwargs["query"] = query + super().__init__(**kwargs) -class FieldAndFormat(AttrDict[Any]): +class SpanMultiTermQuery(QueryBase): """ - :arg field: (required)Wildcard pattern. The request returns values for - field names matching this pattern. - :arg format: Format in which the values are returned. - :arg include_unmapped: No documentation available. + :arg match: (required)Should be a multi term query (one of `wildcard`, + `fuzzy`, `prefix`, `range`, or `regexp` query). + """ + + match: Union[Query, "NotSet"] + + def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): + if not isinstance(match, NotSet): + kwargs["match"] = match + super().__init__(**kwargs) + + +class SpanNearQuery(QueryBase): + """ + :arg clauses: (required)Array of one or more other span type queries. + :arg in_order: Controls whether matches are required to be in-order. + :arg slop: Controls the maximum number of intervening unmatched + positions permitted. """ + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] + in_order: Union[bool, "NotSet"] + slop: Union[int, "NotSet"] + def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - format: Union[str, "NotSet"] = NOT_SET, - include_unmapped: Union[bool, "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + in_order: Union[bool, "NotSet"] = NOT_SET, + slop: Union[int, "NotSet"] = NOT_SET, **kwargs: Any, ): - if field != NOT_SET: - kwargs["field"] = str(field) - if format != NOT_SET: - kwargs["format"] = format - if include_unmapped != NOT_SET: - kwargs["include_unmapped"] = include_unmapped - super().__init__(kwargs) + if not isinstance(clauses, NotSet): + kwargs["clauses"] = clauses + if not isinstance(in_order, NotSet): + kwargs["in_order"] = in_order + if not isinstance(slop, NotSet): + kwargs["slop"] = slop + super().__init__(**kwargs) -class ScriptField(AttrDict[Any]): +class SpanWithinQuery(QueryBase): """ - :arg script: (required)No documentation available. - :arg ignore_failure: No documentation available. + :arg big: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg little: (required)Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. """ + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_failure: Union[bool, "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if script != NOT_SET: - kwargs["script"] = script - if ignore_failure != NOT_SET: - kwargs["ignore_failure"] = ignore_failure - super().__init__(kwargs) + if not isinstance(big, NotSet): + kwargs["big"] = big + if not isinstance(little, NotSet): + kwargs["little"] = little + super().__init__(**kwargs) -class SortOptions(AttrDict[Any]): +class SpanOrQuery(QueryBase): """ - :arg _score: No documentation available. - :arg _doc: No documentation available. - :arg _geo_distance: No documentation available. - :arg _script: No documentation available. + :arg clauses: (required)Array of one or more other span type queries. """ + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] + def __init__( self, *, - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if _score != NOT_SET: - kwargs["_score"] = _score - if _doc != NOT_SET: - kwargs["_doc"] = _doc - if _geo_distance != NOT_SET: - kwargs["_geo_distance"] = _geo_distance - if _script != NOT_SET: - kwargs["_script"] = _script - super().__init__(kwargs) + if not isinstance(clauses, NotSet): + kwargs["clauses"] = clauses + super().__init__(**kwargs) -class SourceFilter(AttrDict[Any]): +class SpanNotQuery(QueryBase): """ - :arg excludes: No documentation available. - :arg includes: No documentation available. + :arg dist: The number of tokens from within the include span that + can’t have overlap with the exclude span. Equivalent to setting + both `pre` and `post`. + :arg exclude: (required)Span query whose matches must not overlap + those returned. + :arg include: (required)Span query whose matches are filtered. + :arg post: The number of tokens after the include span that can’t have + overlap with the exclude span. + :arg pre: The number of tokens before the include span that can’t have + overlap with the exclude span. """ + dist: Union[int, "NotSet"] + exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + post: Union[int, "NotSet"] + pre: Union[int, "NotSet"] + def __init__( self, *, - excludes: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - includes: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, + dist: Union[int, "NotSet"] = NOT_SET, + exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + post: Union[int, "NotSet"] = NOT_SET, + pre: Union[int, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(dist, NotSet): + kwargs["dist"] = dist + if not isinstance(exclude, NotSet): + kwargs["exclude"] = exclude + if not isinstance(include, NotSet): + kwargs["include"] = include + if not isinstance(post, NotSet): + kwargs["post"] = post + if not isinstance(pre, NotSet): + kwargs["pre"] = pre + super().__init__(**kwargs) + + +class ScriptSort(AttrDict[Any]): + """ + :arg order: No documentation available. + :arg script: (required)No documentation available. + :arg type: No documentation available. + :arg mode: No documentation available. + :arg nested: No documentation available. + """ + + order: Union[Literal["asc", "desc"], "NotSet"] + script: Union["i.Script", Dict[str, Any], "NotSet"] + type: Union[Literal["string", "number", "version"], "NotSet"] + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if excludes != NOT_SET: - kwargs["excludes"] = str(excludes) - if includes != NOT_SET: - kwargs["includes"] = str(includes) + if not isinstance(order, NotSet): + kwargs["order"] = order + if not isinstance(script, NotSet): + kwargs["script"] = script + if not isinstance(type, NotSet): + kwargs["type"] = type + if not isinstance(mode, NotSet): + kwargs["mode"] = mode + if not isinstance(nested, NotSet): + kwargs["nested"] = nested + super().__init__(kwargs) + + +class ScoreSort(AttrDict[Any]): + """ + :arg order: No documentation available. + """ + + order: Union[Literal["asc", "desc"], "NotSet"] + + def __init__( + self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + ): + if not isinstance(order, NotSet): + kwargs["order"] = order super().__init__(kwargs) -class HighlightBase(AttrDict[Any]): +class GeoDistanceSort(AttrDict[Any]): """ - :arg type: No documentation available. - :arg boundary_chars: A string that contains each boundary character. - :arg boundary_max_scan: How far to scan for boundary characters. - :arg boundary_scanner: Specifies how to break the highlighted - fragments: chars, sentence, or word. Only valid for the unified - and fvh highlighters. Defaults to `sentence` for the `unified` - highlighter. Defaults to `chars` for the `fvh` highlighter. - :arg boundary_scanner_locale: Controls which locale is used to search - for sentence and word boundaries. This parameter takes a form of a - language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. - :arg force_source: No documentation available. - :arg fragmenter: Specifies how text should be broken up in highlight - snippets: `simple` or `span`. Only valid for the `plain` - highlighter. - :arg fragment_size: The size of the highlighted fragment in - characters. - :arg highlight_filter: No documentation available. - :arg highlight_query: Highlight matches for a query other than the - search query. This is especially useful if you use a rescore query - because those are not taken into account by highlighting by - default. - :arg max_fragment_length: No documentation available. - :arg max_analyzed_offset: If set to a non-negative value, highlighting - stops at this defined maximum limit. The rest of the text is not - processed, thus not highlighted and no error is returned The - `max_analyzed_offset` query setting does not override the - `index.highlight.max_analyzed_offset` setting, which prevails when - it’s set to lower value than the query setting. - :arg no_match_size: The amount of text you want to return from the - beginning of the field if there are no matching fragments to - highlight. - :arg number_of_fragments: The maximum number of fragments to return. - If the number of fragments is set to `0`, no fragments are - returned. Instead, the entire field contents are highlighted and - returned. This can be handy when you need to highlight short texts - such as a title or address, but fragmentation is not required. If - `number_of_fragments` is `0`, `fragment_size` is ignored. - :arg options: No documentation available. - :arg order: Sorts highlighted fragments by score when set to `score`. - By default, fragments will be output in the order they appear in - the field (order: `none`). Setting this option to `score` will - output the most relevant fragments first. Each highlighter applies - its own logic to compute relevancy scores. - :arg phrase_limit: Controls the number of matching phrases in a - document that are considered. Prevents the `fvh` highlighter from - analyzing too many phrases and consuming too much memory. When - using `matched_fields`, `phrase_limit` phrases per matched field - are considered. Raising the limit increases query time and - consumes more memory. Only supported by the `fvh` highlighter. - :arg post_tags: Use in conjunction with `pre_tags` to define the HTML - tags to use for the highlighted text. By default, highlighted text - is wrapped in `` and `` tags. - :arg pre_tags: Use in conjunction with `post_tags` to define the HTML - tags to use for the highlighted text. By default, highlighted text - is wrapped in `` and `` tags. - :arg require_field_match: By default, only fields that contains a - query match are highlighted. Set to `false` to highlight all - fields. - :arg tags_schema: Set to `styled` to use the built-in tag schema. + :arg mode: No documentation available. + :arg distance_type: No documentation available. + :arg ignore_unmapped: No documentation available. + :arg order: No documentation available. + :arg unit: No documentation available. + :arg nested: No documentation available. """ + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] + distance_type: Union[Literal["arc", "plane"], "NotSet"] + ignore_unmapped: Union[bool, "NotSet"] + order: Union[Literal["asc", "desc"], "NotSet"] + unit: Union[Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet"] + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + def __init__( self, *, - type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, - boundary_chars: Union[str, "NotSet"] = NOT_SET, - boundary_max_scan: Union[int, "NotSet"] = NOT_SET, - boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "NotSet" + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, + ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + unit: Union[ + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" ] = NOT_SET, - boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, - force_source: Union[bool, "NotSet"] = NOT_SET, - fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, - fragment_size: Union[int, "NotSet"] = NOT_SET, - highlight_filter: Union[bool, "NotSet"] = NOT_SET, - highlight_query: Union[Query, "NotSet"] = NOT_SET, - max_fragment_length: Union[int, "NotSet"] = NOT_SET, - max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, - no_match_size: Union[int, "NotSet"] = NOT_SET, - number_of_fragments: Union[int, "NotSet"] = NOT_SET, - options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, - order: Union[Literal["score"], "NotSet"] = NOT_SET, - phrase_limit: Union[int, "NotSet"] = NOT_SET, - post_tags: Union[List[str], "NotSet"] = NOT_SET, - pre_tags: Union[List[str], "NotSet"] = NOT_SET, - require_field_match: Union[bool, "NotSet"] = NOT_SET, - tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if type != NOT_SET: - kwargs["type"] = type - if boundary_chars != NOT_SET: - kwargs["boundary_chars"] = boundary_chars - if boundary_max_scan != NOT_SET: - kwargs["boundary_max_scan"] = boundary_max_scan - if boundary_scanner != NOT_SET: - kwargs["boundary_scanner"] = boundary_scanner - if boundary_scanner_locale != NOT_SET: - kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if force_source != NOT_SET: - kwargs["force_source"] = force_source - if fragmenter != NOT_SET: - kwargs["fragmenter"] = fragmenter - if fragment_size != NOT_SET: - kwargs["fragment_size"] = fragment_size - if highlight_filter != NOT_SET: - kwargs["highlight_filter"] = highlight_filter - if highlight_query != NOT_SET: - kwargs["highlight_query"] = highlight_query - if max_fragment_length != NOT_SET: - kwargs["max_fragment_length"] = max_fragment_length - if max_analyzed_offset != NOT_SET: - kwargs["max_analyzed_offset"] = max_analyzed_offset - if no_match_size != NOT_SET: - kwargs["no_match_size"] = no_match_size - if number_of_fragments != NOT_SET: - kwargs["number_of_fragments"] = number_of_fragments - if options != NOT_SET: - kwargs["options"] = options - if order != NOT_SET: + if not isinstance(mode, NotSet): + kwargs["mode"] = mode + if not isinstance(distance_type, NotSet): + kwargs["distance_type"] = distance_type + if not isinstance(ignore_unmapped, NotSet): + kwargs["ignore_unmapped"] = ignore_unmapped + if not isinstance(order, NotSet): kwargs["order"] = order - if phrase_limit != NOT_SET: - kwargs["phrase_limit"] = phrase_limit - if post_tags != NOT_SET: - kwargs["post_tags"] = post_tags - if pre_tags != NOT_SET: - kwargs["pre_tags"] = pre_tags - if require_field_match != NOT_SET: - kwargs["require_field_match"] = require_field_match - if tags_schema != NOT_SET: - kwargs["tags_schema"] = tags_schema + if not isinstance(unit, NotSet): + kwargs["unit"] = unit + if not isinstance(nested, NotSet): + kwargs["nested"] = nested super().__init__(kwargs) -class Highlight(HighlightBase): +class HighlightField(HighlightBase): """ - :arg encoder: No documentation available. - :arg fields: (required)No documentation available. + :arg fragment_offset: No documentation available. + :arg matched_fields: No documentation available. + :arg analyzer: No documentation available. """ + fragment_offset: Union[int, "NotSet"] + matched_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + analyzer: Union[str, "NotSet"] + def __init__( self, *, - encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, - fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], - Dict[str, Any], + fragment_offset: Union[int, "NotSet"] = NOT_SET, + matched_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], "NotSet", ] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, **kwargs: Any, ): - if encoder != NOT_SET: - kwargs["encoder"] = encoder - if fields != NOT_SET: - kwargs["fields"] = str(fields) + if not isinstance(fragment_offset, NotSet): + kwargs["fragment_offset"] = fragment_offset + if not isinstance(matched_fields, NotSet): + kwargs["matched_fields"] = str(matched_fields) + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer super().__init__(**kwargs) @@ -1756,6 +2181,13 @@ class IntervalsContainer(AttrDict[Any]): :arg wildcard: Matches terms using a wildcard pattern. """ + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] + match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] + def __init__( self, *, @@ -1767,17 +2199,17 @@ def __init__( wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if all_of != NOT_SET: + if not isinstance(all_of, NotSet): kwargs["all_of"] = all_of - if any_of != NOT_SET: + if not isinstance(any_of, NotSet): kwargs["any_of"] = any_of - if fuzzy != NOT_SET: + if not isinstance(fuzzy, NotSet): kwargs["fuzzy"] = fuzzy - if match != NOT_SET: + if not isinstance(match, NotSet): kwargs["match"] = match - if prefix != NOT_SET: + if not isinstance(prefix, NotSet): kwargs["prefix"] = prefix - if wildcard != NOT_SET: + if not isinstance(wildcard, NotSet): kwargs["wildcard"] = wildcard super().__init__(kwargs) @@ -1804,6 +2236,16 @@ class IntervalsFilter(AttrDict[Any]): must return a boolean value: `true` or `false`. """ + after: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + before: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + not_contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + not_containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + not_overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] + script: Union["i.Script", Dict[str, Any], "NotSet"] + def __init__( self, *, @@ -1824,138 +2266,27 @@ def __init__( script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if after != NOT_SET: + if not isinstance(after, NotSet): kwargs["after"] = after - if before != NOT_SET: + if not isinstance(before, NotSet): kwargs["before"] = before - if contained_by != NOT_SET: + if not isinstance(contained_by, NotSet): kwargs["contained_by"] = contained_by - if containing != NOT_SET: + if not isinstance(containing, NotSet): kwargs["containing"] = containing - if not_contained_by != NOT_SET: + if not isinstance(not_contained_by, NotSet): kwargs["not_contained_by"] = not_contained_by - if not_containing != NOT_SET: + if not isinstance(not_containing, NotSet): kwargs["not_containing"] = not_containing - if not_overlapping != NOT_SET: + if not isinstance(not_overlapping, NotSet): kwargs["not_overlapping"] = not_overlapping - if overlapping != NOT_SET: + if not isinstance(overlapping, NotSet): kwargs["overlapping"] = overlapping - if script != NOT_SET: - kwargs["script"] = script - super().__init__(kwargs) - - -class ScoreSort(AttrDict[Any]): - """ - :arg order: No documentation available. - """ - - def __init__( - self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any - ): - if order != NOT_SET: - kwargs["order"] = order - super().__init__(kwargs) - - -class GeoDistanceSort(AttrDict[Any]): - """ - :arg mode: No documentation available. - :arg distance_type: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg order: No documentation available. - :arg unit: No documentation available. - :arg nested: No documentation available. - """ - - def __init__( - self, - *, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - unit: Union[ - Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" - ] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if mode != NOT_SET: - kwargs["mode"] = mode - if distance_type != NOT_SET: - kwargs["distance_type"] = distance_type - if ignore_unmapped != NOT_SET: - kwargs["ignore_unmapped"] = ignore_unmapped - if order != NOT_SET: - kwargs["order"] = order - if unit != NOT_SET: - kwargs["unit"] = unit - if nested != NOT_SET: - kwargs["nested"] = nested - super().__init__(kwargs) - - -class ScriptSort(AttrDict[Any]): - """ - :arg order: No documentation available. - :arg script: (required)No documentation available. - :arg type: No documentation available. - :arg mode: No documentation available. - :arg nested: No documentation available. - """ - - def __init__( - self, - *, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if order != NOT_SET: - kwargs["order"] = order - if script != NOT_SET: + if not isinstance(script, NotSet): kwargs["script"] = script - if type != NOT_SET: - kwargs["type"] = type - if mode != NOT_SET: - kwargs["mode"] = mode - if nested != NOT_SET: - kwargs["nested"] = nested super().__init__(kwargs) -class HighlightField(HighlightBase): - """ - :arg fragment_offset: No documentation available. - :arg matched_fields: No documentation available. - :arg analyzer: No documentation available. - """ - - def __init__( - self, - *, - fragment_offset: Union[int, "NotSet"] = NOT_SET, - matched_fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if fragment_offset != NOT_SET: - kwargs["fragment_offset"] = fragment_offset - if matched_fields != NOT_SET: - kwargs["matched_fields"] = str(matched_fields) - if analyzer != NOT_SET: - kwargs["analyzer"] = analyzer - super().__init__(**kwargs) - - class NestedSortValue(AttrDict[Any]): """ :arg filter: No documentation available. @@ -1964,6 +2295,11 @@ class NestedSortValue(AttrDict[Any]): :arg path: (required)No documentation available. """ + filter: Union[Query, "NotSet"] + max_children: Union[int, "NotSet"] + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + path: Union[str, "InstrumentedField", "NotSet"] + def __init__( self, *, @@ -1973,12 +2309,12 @@ def __init__( path: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if filter != NOT_SET: + if not isinstance(filter, NotSet): kwargs["filter"] = filter - if max_children != NOT_SET: + if not isinstance(max_children, NotSet): kwargs["max_children"] = max_children - if nested != NOT_SET: + if not isinstance(nested, NotSet): kwargs["nested"] = nested - if path != NOT_SET: + if not isinstance(path, NotSet): kwargs["path"] = str(path) super().__init__(kwargs) diff --git a/elasticsearch_dsl/utils.py b/elasticsearch_dsl/utils.py index 66594c9d..18aba77c 100644 --- a/elasticsearch_dsl/utils.py +++ b/elasticsearch_dsl/utils.py @@ -336,7 +336,7 @@ def __init__(self, _expand__to_dot: Optional[bool] = None, **params: Any) -> Non _expand__to_dot = EXPAND__TO_DOT self._params: Dict[str, Any] = {} for pname, pvalue in params.items(): - if pvalue == NOT_SET: + if isinstance(pvalue, NotSet): continue # expand "__" to dots if "__" in pname and _expand__to_dot: diff --git a/utils/generator.py b/utils/generator.py index e8eb852d..b871409a 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -401,4 +401,4 @@ def generate_interfaces(schema, interfaces, filename): schema = ElasticsearchSchema() generate_query_classes(schema, "elasticsearch_dsl/query.py") interfaces = schema.interfaces - generate_interfaces(schema, list(interfaces), "elasticsearch_dsl/interfaces.py") + generate_interfaces(schema, sorted(interfaces), "elasticsearch_dsl/interfaces.py") diff --git a/utils/templates/dsl_classes.tpl b/utils/templates/dsl_classes.tpl deleted file mode 100644 index 84d0566c..00000000 --- a/utils/templates/dsl_classes.tpl +++ /dev/null @@ -1,217 +0,0 @@ -{% for k in classes %} -class {{ k.name }}({{ parent }}): - """ - {% for line in k.docstring %} - {{ line }} - {% endfor %} - {% if k.kwargs %} - - {% for kwarg in k.kwargs %} - {% for line in kwarg.doc %} - {{ line }} - {% endfor %} - {% endfor %} - {% endif %} - """ - name = "{{ k.schema.name }}" - {% if k.params %} - _param_defs = { - {% for param in k.params %} - "{{ param.name }}": {{ param.param }}, - {% endfor %} - {% if k.name == "FunctionScore" %} - "filter": {"type": "query"}, - "functions": {"type": "score_function", "multi": True}, - {% endif %} - } - {% endif %} - - def __init__( - self, - {% if k.kwargs and not k.has_field and not k.has_fields %} - *, - {% endif %} - {% for kwarg in k.kwargs %} - {{ kwarg.name }}: {{ kwarg.type }} = NOT_SET, - {% endfor %} - **kwargs: Any - ): - {% if k.name == "FunctionScore" %} - if isinstance(functions, NotSet): - functions = [] - for name in ScoreFunction._classes: - if name in kwargs: - functions.append({name: kwargs.pop(name)}) # type: ignore - {% elif k.has_field %} - if not isinstance(_field, NotSet): - kwargs[str(_field)] = _value - {% elif k.has_fields %} - if not isinstance(fields, NotSet): - for field, value in _fields.items(): - kwargs[str(field)] = value - {% elif k.has_type_alias %} - {% for kwarg in k.kwargs %} - {% if loop.index == 1 %} - if not isinstance({{ kwarg.name }}, NotSet): - {% else %} - elif not isinstance({{ kwarg.name }}, NotSet): - {% endif %} - kwargs = cast(Dict[str, Any], {{ kwarg.name }}.to_dict() if hasattr({{ kwarg.name }}, "to_dict") else {{ kwarg.name }}) - {% endfor %} - {% endif %} - super().__init__( - {% if not k.has_field and not k.has_fields and not k.has_type_alias %} - {% for kwarg in k.kwargs %} - {{ kwarg.name }}={{ kwarg.name }}, - {% endfor %} - {% endif %} - **kwargs - ) - - {% if k.name == "MatchAll" %} - def __add__(self, other: "Query") -> "Query": - return other._clone() - - __and__ = __rand__ = __radd__ = __add__ - - def __or__(self, other: "Query") -> "MatchAll": - return self - - __ror__ = __or__ - - def __invert__(self) -> "MatchNone": - return MatchNone() - - -EMPTY_QUERY = MatchAll() - - {% elif k.name == "MatchNone" %} - def __add__(self, other: "Query") -> "MatchNone": - return self - - __and__ = __rand__ = __radd__ = __add__ - - def __or__(self, other: "Query") -> "Query": - return other._clone() - - __ror__ = __or__ - - def __invert__(self) -> MatchAll: - return MatchAll() - - {% elif k.name == "Bool" %} - def __add__(self, other: Query) -> "Bool": - q = self._clone() - if isinstance(other, Bool): - q.must += other.must - q.should += other.should - q.must_not += other.must_not - q.filter += other.filter - else: - q.must.append(other) - return q - - __radd__ = __add__ - - def __or__(self, other: Query) -> Query: - for q in (self, other): - if isinstance(q, Bool) and not any( - (q.must, q.must_not, q.filter, getattr(q, "minimum_should_match", None)) - ): - other = self if q is other else other - q = q._clone() - if isinstance(other, Bool) and not any( - ( - other.must, - other.must_not, - other.filter, - getattr(other, "minimum_should_match", None), - ) - ): - q.should.extend(other.should) - else: - q.should.append(other) - return q - - return Bool(should=[self, other]) - - __ror__ = __or__ - - @property - def _min_should_match(self) -> int: - return getattr( - self, - "minimum_should_match", - 0 if not self.should or (self.must or self.filter) else 1, - ) - - def __invert__(self) -> Query: - # Because an empty Bool query is treated like - # MatchAll the inverse should be MatchNone - if not any(chain(self.must, self.filter, self.should, self.must_not)): - return MatchNone() - - negations: List[Query] = [] - for q in chain(self.must, self.filter): - negations.append(~q) - - for q in self.must_not: - negations.append(q) - - if self.should and self._min_should_match: - negations.append(Bool(must_not=self.should[:])) - - if len(negations) == 1: - return negations[0] - return Bool(should=negations) - - def __and__(self, other: Query) -> Query: - q = self._clone() - if isinstance(other, Bool): - q.must += other.must - q.must_not += other.must_not - q.filter += other.filter - q.should = [] - - # reset minimum_should_match as it will get calculated below - if "minimum_should_match" in q._params: - del q._params["minimum_should_match"] - - for qx in (self, other): - min_should_match = qx._min_should_match - # TODO: percentages or negative numbers will fail here - # for now we report an error - if not isinstance(min_should_match, int) or min_should_match < 0: - raise ValueError( - "Can only combine queries with positive integer values for minimum_should_match" - ) - # all subqueries are required - if len(qx.should) <= min_should_match: - q.must.extend(qx.should) - # not all of them are required, use it and remember min_should_match - elif not q.should: - q.minimum_should_match = min_should_match - q.should = qx.should - # all queries are optional, just extend should - elif q._min_should_match == 0 and min_should_match == 0: - q.should.extend(qx.should) - # not all are required, add a should list to the must with proper min_should_match - else: - q.must.append( - Bool(should=qx.should, minimum_should_match=min_should_match) - ) - else: - if not (q.must or q.filter) and q.should: - q._params.setdefault("minimum_should_match", 1) - q.must.append(other) - return q - - __rand__ = __and__ - - {% elif k.name == "Terms" %} - def _setattr(self, name: str, value: Any) -> None: - super()._setattr(name, list(value)) - - {% endif %} - -{% endfor %} diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index 52121d24..d48033d3 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -16,6 +16,10 @@ class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endi {% endfor %} {% endfor %} """ + {% for p in k.properties %} + {{ p.name }}: {{ p.type }} + {% endfor %} + def __init__( self, *, @@ -25,7 +29,7 @@ class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endi **kwargs: Any ): {% for p in k.properties %} - if {{ p.name }} != NOT_SET: + if not isinstance({{ p.name }}, NotSet): {% if "InstrumentedField" in p.type %} kwargs["{{ p.name }}"] = str({{ p.name }}) {% else %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index f1f32d34..1231d886 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -142,4 +142,220 @@ class Query(DslBase): return Bool(must=[self, other]) -{% include "dsl_classes.tpl" %} +{% for k in classes %} +class {{ k.name }}({{ parent }}): + """ + {% for line in k.docstring %} + {{ line }} + {% endfor %} + {% if k.kwargs %} + + {% for kwarg in k.kwargs %} + {% for line in kwarg.doc %} + {{ line }} + {% endfor %} + {% endfor %} + {% endif %} + """ + name = "{{ k.schema.name }}" + {% if k.params %} + _param_defs = { + {% for param in k.params %} + "{{ param.name }}": {{ param.param }}, + {% endfor %} + {% if k.name == "FunctionScore" %} + "filter": {"type": "query"}, + "functions": {"type": "score_function", "multi": True}, + {% endif %} + } + {% endif %} + + def __init__( + self, + {% if k.kwargs and not k.has_field and not k.has_fields %} + *, + {% endif %} + {% for kwarg in k.kwargs %} + {{ kwarg.name }}: {{ kwarg.type }} = NOT_SET, + {% endfor %} + **kwargs: Any + ): + {% if k.name == "FunctionScore" %} + if isinstance(functions, NotSet): + functions = [] + for name in ScoreFunction._classes: + if name in kwargs: + functions.append({name: kwargs.pop(name)}) # type: ignore + {% elif k.has_field %} + if not isinstance(_field, NotSet): + kwargs[str(_field)] = _value + {% elif k.has_fields %} + if not isinstance(fields, NotSet): + for field, value in _fields.items(): + kwargs[str(field)] = value + {% elif k.has_type_alias %} + {% for kwarg in k.kwargs %} + {% if loop.index == 1 %} + if not isinstance({{ kwarg.name }}, NotSet): + {% else %} + elif not isinstance({{ kwarg.name }}, NotSet): + {% endif %} + kwargs = cast(Dict[str, Any], {{ kwarg.name }}.to_dict() if hasattr({{ kwarg.name }}, "to_dict") else {{ kwarg.name }}) + {% endfor %} + {% endif %} + super().__init__( + {% if not k.has_field and not k.has_fields and not k.has_type_alias %} + {% for kwarg in k.kwargs %} + {{ kwarg.name }}={{ kwarg.name }}, + {% endfor %} + {% endif %} + **kwargs + ) + + {% if k.name == "MatchAll" %} + def __add__(self, other: "Query") -> "Query": + return other._clone() + + __and__ = __rand__ = __radd__ = __add__ + + def __or__(self, other: "Query") -> "MatchAll": + return self + + __ror__ = __or__ + + def __invert__(self) -> "MatchNone": + return MatchNone() + + +EMPTY_QUERY = MatchAll() + + {% elif k.name == "MatchNone" %} + def __add__(self, other: "Query") -> "MatchNone": + return self + + __and__ = __rand__ = __radd__ = __add__ + + def __or__(self, other: "Query") -> "Query": + return other._clone() + + __ror__ = __or__ + + def __invert__(self) -> MatchAll: + return MatchAll() + + {% elif k.name == "Bool" %} + def __add__(self, other: Query) -> "Bool": + q = self._clone() + if isinstance(other, Bool): + q.must += other.must + q.should += other.should + q.must_not += other.must_not + q.filter += other.filter + else: + q.must.append(other) + return q + + __radd__ = __add__ + + def __or__(self, other: Query) -> Query: + for q in (self, other): + if isinstance(q, Bool) and not any( + (q.must, q.must_not, q.filter, getattr(q, "minimum_should_match", None)) + ): + other = self if q is other else other + q = q._clone() + if isinstance(other, Bool) and not any( + ( + other.must, + other.must_not, + other.filter, + getattr(other, "minimum_should_match", None), + ) + ): + q.should.extend(other.should) + else: + q.should.append(other) + return q + + return Bool(should=[self, other]) + + __ror__ = __or__ + + @property + def _min_should_match(self) -> int: + return getattr( + self, + "minimum_should_match", + 0 if not self.should or (self.must or self.filter) else 1, + ) + + def __invert__(self) -> Query: + # Because an empty Bool query is treated like + # MatchAll the inverse should be MatchNone + if not any(chain(self.must, self.filter, self.should, self.must_not)): + return MatchNone() + + negations: List[Query] = [] + for q in chain(self.must, self.filter): + negations.append(~q) + + for q in self.must_not: + negations.append(q) + + if self.should and self._min_should_match: + negations.append(Bool(must_not=self.should[:])) + + if len(negations) == 1: + return negations[0] + return Bool(should=negations) + + def __and__(self, other: Query) -> Query: + q = self._clone() + if isinstance(other, Bool): + q.must += other.must + q.must_not += other.must_not + q.filter += other.filter + q.should = [] + + # reset minimum_should_match as it will get calculated below + if "minimum_should_match" in q._params: + del q._params["minimum_should_match"] + + for qx in (self, other): + min_should_match = qx._min_should_match + # TODO: percentages or negative numbers will fail here + # for now we report an error + if not isinstance(min_should_match, int) or min_should_match < 0: + raise ValueError( + "Can only combine queries with positive integer values for minimum_should_match" + ) + # all subqueries are required + if len(qx.should) <= min_should_match: + q.must.extend(qx.should) + # not all of them are required, use it and remember min_should_match + elif not q.should: + q.minimum_should_match = min_should_match + q.should = qx.should + # all queries are optional, just extend should + elif q._min_should_match == 0 and min_should_match == 0: + q.should.extend(qx.should) + # not all are required, add a should list to the must with proper min_should_match + else: + q.must.append( + Bool(should=qx.should, minimum_should_match=min_should_match) + ) + else: + if not (q.must or q.filter) and q.should: + q._params.setdefault("minimum_should_match", 1) + q.must.append(other) + return q + + __rand__ = __and__ + + {% elif k.name == "Terms" %} + def _setattr(self, name: str, value: Any) -> None: + super()._setattr(name, list(value)) + + {% endif %} + +{% endfor %} From 44dcd870ee705f35adf6d791e5b4fcd18ad28507 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 3 Sep 2024 18:57:12 +0100 Subject: [PATCH 08/27] more code generator cleanup --- elasticsearch_dsl/interfaces.py | 677 ++++++++++++++---------------- elasticsearch_dsl/query.py | 152 +++---- utils/generator.py | 305 +++++++++----- utils/templates/interfaces.py.tpl | 41 +- utils/templates/query.py.tpl | 33 +- 5 files changed, 622 insertions(+), 586 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index dd7817de..3bf11bf8 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -60,7 +60,7 @@ class CommonTermsQuery(QueryBase): :arg high_freq_operator: No documentation available. :arg low_freq_operator: No documentation available. :arg minimum_should_match: No documentation available. - :arg query: (required)No documentation available. + :arg query: (required) No documentation available. """ analyzer: Union[str, "NotSet"] @@ -96,52 +96,6 @@ def __init__( super().__init__(**kwargs) -class DistanceFeatureQueryBase(QueryBase): - """ - :arg origin: (required)Date or point of origin used to calculate - distances. If the `field` value is a `date` or `date_nanos` field, - the `origin` value must be a date. Date Math, such as `now-1h`, is - supported. If the field value is a `geo_point` field, the `origin` - value must be a geopoint. - :arg pivot: (required)Distance from the `origin` at which relevance - scores receive half of the `boost` value. If the `field` value is - a `date` or `date_nanos` field, the `pivot` value must be a time - unit, such as `1h` or `10d`. If the `field` value is a `geo_point` - field, the `pivot` value must be a distance unit, such as `1km` or - `12m`. - :arg field: (required)Name of the field used to calculate distances. - This field must meet the following criteria: be a `date`, - `date_nanos` or `geo_point` field; have an `index` mapping - parameter value of `true`, which is the default; have an - `doc_values` mapping parameter value of `true`, which is the - default. - """ - - origin: Any - pivot: Any - field: Union[str, "InstrumentedField", "NotSet"] - - def __init__( - self, - *, - origin: Any = NOT_SET, - pivot: Any = NOT_SET, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(origin, NotSet): - kwargs["origin"] = origin - if not isinstance(pivot, NotSet): - kwargs["pivot"] = pivot - if not isinstance(field, NotSet): - kwargs["field"] = str(field) - super().__init__(**kwargs) - - -class DateDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - class FunctionScoreContainer(AttrDict[Any]): """ :arg exp: Function that scores a document with a exponential decay, @@ -218,7 +172,7 @@ class FuzzyQuery(QueryBase): :arg transpositions: Indicates whether edits include transpositions of two adjacent characters (for example `ab` to `ba`). :arg fuzziness: Maximum edit distance allowed for matching. - :arg value: (required)Term you wish to find in the provided field. + :arg value: (required) Term you wish to find in the provided field. """ max_expansions: Union[int, "NotSet"] @@ -254,10 +208,6 @@ def __init__( super().__init__(**kwargs) -class GeoDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - class InnerHits(AttrDict[Any]): """ :arg name: The name for the particular inner hit definition in the @@ -515,7 +465,7 @@ class MatchBoolPrefixQuery(QueryBase): :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. Can be applied to the term subqueries constructed for all terms but the final term. - :arg query: (required)Terms you wish to find in the provided field. + :arg query: (required) Terms you wish to find in the provided field. The last term is used in a prefix query. """ @@ -570,7 +520,7 @@ class MatchPhrasePrefixQuery(QueryBase): tokens. :arg max_expansions: Maximum number of terms to which the last provided term of the query value will expand. - :arg query: (required)Text you wish to find in the provided field. + :arg query: (required) Text you wish to find in the provided field. :arg slop: Maximum number of positions allowed between matching tokens. :arg zero_terms_query: Indicates whether no documents are returned if @@ -611,7 +561,7 @@ class MatchPhraseQuery(QueryBase): """ :arg analyzer: Analyzer used to convert the text in the query value into tokens. - :arg query: (required)Query terms that are analyzed and turned into a + :arg query: (required) Query terms that are analyzed and turned into a phrase query. :arg slop: Maximum number of positions allowed between matching tokens. @@ -667,7 +617,7 @@ class MatchQuery(QueryBase): value. :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. - :arg query: (required)Text, number, boolean value or date you wish to + :arg query: (required) Text, number, boolean value or date you wish to find in the provided field. :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` @@ -739,8 +689,8 @@ def __init__( class PinnedDoc(AttrDict[Any]): """ - :arg _id: (required)The unique document ID. - :arg _index: (required)The index that contains the document. + :arg _id: (required) The unique document ID. + :arg _index: (required) The index that contains the document. """ _id: Union[str, "NotSet"] @@ -763,7 +713,7 @@ def __init__( class PrefixQuery(QueryBase): """ :arg rewrite: Method used to rewrite the query. - :arg value: (required)Beginning characters of terms you wish to find + :arg value: (required) Beginning characters of terms you wish to find in the provided field. :arg case_insensitive: Allows ASCII case insensitive matching of the value with the indexed field values when set to `true`. Default is @@ -820,7 +770,7 @@ class RankFeatureFunctionLinear(RankFeatureFunction): class RankFeatureFunctionLogarithm(RankFeatureFunction): """ - :arg scaling_factor: (required)Configurable scaling factor. + :arg scaling_factor: (required) Configurable scaling factor. """ scaling_factor: Union[float, "NotSet"] @@ -849,9 +799,9 @@ def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): class RankFeatureFunctionSigmoid(RankFeatureFunction): """ - :arg pivot: (required)Configurable pivot value so that the result will - be less than 0.5. - :arg exponent: (required)Configurable Exponent. + :arg pivot: (required) Configurable pivot value so that the result + will be less than 0.5. + :arg exponent: (required) Configurable Exponent. """ pivot: Union[float, "NotSet"] @@ -881,8 +831,8 @@ class RegexpQuery(QueryBase): :arg max_determinized_states: Maximum number of automaton states required for the query. :arg rewrite: Method used to rewrite the query. - :arg value: (required)Regular expression for terms you wish to find in - the provided field. + :arg value: (required) Regular expression for terms you wish to find + in the provided field. """ case_insensitive: Union[bool, "NotSet"] @@ -1046,7 +996,7 @@ def __init__( class SpanTermQuery(QueryBase): """ - :arg value: (required)No documentation available. + :arg value: (required) No documentation available. """ value: Union[str, "NotSet"] @@ -1059,7 +1009,7 @@ def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): class TermQuery(QueryBase): """ - :arg value: (required)Term you wish to find in the provided field. + :arg value: (required) Term you wish to find in the provided field. :arg case_insensitive: Allows ASCII case insensitive matching of the value with the indexed field values when set to `true`. When `false`, the case sensitivity of matching depends on the @@ -1089,7 +1039,7 @@ class TermsSetQuery(QueryBase): of matching terms required to return a document. :arg minimum_should_match_script: Custom script containing the number of matching terms required to return a document. - :arg terms: (required)Array of terms you wish to find in the provided + :arg terms: (required) Array of terms you wish to find in the provided field. """ @@ -1118,8 +1068,8 @@ def __init__( class TextExpansionQuery(QueryBase): """ - :arg model_id: (required)The text expansion NLP model to use - :arg model_text: (required)The query text + :arg model_id: (required) The text expansion NLP model to use + :arg model_text: (required) The query text :arg pruning_config: Token pruning configurations """ @@ -1178,13 +1128,9 @@ def __init__( super().__init__(kwargs) -class UntypedDistanceFeatureQuery(DistanceFeatureQueryBase): - pass - - class WeightedTokensQuery(QueryBase): """ - :arg tokens: (required)The tokens representing this query + :arg tokens: (required) The tokens representing this query :arg pruning_config: Token pruning configurations """ @@ -1245,33 +1191,10 @@ def __init__( super().__init__(**kwargs) -class ScriptField(AttrDict[Any]): - """ - :arg script: (required)No documentation available. - :arg ignore_failure: No documentation available. - """ - - script: Union["i.Script", Dict[str, Any], "NotSet"] - ignore_failure: Union[bool, "NotSet"] - - def __init__( - self, - *, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_failure: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(script, NotSet): - kwargs["script"] = script - if not isinstance(ignore_failure, NotSet): - kwargs["ignore_failure"] = ignore_failure - super().__init__(kwargs) - - class FieldAndFormat(AttrDict[Any]): """ - :arg field: (required)Wildcard pattern. The request returns values for - field names matching this pattern. + :arg field: (required) Wildcard pattern. The request returns values + for field names matching this pattern. :arg format: Format in which the values are returned. :arg include_unmapped: No documentation available. """ @@ -1297,36 +1220,39 @@ def __init__( super().__init__(kwargs) -class SortOptions(AttrDict[Any]): +class FieldCollapse(AttrDict[Any]): """ - :arg _score: No documentation available. - :arg _doc: No documentation available. - :arg _geo_distance: No documentation available. - :arg _script: No documentation available. + :arg field: (required) The field to collapse the result set on + :arg inner_hits: The number of inner hits and their sort order + :arg max_concurrent_group_searches: The number of concurrent requests + allowed to retrieve the inner_hits per group + :arg collapse: No documentation available. """ - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] + field: Union[str, "InstrumentedField", "NotSet"] + inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet"] + max_concurrent_group_searches: Union[int, "NotSet"] + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] def __init__( self, *, - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + inner_hits: Union[ + "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" + ] = NOT_SET, + max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, + collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(_score, NotSet): - kwargs["_score"] = _score - if not isinstance(_doc, NotSet): - kwargs["_doc"] = _doc - if not isinstance(_geo_distance, NotSet): - kwargs["_geo_distance"] = _geo_distance - if not isinstance(_script, NotSet): - kwargs["_script"] = _script + if not isinstance(field, NotSet): + kwargs["field"] = str(field) + if not isinstance(inner_hits, NotSet): + kwargs["inner_hits"] = inner_hits + if not isinstance(max_concurrent_group_searches, NotSet): + kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches + if not isinstance(collapse, NotSet): + kwargs["collapse"] = collapse super().__init__(kwargs) @@ -1491,7 +1417,7 @@ def __init__( class Highlight(HighlightBase): """ :arg encoder: No documentation available. - :arg fields: (required)No documentation available. + :arg fields: (required) No documentation available. """ encoder: Union[Literal["default", "html"], "NotSet"] @@ -1519,39 +1445,59 @@ def __init__( super().__init__(**kwargs) -class FieldCollapse(AttrDict[Any]): +class ScriptField(AttrDict[Any]): """ - :arg field: (required)The field to collapse the result set on - :arg inner_hits: The number of inner hits and their sort order - :arg max_concurrent_group_searches: The number of concurrent requests - allowed to retrieve the inner_hits per group - :arg collapse: No documentation available. + :arg script: (required) No documentation available. + :arg ignore_failure: No documentation available. """ - field: Union[str, "InstrumentedField", "NotSet"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet"] - max_concurrent_group_searches: Union[int, "NotSet"] - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] + script: Union["i.Script", Dict[str, Any], "NotSet"] + ignore_failure: Union[bool, "NotSet"] def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - inner_hits: Union[ - "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + ignore_failure: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(field, NotSet): - kwargs["field"] = str(field) - if not isinstance(inner_hits, NotSet): - kwargs["inner_hits"] = inner_hits - if not isinstance(max_concurrent_group_searches, NotSet): - kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches - if not isinstance(collapse, NotSet): - kwargs["collapse"] = collapse + if not isinstance(script, NotSet): + kwargs["script"] = script + if not isinstance(ignore_failure, NotSet): + kwargs["ignore_failure"] = ignore_failure + super().__init__(kwargs) + + +class SortOptions(AttrDict[Any]): + """ + :arg _score: No documentation available. + :arg _doc: No documentation available. + :arg _geo_distance: No documentation available. + :arg _script: No documentation available. + """ + + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, + _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(_score, NotSet): + kwargs["_score"] = _score + if not isinstance(_doc, NotSet): + kwargs["_doc"] = _doc + if not isinstance(_geo_distance, NotSet): + kwargs["_geo_distance"] = _geo_distance + if not isinstance(_script, NotSet): + kwargs["_script"] = _script super().__init__(kwargs) @@ -1590,45 +1536,22 @@ def __init__( super().__init__(kwargs) -class IntervalsPrefix(AttrDict[Any]): - """ - :arg analyzer: Analyzer used to analyze the `prefix`. - :arg prefix: (required)Beginning characters of terms you wish to find - in the top-level field. - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `prefix` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. - """ - - analyzer: Union[str, "NotSet"] - prefix: Union[str, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] - - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - prefix: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(analyzer, NotSet): - kwargs["analyzer"] = analyzer - if not isinstance(prefix, NotSet): - kwargs["prefix"] = prefix - if not isinstance(use_field, NotSet): - kwargs["use_field"] = str(use_field) - super().__init__(kwargs) - - -class IntervalsAnyOf(AttrDict[Any]): +class IntervalsAllOf(AttrDict[Any]): """ - :arg intervals: (required)An array of rules to match. + :arg intervals: (required) An array of rules to combine. All rules + must produce a match in a document for the overall source to + match. + :arg max_gaps: Maximum number of positions between the matching terms. + Intervals produced by the rules further apart than this are not + considered matches. + :arg ordered: If `true`, intervals produced by the rules should appear + in the order in which they are specified. :arg filter: Rule used to filter returned intervals. """ intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] + max_gaps: Union[int, "NotSet"] + ordered: Union[bool, "NotSet"] filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] def __init__( @@ -1637,31 +1560,29 @@ def __init__( intervals: Union[ List["i.IntervalsContainer"], Dict[str, Any], "NotSet" ] = NOT_SET, + max_gaps: Union[int, "NotSet"] = NOT_SET, + ordered: Union[bool, "NotSet"] = NOT_SET, filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): if not isinstance(intervals, NotSet): kwargs["intervals"] = intervals + if not isinstance(max_gaps, NotSet): + kwargs["max_gaps"] = max_gaps + if not isinstance(ordered, NotSet): + kwargs["ordered"] = ordered if not isinstance(filter, NotSet): kwargs["filter"] = filter super().__init__(kwargs) -class IntervalsAllOf(AttrDict[Any]): +class IntervalsAnyOf(AttrDict[Any]): """ - :arg intervals: (required)An array of rules to combine. All rules must - produce a match in a document for the overall source to match. - :arg max_gaps: Maximum number of positions between the matching terms. - Intervals produced by the rules further apart than this are not - considered matches. - :arg ordered: If `true`, intervals produced by the rules should appear - in the order in which they are specified. + :arg intervals: (required) An array of rules to match. :arg filter: Rule used to filter returned intervals. """ intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] - max_gaps: Union[int, "NotSet"] - ordered: Union[bool, "NotSet"] filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] def __init__( @@ -1670,17 +1591,11 @@ def __init__( intervals: Union[ List["i.IntervalsContainer"], Dict[str, Any], "NotSet" ] = NOT_SET, - max_gaps: Union[int, "NotSet"] = NOT_SET, - ordered: Union[bool, "NotSet"] = NOT_SET, filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): if not isinstance(intervals, NotSet): kwargs["intervals"] = intervals - if not isinstance(max_gaps, NotSet): - kwargs["max_gaps"] = max_gaps - if not isinstance(ordered, NotSet): - kwargs["ordered"] = ordered if not isinstance(filter, NotSet): kwargs["filter"] = filter super().__init__(kwargs) @@ -1692,7 +1607,7 @@ class IntervalsFuzzy(AttrDict[Any]): :arg fuzziness: Maximum edit distance allowed for matching. :arg prefix_length: Number of beginning characters left unchanged when creating expansions. - :arg term: (required)The term to match. + :arg term: (required) The term to match. :arg transpositions: Indicates whether edits include transpositions of two adjacent characters (for example, `ab` to `ba`). :arg use_field: If specified, match intervals from this field rather @@ -1734,38 +1649,6 @@ def __init__( super().__init__(kwargs) -class IntervalsWildcard(AttrDict[Any]): - """ - :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the - top-level field's analyzer. - :arg pattern: (required)Wildcard pattern used to find matching terms. - :arg use_field: If specified, match intervals from this field rather - than the top-level field. The `pattern` is normalized using the - search analyzer from this field, unless `analyzer` is specified - separately. - """ - - analyzer: Union[str, "NotSet"] - pattern: Union[str, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] - - def __init__( - self, - *, - analyzer: Union[str, "NotSet"] = NOT_SET, - pattern: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(analyzer, NotSet): - kwargs["analyzer"] = analyzer - if not isinstance(pattern, NotSet): - kwargs["pattern"] = pattern - if not isinstance(use_field, NotSet): - kwargs["use_field"] = str(use_field) - super().__init__(kwargs) - - class IntervalsMatch(AttrDict[Any]): """ :arg analyzer: Analyzer used to analyze terms in the query. @@ -1773,7 +1656,7 @@ class IntervalsMatch(AttrDict[Any]): Terms further apart than this are not considered matches. :arg ordered: If `true`, matching terms must appear in their specified order. - :arg query: (required)Text you wish to find in the provided field. + :arg query: (required) Text you wish to find in the provided field. :arg use_field: If specified, match intervals from this field rather than the top-level field. The `term` is normalized using the search analyzer from this field, unless `analyzer` is specified @@ -1814,58 +1697,98 @@ def __init__( super().__init__(kwargs) -class TextEmbedding(AttrDict[Any]): - """ - :arg model_id: (required)No documentation available. - :arg model_text: (required)No documentation available. +class IntervalsPrefix(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze the `prefix`. + :arg prefix: (required) Beginning characters of terms you wish to find + in the top-level field. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `prefix` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. """ - model_id: Union[str, "NotSet"] - model_text: Union[str, "NotSet"] + analyzer: Union[str, "NotSet"] + prefix: Union[str, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] def __init__( self, *, - model_id: Union[str, "NotSet"] = NOT_SET, - model_text: Union[str, "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + prefix: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(model_id, NotSet): - kwargs["model_id"] = model_id - if not isinstance(model_text, NotSet): - kwargs["model_text"] = model_text + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(prefix, NotSet): + kwargs["prefix"] = prefix + if not isinstance(use_field, NotSet): + kwargs["use_field"] = str(use_field) super().__init__(kwargs) -class SpanFirstQuery(QueryBase): +class IntervalsWildcard(AttrDict[Any]): """ - :arg end: (required)Controls the maximum end position permitted in a - match. - :arg match: (required)Can be any other span type query. + :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the + top-level field's analyzer. + :arg pattern: (required) Wildcard pattern used to find matching terms. + :arg use_field: If specified, match intervals from this field rather + than the top-level field. The `pattern` is normalized using the + search analyzer from this field, unless `analyzer` is specified + separately. """ - end: Union[int, "NotSet"] - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + analyzer: Union[str, "NotSet"] + pattern: Union[str, "NotSet"] + use_field: Union[str, "InstrumentedField", "NotSet"] def __init__( self, *, - end: Union[int, "NotSet"] = NOT_SET, - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + analyzer: Union[str, "NotSet"] = NOT_SET, + pattern: Union[str, "NotSet"] = NOT_SET, + use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(end, NotSet): - kwargs["end"] = end - if not isinstance(match, NotSet): - kwargs["match"] = match - super().__init__(**kwargs) + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + if not isinstance(pattern, NotSet): + kwargs["pattern"] = pattern + if not isinstance(use_field, NotSet): + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + +class TextEmbedding(AttrDict[Any]): + """ + :arg model_id: (required) No documentation available. + :arg model_text: (required) No documentation available. + """ + + model_id: Union[str, "NotSet"] + model_text: Union[str, "NotSet"] + + def __init__( + self, + *, + model_id: Union[str, "NotSet"] = NOT_SET, + model_text: Union[str, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(model_id, NotSet): + kwargs["model_id"] = model_id + if not isinstance(model_text, NotSet): + kwargs["model_text"] = model_text + super().__init__(kwargs) class SpanContainingQuery(QueryBase): """ - :arg big: (required)Can be any span query. Matching spans from `big` + :arg big: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. - :arg little: (required)Can be any span query. Matching spans from + :arg little: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. """ @@ -1888,8 +1811,8 @@ def __init__( class SpanFieldMaskingQuery(QueryBase): """ - :arg field: (required)No documentation available. - :arg query: (required)No documentation available. + :arg field: (required) No documentation available. + :arg query: (required) No documentation available. """ field: Union[str, "InstrumentedField", "NotSet"] @@ -1909,10 +1832,34 @@ def __init__( super().__init__(**kwargs) +class SpanFirstQuery(QueryBase): + """ + :arg end: (required) Controls the maximum end position permitted in a + match. + :arg match: (required) Can be any other span type query. + """ + + end: Union[int, "NotSet"] + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + end: Union[int, "NotSet"] = NOT_SET, + match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(end, NotSet): + kwargs["end"] = end + if not isinstance(match, NotSet): + kwargs["match"] = match + super().__init__(**kwargs) + + class SpanMultiTermQuery(QueryBase): """ - :arg match: (required)Should be a multi term query (one of `wildcard`, - `fuzzy`, `prefix`, `range`, or `regexp` query). + :arg match: (required) Should be a multi term query (one of + `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). """ match: Union[Query, "NotSet"] @@ -1925,7 +1872,7 @@ def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): class SpanNearQuery(QueryBase): """ - :arg clauses: (required)Array of one or more other span type queries. + :arg clauses: (required) Array of one or more other span type queries. :arg in_order: Controls whether matches are required to be in-order. :arg slop: Controls the maximum number of intervening unmatched positions permitted. @@ -1952,57 +1899,14 @@ def __init__( super().__init__(**kwargs) -class SpanWithinQuery(QueryBase): - """ - :arg big: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. - :arg little: (required)Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. - """ - - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - - def __init__( - self, - *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(big, NotSet): - kwargs["big"] = big - if not isinstance(little, NotSet): - kwargs["little"] = little - super().__init__(**kwargs) - - -class SpanOrQuery(QueryBase): - """ - :arg clauses: (required)Array of one or more other span type queries. - """ - - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] - - def __init__( - self, - *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(clauses, NotSet): - kwargs["clauses"] = clauses - super().__init__(**kwargs) - - class SpanNotQuery(QueryBase): """ :arg dist: The number of tokens from within the include span that can’t have overlap with the exclude span. Equivalent to setting both `pre` and `post`. - :arg exclude: (required)Span query whose matches must not overlap + :arg exclude: (required) Span query whose matches must not overlap those returned. - :arg include: (required)Span query whose matches are filtered. + :arg include: (required) Span query whose matches are filtered. :arg post: The number of tokens after the include span that can’t have overlap with the exclude span. :arg pre: The number of tokens before the include span that can’t have @@ -2038,57 +1942,81 @@ def __init__( super().__init__(**kwargs) -class ScriptSort(AttrDict[Any]): +class SpanOrQuery(QueryBase): """ - :arg order: No documentation available. - :arg script: (required)No documentation available. - :arg type: No documentation available. - :arg mode: No documentation available. - :arg nested: No documentation available. + :arg clauses: (required) Array of one or more other span type queries. """ - order: Union[Literal["asc", "desc"], "NotSet"] - script: Union["i.Script", Dict[str, Any], "NotSet"] - type: Union[Literal["string", "number", "version"], "NotSet"] - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] def __init__( self, *, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(order, NotSet): - kwargs["order"] = order - if not isinstance(script, NotSet): - kwargs["script"] = script - if not isinstance(type, NotSet): - kwargs["type"] = type - if not isinstance(mode, NotSet): - kwargs["mode"] = mode - if not isinstance(nested, NotSet): - kwargs["nested"] = nested - super().__init__(kwargs) + if not isinstance(clauses, NotSet): + kwargs["clauses"] = clauses + super().__init__(**kwargs) -class ScoreSort(AttrDict[Any]): +class SpanWithinQuery(QueryBase): """ - :arg order: No documentation available. + :arg big: (required) Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg little: (required) Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. """ - order: Union[Literal["asc", "desc"], "NotSet"] + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] def __init__( - self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + self, + *, + big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, ): - if not isinstance(order, NotSet): - kwargs["order"] = order - super().__init__(kwargs) + if not isinstance(big, NotSet): + kwargs["big"] = big + if not isinstance(little, NotSet): + kwargs["little"] = little + super().__init__(**kwargs) + + +class HighlightField(HighlightBase): + """ + :arg fragment_offset: No documentation available. + :arg matched_fields: No documentation available. + :arg analyzer: No documentation available. + """ + + fragment_offset: Union[int, "NotSet"] + matched_fields: Union[ + Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + ] + analyzer: Union[str, Dict[str, Any], "NotSet"] + + def __init__( + self, + *, + fragment_offset: Union[int, "NotSet"] = NOT_SET, + matched_fields: Union[ + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "NotSet", + ] = NOT_SET, + analyzer: Union[str, Dict[str, Any], "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(fragment_offset, NotSet): + kwargs["fragment_offset"] = fragment_offset + if not isinstance(matched_fields, NotSet): + kwargs["matched_fields"] = str(matched_fields) + if not isinstance(analyzer, NotSet): + kwargs["analyzer"] = analyzer + super().__init__(**kwargs) class GeoDistanceSort(AttrDict[Any]): @@ -2136,38 +2064,57 @@ def __init__( super().__init__(kwargs) -class HighlightField(HighlightBase): +class ScoreSort(AttrDict[Any]): """ - :arg fragment_offset: No documentation available. - :arg matched_fields: No documentation available. - :arg analyzer: No documentation available. + :arg order: No documentation available. """ - fragment_offset: Union[int, "NotSet"] - matched_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" - ] - analyzer: Union[str, "NotSet"] + order: Union[Literal["asc", "desc"], "NotSet"] + + def __init__( + self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + ): + if not isinstance(order, NotSet): + kwargs["order"] = order + super().__init__(kwargs) + + +class ScriptSort(AttrDict[Any]): + """ + :arg order: No documentation available. + :arg script: (required) No documentation available. + :arg type: No documentation available. + :arg mode: No documentation available. + :arg nested: No documentation available. + """ + + order: Union[Literal["asc", "desc"], "NotSet"] + script: Union["i.Script", Dict[str, Any], "NotSet"] + type: Union[Literal["string", "number", "version"], "NotSet"] + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] def __init__( self, *, - fragment_offset: Union[int, "NotSet"] = NOT_SET, - matched_fields: Union[ - Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, + order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, + mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, + nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, **kwargs: Any, ): - if not isinstance(fragment_offset, NotSet): - kwargs["fragment_offset"] = fragment_offset - if not isinstance(matched_fields, NotSet): - kwargs["matched_fields"] = str(matched_fields) - if not isinstance(analyzer, NotSet): - kwargs["analyzer"] = analyzer - super().__init__(**kwargs) + if not isinstance(order, NotSet): + kwargs["order"] = order + if not isinstance(script, NotSet): + kwargs["script"] = script + if not isinstance(type, NotSet): + kwargs["type"] = type + if not isinstance(mode, NotSet): + kwargs["mode"] = mode + if not isinstance(nested, NotSet): + kwargs["nested"] = nested + super().__init__(kwargs) class IntervalsContainer(AttrDict[Any]): @@ -2292,7 +2239,7 @@ class NestedSortValue(AttrDict[Any]): :arg filter: No documentation available. :arg max_children: No documentation available. :arg nested: No documentation available. - :arg path: (required)No documentation available. + :arg path: (required) No documentation available. """ filter: Union[Query, "NotSet"] diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index aafe9065..0519279d 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -302,12 +302,13 @@ class Boosting(Query): Returns documents matching a `positive` query while reducing the relevance score of documents that also match a `negative` query. - :arg negative: (required)Query used to decrease the relevance score of - matching documents. - :arg positive: (required)Any returned documents must match this query. - :arg negative_boost: (required)Floating point number between 0 and 1.0 - used to decrease the relevance scores of documents matching the - `negative` query. + :arg negative: (required) Query used to decrease the relevance score + of matching documents. + :arg positive: (required) Any returned documents must match this + query. + :arg negative_boost: (required) Floating point number between 0 and + 1.0 used to decrease the relevance scores of documents matching + the `negative` query. """ name = "boosting" @@ -358,10 +359,10 @@ class CombinedFields(Query): The `combined_fields` query supports searching multiple text fields as if their contents had been indexed into one combined field. - :arg query: (required)Text to search for in the provided `fields`. The - `combined_fields` query analyzes the provided text before + :arg query: (required) Text to search for in the provided `fields`. + The `combined_fields` query analyzes the provided text before performing a search. - :arg fields: (required)List of fields to search. Field wildcard + :arg fields: (required) List of fields to search. Field wildcard patterns are allowed. Only `text` fields are supported, and they must all have the same search `analyzer`. :arg auto_generate_synonyms_phrase_query: If true, match phrase @@ -404,7 +405,7 @@ class ConstantScore(Query): Wraps a filter query and returns every matching document with a relevance score equal to the `boost` parameter value. - :arg filter: (required)Filter query you wish to run. Any returned + :arg filter: (required) Filter query you wish to run. Any returned documents must match this query. Filter queries do not calculate relevance scores. To speed up performance, Elasticsearch automatically caches frequently used filter queries. @@ -427,7 +428,7 @@ class DisMax(Query): relevance score from any matching clause, plus a tie breaking increment for any additional matching subqueries. - :arg queries: (required)One or more query clauses. Returned documents + :arg queries: (required) One or more query clauses. Returned documents must match one or more of these queries. If a document matches multiple queries, Elasticsearch uses the highest relevance score. :arg tie_breaker: Floating point number between 0 and 1.0 used to @@ -456,9 +457,23 @@ class DistanceFeature(Query): date or point. For example, you can use this query to give more weight to documents closer to a certain date or location. - :arg untyped: An instance of ``UntypedDistanceFeatureQuery``. - :arg geo: An instance of ``GeoDistanceFeatureQuery``. - :arg date: An instance of ``DateDistanceFeatureQuery``. + :arg pivot: (required) Distance from the `origin` at which relevance + scores receive half of the `boost` value. If the `field` value is + a `date` or `date_nanos` field, the `pivot` value must be a time + unit, such as `1h` or `10d`. If the `field` value is a `geo_point` + field, the `pivot` value must be a distance unit, such as `1km` or + `12m`. + :arg field: (required) Name of the field used to calculate distances. + This field must meet the following criteria: be a `date`, + `date_nanos` or `geo_point` field; have an `index` mapping + parameter value of `true`, which is the default; have an + `doc_values` mapping parameter value of `true`, which is the + default. + :arg origin: (required) Date or point of origin used to calculate + distances. If the `field` value is a `date` or `date_nanos` field, + the `origin` value must be a date. Date Math, such as `now-1h`, is + supported. If the field value is a `geo_point` field, the `origin` + value must be a geopoint. """ name = "distance_feature" @@ -466,32 +481,19 @@ class DistanceFeature(Query): def __init__( self, *, - untyped: Union["i.UntypedDistanceFeatureQuery", "NotSet"] = NOT_SET, - geo: Union["i.GeoDistanceFeatureQuery", "NotSet"] = NOT_SET, - date: Union["i.DateDistanceFeatureQuery", "NotSet"] = NOT_SET, + pivot: Any = NOT_SET, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + origin: Any = NOT_SET, **kwargs: Any, ): - if not isinstance(untyped, NotSet): - kwargs = cast( - Dict[str, Any], - untyped.to_dict() if hasattr(untyped, "to_dict") else untyped, - ) - elif not isinstance(geo, NotSet): - kwargs = cast( - Dict[str, Any], geo.to_dict() if hasattr(geo, "to_dict") else geo - ) - elif not isinstance(date, NotSet): - kwargs = cast( - Dict[str, Any], date.to_dict() if hasattr(date, "to_dict") else date - ) - super().__init__(**kwargs) + super().__init__(pivot=pivot, field=field, origin=origin, **kwargs) class Exists(Query): """ Returns documents that contain an indexed value for a field. - :arg field: (required)Name of the field you wish to search. + :arg field: (required) Name of the field you wish to search. """ name = "exists" @@ -623,7 +625,7 @@ class GeoDistance(Query): Matches `geo_point` and `geo_shape` values within a given distance of a geopoint. - :arg distance: (required)The radius of the circle centred on the + :arg distance: (required) The radius of the circle centred on the specified location. Points which fall into this circle are considered to be matches. :arg distance_type: How to compute the distance. Set to `plane` for a @@ -708,10 +710,10 @@ class HasChild(Query): Returns parent documents whose joined child documents match a provided query. - :arg query: (required)Query you wish to run on child documents of the + :arg query: (required) Query you wish to run on child documents of the `type` field. If a child document matches the search, the query returns the parent document. - :arg type: (required)Name of the child relationship mapped for the + :arg type: (required) Name of the child relationship mapped for the `join` field. :arg ignore_unmapped: Indicates whether to ignore an unmapped `type` and not return any documents instead of an error. @@ -764,11 +766,11 @@ class HasParent(Query): Returns child documents whose joined parent document matches a provided query. - :arg parent_type: (required)Name of the parent relationship mapped for - the `join` field. - :arg query: (required)Query you wish to run on parent documents of the - `parent_type` field. If a parent document matches the search, the - query returns its child documents. + :arg parent_type: (required) Name of the parent relationship mapped + for the `join` field. + :arg query: (required) Query you wish to run on parent documents of + the `parent_type` field. If a parent document matches the search, + the query returns its child documents. :arg ignore_unmapped: Indicates whether to ignore an unmapped `parent_type` and not return any documents instead of an error. You can use this parameter to query multiple indices that may not @@ -846,7 +848,7 @@ class Knn(Query): similarity metric. knn query finds nearest vectors through approximate search on indexed dense_vectors. - :arg field: (required)The name of the vector field to search against + :arg field: (required) The name of the vector field to search against :arg query_vector: The query vector :arg query_vector_builder: The query vector builder. You must provide a query_vector_builder or query_vector, but not both. @@ -1033,7 +1035,7 @@ class MoreLikeThis(Query): """ Returns documents that are "like" a given set of documents. - :arg like: (required)Specifies free form text and/or a single or + :arg like: (required) Specifies free form text and/or a single or multiple documents for which you want to find similar documents. :arg analyzer: The analyzer that is used to analyze the free form text. Defaults to the analyzer associated with the first field in @@ -1139,7 +1141,7 @@ class MultiMatch(Query): value across multiple fields. The provided text is analyzed before matching. - :arg query: (required)Text, number, boolean value or date you wish to + :arg query: (required) Text, number, boolean value or date you wish to find in the provided field. :arg analyzer: Analyzer used to convert the text in the query value into tokens. @@ -1240,8 +1242,8 @@ class Nested(Query): Wraps another query to search nested fields. If an object matches the search, the nested query returns the root parent document. - :arg path: (required)Path to the nested object you wish to search. - :arg query: (required)Query you wish to run on nested objects in the + :arg path: (required) Path to the nested object you wish to search. + :arg query: (required) Query you wish to run on nested objects in the path. :arg ignore_unmapped: Indicates whether to ignore an unmapped path and not return any documents instead of an error. @@ -1304,7 +1306,7 @@ class Percolate(Query): """ Matches queries stored in an index. - :arg field: (required)Field that holds the indexed queries. The field + :arg field: (required) Field that holds the indexed queries. The field must use the `percolator` mapping type. :arg document: The source of the document being percolated. :arg documents: An array of sources of the documents being percolated. @@ -1352,7 +1354,7 @@ class Pinned(Query): Promotes selected documents to rank higher than those matching a given query. - :arg organic: (required)Any choice of query used to rank documents + :arg organic: (required) Any choice of query used to rank documents which will be ranked below the "pinned" documents. :arg ids: Document IDs listed in the order they are to appear in results. Required if `docs` is not specified. @@ -1402,7 +1404,7 @@ class QueryString(Query): Returns documents based on a provided query string, using a parser with a strict syntax. - :arg query: (required)Query string you wish to parse and use for + :arg query: (required) Query string you wish to parse and use for search. :arg allow_leading_wildcard: If `true`, the wildcard characters `*` and `?` are allowed as the first character of the query string. @@ -1551,7 +1553,7 @@ class RankFeature(Query): Boosts the relevance score of documents based on the numeric value of a `rank_feature` or `rank_features` field. - :arg field: (required)`rank_feature` or `rank_features` field used to + :arg field: (required) `rank_feature` or `rank_features` field used to boost relevance scores. :arg saturation: Saturation function used to boost relevance scores based on the value of the rank feature `field`. @@ -1618,9 +1620,9 @@ class Rule(Query): """ No documentation available. - :arg ruleset_ids: (required)No documentation available. - :arg match_criteria: (required)No documentation available. - :arg organic: (required)No documentation available. + :arg ruleset_ids: (required) No documentation available. + :arg match_criteria: (required) No documentation available. + :arg organic: (required) No documentation available. """ name = "rule" @@ -1649,7 +1651,7 @@ class Script(Query): Filters documents based on a provided script. The script query is typically used in a filter context. - :arg script: (required)Contains a script to run as a query. This + :arg script: (required) Contains a script to run as a query. This script must return a boolean value, `true` or `false`. """ @@ -1668,8 +1670,8 @@ class ScriptScore(Query): """ Uses a script to provide a custom score for returned documents. - :arg query: (required)Query used to return documents. - :arg script: (required)Script used to compute the score of documents + :arg query: (required) Query used to return documents. + :arg script: (required) Script used to compute the score of documents returned by the query. Important: final relevance scores from the `script_score` query cannot be negative. :arg min_score: Documents with a score lower than this floating point @@ -1696,8 +1698,8 @@ class Semantic(Query): """ A semantic query to semantic_text field types - :arg query: (required)The query text - :arg field: (required)The field to query, which must be a + :arg query: (required) The query text + :arg field: (required) The field to query, which must be a semantic_text field type """ @@ -1734,7 +1736,7 @@ class SimpleQueryString(Query): Returns documents based on a provided query string, using a parser with a limited but fault-tolerant syntax. - :arg query: (required)Query string in the simple query string syntax + :arg query: (required) Query string in the simple query string syntax you wish to parse and use for search. :arg analyzer: Analyzer used to convert text in the query string into tokens. @@ -1808,9 +1810,9 @@ class SpanContaining(Query): """ Returns matches which enclose another span query. - :arg little: (required)Can be any span query. Matching spans from + :arg little: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. - :arg big: (required)Can be any span query. Matching spans from `big` + :arg big: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. """ @@ -1831,8 +1833,8 @@ class SpanFieldMasking(Query): Wrapper to allow span queries to participate in composite single-field span queries by _lying_ about their search field. - :arg query: (required)No documentation available. - :arg field: (required)No documentation available. + :arg query: (required) No documentation available. + :arg field: (required) No documentation available. """ name = "span_field_masking" @@ -1851,8 +1853,8 @@ class SpanFirst(Query): """ Matches spans near the beginning of a field. - :arg match: (required)Can be any other span type query. - :arg end: (required)Controls the maximum end position permitted in a + :arg match: (required) Can be any other span type query. + :arg end: (required) Controls the maximum end position permitted in a match. """ @@ -1874,8 +1876,8 @@ class SpanMulti(Query): `prefix`, `range`, or `regexp` query) as a `span` query, so it can be nested. - :arg match: (required)Should be a multi term query (one of `wildcard`, - `fuzzy`, `prefix`, `range`, or `regexp` query). + :arg match: (required) Should be a multi term query (one of + `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). """ name = "span_multi" @@ -1893,7 +1895,7 @@ class SpanNear(Query): maximum number of intervening unmatched positions, as well as whether matches are required to be in-order. - :arg clauses: (required)Array of one or more other span type queries. + :arg clauses: (required) Array of one or more other span type queries. :arg in_order: Controls whether matches are required to be in-order. :arg slop: Controls the maximum number of intervening unmatched positions permitted. @@ -1918,9 +1920,9 @@ class SpanNot(Query): within x tokens before (controlled by the parameter `pre`) or y tokens after (controlled by the parameter `post`) another span query. - :arg exclude: (required)Span query whose matches must not overlap + :arg exclude: (required) Span query whose matches must not overlap those returned. - :arg include: (required)Span query whose matches are filtered. + :arg include: (required) Span query whose matches are filtered. :arg dist: The number of tokens from within the include span that can’t have overlap with the exclude span. Equivalent to setting both `pre` and `post`. @@ -1951,7 +1953,7 @@ class SpanOr(Query): """ Matches the union of its span clauses. - :arg clauses: (required)Array of one or more other span type queries. + :arg clauses: (required) Array of one or more other span type queries. """ name = "span_or" @@ -1990,9 +1992,9 @@ class SpanWithin(Query): """ Returns matches which are enclosed inside another span query. - :arg little: (required)Can be any span query. Matching spans from + :arg little: (required) Can be any span query. Matching spans from `little` that are enclosed within `big` are returned. - :arg big: (required)Can be any span query. Matching spans from + :arg big: (required) Can be any span query. Matching spans from `little` that are enclosed within `big` are returned. """ @@ -2014,7 +2016,7 @@ class SparseVector(Query): convert a query into a list of token-weight pairs, queries against a sparse vector field. - :arg field: (required)The name of the field that contains the token- + :arg field: (required) The name of the field that contains the token- weight pairs to be searched against. This field must be a mapped sparse_vector field. :arg query_vector: Dictionary of precomputed sparse vectors and their @@ -2201,7 +2203,7 @@ class Wrapper(Query): """ A query that accepts any other query as base64 encoded string. - :arg query: (required)A base64 encoded query. The binary data format + :arg query: (required) A base64 encoded query. The binary data format can be any of JSON, YAML, CBOR or SMILE encodings """ @@ -2215,7 +2217,7 @@ class Type(Query): """ No documentation available. - :arg value: (required)No documentation available. + :arg value: (required) No documentation available. """ name = "type" diff --git a/utils/generator.py b/utils/generator.py index b871409a..458acbc2 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -33,7 +33,14 @@ query_py = jinja_env.get_template("query.py.tpl") interfaces_py = jinja_env.get_template("interfaces.py.tpl") -RESERVED = {"from": "from_"} +# map with name replacements for Elasticsearch attributes +PROP_REPLACEMENTS = {"from": "from_"} + +# map with Elasticsearch type replacements +# keys and values are in given in "{namespace}:{name}" format +TYPE_REPLACEMENTS = { + "_types.query_dsl:DistanceFeatureQuery": "_types.query_dsl:DistanceFeatureQueryBase", +} def wrapped_doc(text, width=70, initial_indent="", subsequent_indent=""): @@ -65,6 +72,8 @@ def add_not_set(type_): class ElasticsearchSchema: + """Operations related to the Elasticsearch schema.""" + def __init__(self): response = None for branch in [f"{VERSION[0]}.{VERSION[1]}", "main"]: @@ -78,6 +87,10 @@ def __init__(self): if not response: raise RuntimeError("Could not download Elasticsearch schema") self.schema = json.loads(response.read()) + + # Interfaces collects interfaces that are seen while traversing the schema. + # Any interfaces collected here are then rendered as Python in the + # interfaces.py module. self.interfaces = set() def find_type(self, name, namespace=None): @@ -91,6 +104,13 @@ def reset_interfaces(self): self.interfaces = set() def get_python_type(self, schema_type): + """Obtain Python typing details for a given schema type + + This method returns a tuple. The first element is a string with the + Python type hint. The second element is a dictionary with Python DSL + specific typing details to be stored in the DslBase._param_defs + attribute (or None if the type does not need to be in _param_defs). + """ if schema_type["kind"] == "instance_of": type_name = schema_type["type"] if type_name["namespace"] in ["_types", "internal", "_builtins"]: @@ -109,6 +129,7 @@ def get_python_type(self, schema_type): elif type_name["name"] == "Field": return 'Union[str, "InstrumentedField"]', None else: + # not an instance of a native type, so we get the type and try again return self.get_python_type( self.find_type(type_name["name"], type_name["namespace"]) ) @@ -116,22 +137,25 @@ def get_python_type(self, schema_type): type_name["namespace"] == "_types.query_dsl" and type_name["name"] == "QueryContainer" ): + # QueryContainer maps to the DSL's Query class return "Query", {"type": "query"} else: + # for any other instances we get the type and recurse type_ = self.find_type(type_name["name"], type_name["namespace"]) if type_: return self.get_python_type(type_) elif schema_type["kind"] == "type_alias": + # for an alias, we use the aliased type return self.get_python_type(schema_type["type"]) elif schema_type["kind"] == "array_of": + # for arrays we use List[element_type] type_, param = self.get_python_type(schema_type["value"]) - if type_.startswith("Union["): - types = type_[6:-1].split(",") return f"List[{type_}]", {**param, "multi": True} if param else None elif schema_type["kind"] == "dictionary_of": + # for dicts we use Mapping[key_type, value_type] key_type, key_param = self.get_python_type(schema_type["key"]) value_type, value_param = self.get_python_type(schema_type["value"]) return f"Mapping[{key_type}, {value_type}]", None @@ -143,6 +167,7 @@ def get_python_type(self, schema_type): and schema_type["items"][1]["kind"] == "array_of" and schema_type["items"][0] == schema_type["items"][1]["value"] ): + # special kind of unions in the form Union[type, List[type]] type_, param = self.get_python_type(schema_type["items"][0]) return ( f"Union[{type_}, List[{type_}]]", @@ -154,18 +179,23 @@ def get_python_type(self, schema_type): and schema_type["items"][1]["kind"] == "instance_of" and schema_type["items"][0]["type"] == {"name": "T", "namespace": "_spec_utils.PipeSeparatedFlags"} + and schema_type["items"][1]["type"] + == {"name": "string", "namespace": "_builtins"} ): + # for now we treat PipeSeparatedFlags as a special case self.interfaces.add("PipeSeparatedFlags") return '"i.PipeSeparatedFlags"', None else: + # generic union type types = list( - dict.fromkeys( + dict.fromkeys( # eliminate duplicates [self.get_python_type(t) for t in schema_type["items"]] ) ) return "Union[" + ", ".join([type_ for type_, _ in types]) + "]", None elif schema_type["kind"] == "enum": + # enums are mapped to Literal[member, ...] return ( "Literal[" + ", ".join( @@ -177,12 +207,14 @@ def get_python_type(self, schema_type): elif schema_type["kind"] == "interface": if schema_type["name"]["namespace"] == "_types.query_dsl": + # handle specific DSL classes explicitly to map to existing + # Python DSL classes if schema_type["name"]["name"].endswith("RangeQuery"): return '"wrappers.Range[Any]"', None elif schema_type["name"]["name"].endswith("ScoreFunction"): name = schema_type["name"]["name"][:-8] if name == "FieldValueFactorScore": - name = "FieldValueFactor" # naming exception + name = "FieldValueFactor" # Python DSL uses different name return f'"f.{name}"', None elif schema_type["name"]["name"].endswith("DecayFunction"): return '"f.DecayFunction"', None @@ -191,15 +223,28 @@ def get_python_type(self, schema_type): elif schema_type["name"]["namespace"] == "_types.analysis" and schema_type[ "name" ]["name"].endswith("Analyzer"): - return "str", None + # not expanding analyzers at this time, maybe in the future + return "str, Dict[str, Any]", None + + # to handle other interfaces we generate a type of the same name + # and add the interface to the interfaces.py module self.interfaces.add(schema_type["name"]["name"]) return f"\"i.{schema_type['name']['name']}\"", None elif schema_type["kind"] == "user_defined_value": + # user_defined_value maps to Python's Any type return "Any", None raise RuntimeError(f"Cannot find Python type for {schema_type}") - def argument_to_python_type(self, arg): + def get_attribute_data(self, arg): + """Return the template definitions for a class attribute. + + This method returns a tuple. The first element is a dict with the + information to render the attribute. The second element is a dictionary + with Python DSL specific typing details to be stored in the + DslBase._param_defs attribute (or None if the type does not need to be + in _param_defs). + """ try: type_, param = schema.get_python_type(arg["type"]) except RuntimeError: @@ -207,125 +252,157 @@ def argument_to_python_type(self, arg): param = None if type_ != "Any": if "i." in type_: - type_ = add_dict_type(type_) + type_ = add_dict_type(type_) # interfaces can be given as dicts type_ = add_not_set(type_) - required = "(required)" if arg["required"] else "" + required = "(required) " if arg["required"] else "" doc = wrapped_doc( f":arg {arg['name']}: {required}{arg.get('description', 'No documentation available.')}", subsequent_indent=" ", ) - kwarg = { - "name": RESERVED.get(arg["name"], arg["name"]), + arg = { + "name": PROP_REPLACEMENTS.get(arg["name"], arg["name"]), "type": type_, "doc": doc, "required": arg["required"], } if param is not None: param = {"name": arg["name"], "param": param} - return kwarg, param + return arg, param - def instance_of_to_python_class(self, p, k): - instance = schema.find_type( - p["type"]["type"]["name"], p["type"]["type"]["namespace"] - ) - if instance["kind"] == "interface": - k["kwargs"] = [] - k["params"] = [] - for p in instance["properties"]: - kwarg, param = self.argument_to_python_type(p) - if kwarg["required"]: - i = 0 - for i in range(len(k["kwargs"])): - if k["kwargs"][i]["required"] is False: - break - k["kwargs"].insert(i, kwarg) + def property_to_python_class(self, p): + """Return a dictionary with template data necessary to render a schema + property as a Python class. + + Used for "container" sub-classes such as `QueryContainer`, where each + sub-class is represented by a Python DSL class. + + The format is as follows: + + ```python + { + "property_name": "the name of the property", + "name": "the class name to use for the property", + "docstring": "the formatted docstring as a list of strings", + "args": [ # a Python description of each class attribute + "name": "the name of the attribute", + "type": "the Python type hint for the attribute", + "doc": ["formatted lines of documentation to add to class docstring"], + "required": bool + ], + "params": [ + "name": "the attribute name", + "param": "the param dictionary to include in `_param_defs` for the class", + ], # a DSL-specific description of interesting attributes + "is_single_field": bool # True for single-key dicts with field key + "is_multi_field": bool # True for multi-key dicts with field keys + } + ``` + """ + k = { + "property_name": p["name"], + "name": "".join([w.title() for w in p["name"].split("_")]), + } + k["docstring"] = wrapped_doc(p.get("description")) + kind = p["type"]["kind"] + if kind == "instance_of": + namespace = p["type"]["type"]["namespace"] + name = p["type"]["type"]["name"] + if f"{namespace}:{name}" in TYPE_REPLACEMENTS: + namespace, name = TYPE_REPLACEMENTS[f"{namespace}:{name}"].split(":") + instance = schema.find_type(name, namespace) + if instance["kind"] == "interface": + k["args"] = [] + k["params"] = [] + for arg in instance["properties"]: + python_arg, param = self.get_attribute_data(arg) + if python_arg["required"]: + # insert in the right place so that all required arguments + # appear at the top of the argument list + i = 0 + for i in range(len(k["args"])): + if k["args"][i]["required"] is False: + break + k["args"].insert(i, python_arg) + else: + k["args"].append(python_arg) + if param: + k["params"].append(param) + else: + raise RuntimeError( + f"Cannot generate code for instances of kind '{instance['kind']}'" + ) + + elif kind == "dictionary_of": + key_type, _ = schema.get_python_type(p["type"]["key"]) + if "InstrumentedField" in key_type: + value_type, _ = schema.get_python_type(p["type"]["value"]) + if p["type"]["singleKey"]: + # special handling for single-key dicts with field key + k["args"] = [ + { + "name": "_field", + "type": add_not_set(key_type), + "doc": [":arg _field: The field to use in this query."], + "required": False, + }, + { + "name": "_value", + "type": add_not_set(add_dict_type(value_type)), + "doc": [":arg _value: The query value for the field."], + "required": False, + }, + ] + k["is_single_field"] = True else: - k["kwargs"].append(kwarg) - if param: - k["params"].append(param) - elif instance["kind"] == "type_alias": - if ( - "codegenNames" in instance - and instance["type"]["kind"] == "union_of" - and len(instance["type"]["items"]) == len(instance["codegenNames"]) - ): - k["kwargs"] = [] - for name, type_ in zip( - instance["codegenNames"], instance["type"]["items"] - ): - python_type, _ = self.get_python_type(type_) - k["kwargs"].append( + # special handling for multi-key dicts with field keys + k["args"] = [ { - "name": name, - "type": f'Union[{python_type}, "NotSet"]', + "name": "_fields", + "type": f"Optional[Mapping[{key_type}, {value_type}]]", "doc": [ - f":arg {name}: An instance of ``{python_type[3:-1]}``." + ":arg _fields: A dictionary of fields with their values." ], "required": False, - } - ) - k["has_type_alias"] = True - else: - raise RuntimeError("Cannot generate code for non-enum type aliases") - else: - raise RuntimeError( - f"Cannot generate code for instances of kind '{instance['kind']}'" - ) - return k - - def dictionary_of_to_python_class(self, p, k): - key_type, _ = schema.get_python_type(p["type"]["key"]) - if "InstrumentedField" in key_type: - value_type, _ = schema.get_python_type(p["type"]["value"]) - if p["type"]["singleKey"]: - k["kwargs"] = [ - { - "name": "_field", - "type": add_not_set(key_type), - "doc": [":arg _field: The field to use in this query."], - "required": False, - }, - { - "name": "_value", - "type": add_not_set(add_dict_type(value_type)), - "doc": [":arg _value: The query value for the field."], - "required": False, - }, - ] - k["has_field"] = True + }, + ] + k["is_multi_field"] = True else: - k["kwargs"] = [ - { - "name": "_fields", - "type": f"Optional[Mapping[{key_type}, {value_type}]]", - "doc": [ - ":arg _fields: A dictionary of fields with their values." - ], - "required": False, - }, - ] - k["has_fields"] = True - else: - raise RuntimeError(f"Cannot generate code for type {p['type']}") - return k + raise RuntimeError(f"Cannot generate code for type {p['type']}") - def property_to_python_class(self, p): - k = {"schema": p, "name": "".join([w.title() for w in p["name"].split("_")])} - k["docstring"] = wrapped_doc(p.get("description")) - kind = p["type"]["kind"] - if kind == "instance_of": - k = self.instance_of_to_python_class(p, k) - elif kind == "dictionary_of": - k = self.dictionary_of_to_python_class(p, k) else: raise RuntimeError(f"Cannot generate code for type {p['type']}") return k def interface_to_python_class(self, interface, interfaces): + """Return a dictionary with template data necessary to render an + interface a Python class. + + This is used to render interfaces that are referenced by container + classes. The current list of rendered interfaces is passed as a second + argument to allow this method to add more interfaces to it as they are + discovered. + + The returned format is as follows: + + ```python + { + "name": "the class name to use for the interface class", + "parent": "the parent class name", + "args": [ # a Python description of each class attribute + "name": "the name of the attribute", + "type": "the Python type hint for the attribute", + "doc": ["formatted lines of documentation to add to class docstring"], + "required": bool + ], + } + ``` + """ type_ = schema.find_type(interface) if type_["kind"] != "interface": raise RuntimeError(f"Type {interface} is not an interface") if "inherits" in type_ and "type" in type_["inherits"]: + # this class has parents, make sure we have all the parents in our + # list of interfaces to render parent = type_["inherits"]["type"]["name"] base = type_ while base and "inherits" in base and "type" in base["inherits"]: @@ -336,38 +413,38 @@ def interface_to_python_class(self, interface, interfaces): base["inherits"]["type"]["namespace"], ) else: + # no parent, will inherit from AttrDict parent = None - k = {"name": interface, "parent": parent, "properties": []} + k = {"name": interface, "parent": parent, "args": []} for arg in type_["properties"]: - arg_type, _ = schema.argument_to_python_type(arg) - k["properties"].append(arg_type) + arg_type, _ = schema.get_attribute_data(arg) + k["args"].append(arg_type) return k -def generate_query_classes(schema, filename): +def generate_query_py(schema, filename): + """Generate query.py with all the properties of `QueryContainer` as Python + classes. + """ classes = [] query_container = schema.find_type("QueryContainer", "_types.query_dsl") for p in query_container["properties"]: - k = schema.property_to_python_class(p) - classes.append(k) + classes.append(schema.property_to_python_class(p)) with open(filename, "wt") as f: - f.write( - query_py.render( - classes=classes, parent="Query", interfaces=sorted(schema.interfaces) - ) - ) + f.write(query_py.render(classes=classes, parent="Query")) print(f"Generated {filename}.") -def generate_interfaces(schema, interfaces, filename): +def generate_interfaces_py(schema, interfaces, filename): + """Generate interfaces.py""" classes = {} for interface in interfaces: if interface == "PipeSeparatedFlags": continue # handled as a special case schema.reset_interfaces() k = schema.interface_to_python_class(interface, interfaces) - for new_interface in schema.interfaces: + for new_interface in sorted(schema.interfaces): if new_interface not in interfaces: interfaces.append(new_interface) classes[k["name"]] = k @@ -399,6 +476,8 @@ def generate_interfaces(schema, interfaces, filename): if __name__ == "__main__": schema = ElasticsearchSchema() - generate_query_classes(schema, "elasticsearch_dsl/query.py") + generate_query_py(schema, "elasticsearch_dsl/query.py") interfaces = schema.interfaces - generate_interfaces(schema, sorted(interfaces), "elasticsearch_dsl/interfaces.py") + generate_interfaces_py( + schema, sorted(interfaces), "elasticsearch_dsl/interfaces.py" + ) diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index d48033d3..d178388c 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -1,3 +1,20 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from typing import Any, Dict, List, Literal, Mapping, Union from elasticsearch_dsl.document_base import InstrumentedField from elasticsearch_dsl import function as f, interfaces as i, Query @@ -8,32 +25,32 @@ PipeSeparatedFlags = str {% for k in classes %} class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endif %}): - {% if k.properties %} + {% if k.args %} """ - {% for p in k.properties %} - {% for line in p.doc %} + {% for arg in k.args %} + {% for line in arg.doc %} {{ line }} {% endfor %} {% endfor %} """ - {% for p in k.properties %} - {{ p.name }}: {{ p.type }} + {% for arg in k.args %} + {{ arg.name }}: {{ arg.type }} {% endfor %} def __init__( self, *, - {% for p in k.properties %} - {{ p.name }}: {{ p.type }} = NOT_SET, + {% for arg in k.args %} + {{ arg.name }}: {{ arg.type }} = NOT_SET, {% endfor %} **kwargs: Any ): - {% for p in k.properties %} - if not isinstance({{ p.name }}, NotSet): - {% if "InstrumentedField" in p.type %} - kwargs["{{ p.name }}"] = str({{ p.name }}) + {% for arg in k.args %} + if not isinstance({{ arg.name }}, NotSet): + {% if "InstrumentedField" in arg.type %} + kwargs["{{ arg.name }}"] = str({{ arg.name }}) {% else %} - kwargs["{{ p.name }}"] = {{ p.name }} + kwargs["{{ arg.name }}"] = {{ arg.name }} {% endif %} {% endfor %} {% if k.parent %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 1231d886..bf8899cb 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -148,16 +148,16 @@ class {{ k.name }}({{ parent }}): {% for line in k.docstring %} {{ line }} {% endfor %} - {% if k.kwargs %} + {% if k.args %} - {% for kwarg in k.kwargs %} + {% for kwarg in k.args %} {% for line in kwarg.doc %} {{ line }} {% endfor %} {% endfor %} {% endif %} """ - name = "{{ k.schema.name }}" + name = "{{ k.property_name }}" {% if k.params %} _param_defs = { {% for param in k.params %} @@ -172,11 +172,11 @@ class {{ k.name }}({{ parent }}): def __init__( self, - {% if k.kwargs and not k.has_field and not k.has_fields %} + {% if k.args and not k.is_single_field and not k.is_multi_field %} *, {% endif %} - {% for kwarg in k.kwargs %} - {{ kwarg.name }}: {{ kwarg.type }} = NOT_SET, + {% for arg in k.args %} + {{ arg.name }}: {{ arg.type }} = NOT_SET, {% endfor %} **kwargs: Any ): @@ -186,27 +186,18 @@ class {{ k.name }}({{ parent }}): for name in ScoreFunction._classes: if name in kwargs: functions.append({name: kwargs.pop(name)}) # type: ignore - {% elif k.has_field %} + {% elif k.is_single_field %} if not isinstance(_field, NotSet): kwargs[str(_field)] = _value - {% elif k.has_fields %} + {% elif k.is_multi_field %} if not isinstance(fields, NotSet): for field, value in _fields.items(): kwargs[str(field)] = value - {% elif k.has_type_alias %} - {% for kwarg in k.kwargs %} - {% if loop.index == 1 %} - if not isinstance({{ kwarg.name }}, NotSet): - {% else %} - elif not isinstance({{ kwarg.name }}, NotSet): - {% endif %} - kwargs = cast(Dict[str, Any], {{ kwarg.name }}.to_dict() if hasattr({{ kwarg.name }}, "to_dict") else {{ kwarg.name }}) - {% endfor %} {% endif %} super().__init__( - {% if not k.has_field and not k.has_fields and not k.has_type_alias %} - {% for kwarg in k.kwargs %} - {{ kwarg.name }}={{ kwarg.name }}, + {% if not k.is_single_field and not k.is_multi_field %} + {% for arg in k.args %} + {{ arg.name }}={{ arg.name }}, {% endfor %} {% endif %} **kwargs @@ -351,7 +342,7 @@ EMPTY_QUERY = MatchAll() return q __rand__ = __and__ - + {% elif k.name == "Terms" %} def _setattr(self, name: str, value: Any) -> None: super()._setattr(name, list(value)) From ffbbe1fcbbc317b5e17df2632f713de21e5f5a54 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 3 Sep 2024 19:45:26 +0100 Subject: [PATCH 09/27] add a unit test using some of the generated classes --- tests/_async/test_search.py | 78 ++++++++++++++++++++++++++++++++++++- tests/_sync/test_search.py | 78 ++++++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/tests/_async/test_search.py b/tests/_async/test_search.py index a932c9f2..cfb2d269 100644 --- a/tests/_async/test_search.py +++ b/tests/_async/test_search.py @@ -21,7 +21,15 @@ import pytest from pytest import raises -from elasticsearch_dsl import AsyncEmptySearch, AsyncSearch, Document, Q, query +from elasticsearch_dsl import ( + AsyncEmptySearch, + AsyncSearch, + Document, + Q, + interfaces, + query, + wrappers, +) from elasticsearch_dsl.exceptions import IllegalOperation @@ -530,6 +538,74 @@ def test_reverse() -> None: assert d == s.to_dict() +def test_code_generated_classes() -> None: + s = AsyncSearch() + s = ( + s.query(query.Match("title", interfaces.MatchQuery(query="python"))) + .query(~query.Match("title", interfaces.MatchQuery(query="ruby"))) + .query( + query.Knn( + field="title", + query_vector=[1.0, 2.0, 3.0], + num_candidates=10, + k=3, + filter=query.Range("year", wrappers.Range(gt="2004")), + ) + ) + .filter( + query.Term("category", interfaces.TermQuery(value="meetup")) + | query.Term("category", interfaces.TermQuery(value="conference")) + ) + .collapse("user_id") + .post_filter(query.Terms(tags=["prague", "czech"])) + .script_fields(more_attendees="doc['attendees'].value + 42") + ) + assert { + "query": { + "bool": { + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": {"value": "meetup"}}}, + {"term": {"category": {"value": "conference"}}}, + ] + } + } + ], + "must": [ + {"match": {"title": {"query": "python"}}}, + { + "knn": { + "field": "title", + "filter": [ + { + "range": { + "year": { + "gt": "2004", + }, + }, + }, + ], + "k": 3, + "num_candidates": 10, + "query_vector": [ + 1.0, + 2.0, + 3.0, + ], + }, + }, + ], + "must_not": [{"match": {"title": {"query": "ruby"}}}], + } + }, + "post_filter": {"terms": {"tags": ["prague", "czech"]}}, + "collapse": {"field": "user_id"}, + "script_fields": {"more_attendees": {"script": "doc['attendees'].value + 42"}}, + } == s.to_dict() + + def test_from_dict_doesnt_need_query() -> None: s = AsyncSearch.from_dict({"size": 5}) diff --git a/tests/_sync/test_search.py b/tests/_sync/test_search.py index fefa0ee2..30a01188 100644 --- a/tests/_sync/test_search.py +++ b/tests/_sync/test_search.py @@ -21,7 +21,15 @@ import pytest from pytest import raises -from elasticsearch_dsl import Document, EmptySearch, Q, Search, query +from elasticsearch_dsl import ( + Document, + EmptySearch, + Q, + Search, + interfaces, + query, + wrappers, +) from elasticsearch_dsl.exceptions import IllegalOperation @@ -530,6 +538,74 @@ def test_reverse() -> None: assert d == s.to_dict() +def test_code_generated_classes() -> None: + s = Search() + s = ( + s.query(query.Match("title", interfaces.MatchQuery(query="python"))) + .query(~query.Match("title", interfaces.MatchQuery(query="ruby"))) + .query( + query.Knn( + field="title", + query_vector=[1.0, 2.0, 3.0], + num_candidates=10, + k=3, + filter=query.Range("year", wrappers.Range(gt="2004")), + ) + ) + .filter( + query.Term("category", interfaces.TermQuery(value="meetup")) + | query.Term("category", interfaces.TermQuery(value="conference")) + ) + .collapse("user_id") + .post_filter(query.Terms(tags=["prague", "czech"])) + .script_fields(more_attendees="doc['attendees'].value + 42") + ) + assert { + "query": { + "bool": { + "filter": [ + { + "bool": { + "should": [ + {"term": {"category": {"value": "meetup"}}}, + {"term": {"category": {"value": "conference"}}}, + ] + } + } + ], + "must": [ + {"match": {"title": {"query": "python"}}}, + { + "knn": { + "field": "title", + "filter": [ + { + "range": { + "year": { + "gt": "2004", + }, + }, + }, + ], + "k": 3, + "num_candidates": 10, + "query_vector": [ + 1.0, + 2.0, + 3.0, + ], + }, + }, + ], + "must_not": [{"match": {"title": {"query": "ruby"}}}], + } + }, + "post_filter": {"terms": {"tags": ["prague", "czech"]}}, + "collapse": {"field": "user_id"}, + "script_fields": {"more_attendees": {"script": "doc['attendees'].value + 42"}}, + } == s.to_dict() + + def test_from_dict_doesnt_need_query() -> None: s = Search.from_dict({"size": 5}) From 2118bd8f8177a640707298bf87aa791ca62f1517 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 5 Sep 2024 14:46:25 +0100 Subject: [PATCH 10/27] no need to "reset" the interface list --- elasticsearch_dsl/interfaces.py | 88 ++++++++++++++++----------------- utils/generator.py | 27 ++++------ 2 files changed, 54 insertions(+), 61 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index 3bf11bf8..6e86ce0a 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -1191,35 +1191,6 @@ def __init__( super().__init__(**kwargs) -class FieldAndFormat(AttrDict[Any]): - """ - :arg field: (required) Wildcard pattern. The request returns values - for field names matching this pattern. - :arg format: Format in which the values are returned. - :arg include_unmapped: No documentation available. - """ - - field: Union[str, "InstrumentedField", "NotSet"] - format: Union[str, "NotSet"] - include_unmapped: Union[bool, "NotSet"] - - def __init__( - self, - *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - format: Union[str, "NotSet"] = NOT_SET, - include_unmapped: Union[bool, "NotSet"] = NOT_SET, - **kwargs: Any, - ): - if not isinstance(field, NotSet): - kwargs["field"] = str(field) - if not isinstance(format, NotSet): - kwargs["format"] = format - if not isinstance(include_unmapped, NotSet): - kwargs["include_unmapped"] = include_unmapped - super().__init__(kwargs) - - class FieldCollapse(AttrDict[Any]): """ :arg field: (required) The field to collapse the result set on @@ -1256,6 +1227,35 @@ def __init__( super().__init__(kwargs) +class FieldAndFormat(AttrDict[Any]): + """ + :arg field: (required) Wildcard pattern. The request returns values + for field names matching this pattern. + :arg format: Format in which the values are returned. + :arg include_unmapped: No documentation available. + """ + + field: Union[str, "InstrumentedField", "NotSet"] + format: Union[str, "NotSet"] + include_unmapped: Union[bool, "NotSet"] + + def __init__( + self, + *, + field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + format: Union[str, "NotSet"] = NOT_SET, + include_unmapped: Union[bool, "NotSet"] = NOT_SET, + **kwargs: Any, + ): + if not isinstance(field, NotSet): + kwargs["field"] = str(field) + if not isinstance(format, NotSet): + kwargs["format"] = format + if not isinstance(include_unmapped, NotSet): + kwargs["include_unmapped"] = include_unmapped + super().__init__(kwargs) + + class HighlightBase(AttrDict[Any]): """ :arg type: No documentation available. @@ -2019,6 +2019,21 @@ def __init__( super().__init__(**kwargs) +class ScoreSort(AttrDict[Any]): + """ + :arg order: No documentation available. + """ + + order: Union[Literal["asc", "desc"], "NotSet"] + + def __init__( + self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + ): + if not isinstance(order, NotSet): + kwargs["order"] = order + super().__init__(kwargs) + + class GeoDistanceSort(AttrDict[Any]): """ :arg mode: No documentation available. @@ -2064,21 +2079,6 @@ def __init__( super().__init__(kwargs) -class ScoreSort(AttrDict[Any]): - """ - :arg order: No documentation available. - """ - - order: Union[Literal["asc", "desc"], "NotSet"] - - def __init__( - self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any - ): - if not isinstance(order, NotSet): - kwargs["order"] = order - super().__init__(kwargs) - - class ScriptSort(AttrDict[Any]): """ :arg order: No documentation available. diff --git a/utils/generator.py b/utils/generator.py index 458acbc2..4d613c23 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -91,7 +91,7 @@ def __init__(self): # Interfaces collects interfaces that are seen while traversing the schema. # Any interfaces collected here are then rendered as Python in the # interfaces.py module. - self.interfaces = set() + self.interfaces = [] def find_type(self, name, namespace=None): for t in self.schema["types"]: @@ -100,9 +100,6 @@ def find_type(self, name, namespace=None): ): return t - def reset_interfaces(self): - self.interfaces = set() - def get_python_type(self, schema_type): """Obtain Python typing details for a given schema type @@ -183,7 +180,8 @@ def get_python_type(self, schema_type): == {"name": "string", "namespace": "_builtins"} ): # for now we treat PipeSeparatedFlags as a special case - self.interfaces.add("PipeSeparatedFlags") + if "PipeSeparatedFlags" not in self.interfaces: + self.interfaces.append("PipeSeparatedFlags") return '"i.PipeSeparatedFlags"', None else: # generic union type @@ -228,7 +226,8 @@ def get_python_type(self, schema_type): # to handle other interfaces we generate a type of the same name # and add the interface to the interfaces.py module - self.interfaces.add(schema_type["name"]["name"]) + if schema_type["name"]["name"] not in self.interfaces: + self.interfaces.append(schema_type["name"]["name"]) return f"\"i.{schema_type['name']['name']}\"", None elif schema_type["kind"] == "user_defined_value": # user_defined_value maps to Python's Any type @@ -436,17 +435,14 @@ def generate_query_py(schema, filename): print(f"Generated {filename}.") -def generate_interfaces_py(schema, interfaces, filename): +def generate_interfaces_py(schema, filename): """Generate interfaces.py""" classes = {} - for interface in interfaces: + schema.interfaces = sorted(schema.interfaces) + for interface in schema.interfaces: if interface == "PipeSeparatedFlags": continue # handled as a special case - schema.reset_interfaces() - k = schema.interface_to_python_class(interface, interfaces) - for new_interface in sorted(schema.interfaces): - if new_interface not in interfaces: - interfaces.append(new_interface) + k = schema.interface_to_python_class(interface, schema.interfaces) classes[k["name"]] = k classes_list = [] @@ -477,7 +473,4 @@ def generate_interfaces_py(schema, interfaces, filename): if __name__ == "__main__": schema = ElasticsearchSchema() generate_query_py(schema, "elasticsearch_dsl/query.py") - interfaces = schema.interfaces - generate_interfaces_py( - schema, sorted(interfaces), "elasticsearch_dsl/interfaces.py" - ) + generate_interfaces_py(schema, "elasticsearch_dsl/interfaces.py") From 8a227a857188653b5cd68586c289c25914a60a5a Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 5 Sep 2024 15:32:19 +0100 Subject: [PATCH 11/27] use the transport's DEFAULT type --- elasticsearch_dsl/function.py | 32 +- elasticsearch_dsl/interfaces.py | 1575 +++++++++++++++-------------- elasticsearch_dsl/query.py | 530 +++++----- elasticsearch_dsl/utils.py | 10 +- utils/generator.py | 6 +- utils/templates/interfaces.py.tpl | 9 +- utils/templates/query.py.tpl | 13 +- 7 files changed, 1112 insertions(+), 1063 deletions(-) diff --git a/elasticsearch_dsl/function.py b/elasticsearch_dsl/function.py index 45f7c8ec..47d07da8 100644 --- a/elasticsearch_dsl/function.py +++ b/elasticsearch_dsl/function.py @@ -28,7 +28,9 @@ overload, ) -from .utils import NOT_SET, AttrDict, DslBase, NotSet +from elastic_transport.client_utils import DEFAULT, DefaultType + +from .utils import AttrDict, DslBase @overload @@ -152,23 +154,23 @@ class DecayFunction(AttrDict[Any]): def __init__( self, *, - decay: Union[float, "NotSet"] = NOT_SET, - offset: Any = NOT_SET, - scale: Any = NOT_SET, - origin: Any = NOT_SET, + decay: Union[float, "DefaultType"] = DEFAULT, + offset: Any = DEFAULT, + scale: Any = DEFAULT, + origin: Any = DEFAULT, multi_value_mode: Union[ - Literal["min", "max", "avg", "sum"], "NotSet" - ] = NOT_SET, + Literal["min", "max", "avg", "sum"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(decay, NotSet): + if decay != DEFAULT: kwargs["decay"] = decay - if not isinstance(offset, NotSet): + if offset != DEFAULT: kwargs["offset"] = offset - if not isinstance(scale, NotSet): - kwargs["offset"] = scale - if not isinstance(origin, NotSet): - kwargs["offset"] = origin - if not isinstance(multi_value_mode, NotSet): - kwargs["offset"] = multi_value_mode + if scale != DEFAULT: + kwargs["scale"] = scale + if origin != DEFAULT: + kwargs["origin"] = origin + if multi_value_mode != DEFAULT: + kwargs["multi_value_mode"] = multi_value_mode super().__init__(kwargs) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index 6e86ce0a..b9a3d58f 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -17,11 +17,13 @@ from typing import Any, Dict, List, Literal, Mapping, Union +from elastic_transport.client_utils import DEFAULT, DefaultType + from elasticsearch_dsl import Query from elasticsearch_dsl import function as f from elasticsearch_dsl import interfaces as i from elasticsearch_dsl.document_base import InstrumentedField -from elasticsearch_dsl.utils import NOT_SET, AttrDict, NotSet +from elasticsearch_dsl.utils import AttrDict PipeSeparatedFlags = str @@ -36,19 +38,19 @@ class QueryBase(AttrDict[Any]): :arg _name: No documentation available. """ - boost: Union[float, "NotSet"] - _name: Union[str, "NotSet"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, - boost: Union[float, "NotSet"] = NOT_SET, - _name: Union[str, "NotSet"] = NOT_SET, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(boost, NotSet): + if boost != DEFAULT: kwargs["boost"] = boost - if not isinstance(_name, NotSet): + if _name != DEFAULT: kwargs["_name"] = _name super().__init__(kwargs) @@ -63,35 +65,35 @@ class CommonTermsQuery(QueryBase): :arg query: (required) No documentation available. """ - analyzer: Union[str, "NotSet"] - cutoff_frequency: Union[float, "NotSet"] - high_freq_operator: Union[Literal["and", "or"], "NotSet"] - low_freq_operator: Union[Literal["and", "or"], "NotSet"] - minimum_should_match: Union[int, str, "NotSet"] - query: Union[str, "NotSet"] + analyzer: Union[str, "DefaultType"] + cutoff_frequency: Union[float, "DefaultType"] + high_freq_operator: Union[Literal["and", "or"], "DefaultType"] + low_freq_operator: Union[Literal["and", "or"], "DefaultType"] + minimum_should_match: Union[int, str, "DefaultType"] + query: Union[str, "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - high_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - low_freq_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, + high_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + low_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(cutoff_frequency, NotSet): + if cutoff_frequency != DEFAULT: kwargs["cutoff_frequency"] = cutoff_frequency - if not isinstance(high_freq_operator, NotSet): + if high_freq_operator != DEFAULT: kwargs["high_freq_operator"] = high_freq_operator - if not isinstance(low_freq_operator, NotSet): + if low_freq_operator != DEFAULT: kwargs["low_freq_operator"] = low_freq_operator - if not isinstance(minimum_should_match, NotSet): + if minimum_should_match != DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query super().__init__(**kwargs) @@ -121,43 +123,43 @@ class FunctionScoreContainer(AttrDict[Any]): :arg weight: No documentation available. """ - exp: Union["f.DecayFunction", "NotSet"] - gauss: Union["f.DecayFunction", "NotSet"] - linear: Union["f.DecayFunction", "NotSet"] - field_value_factor: Union["f.FieldValueFactor", "NotSet"] - random_score: Union["f.RandomScore", "NotSet"] - script_score: Union["f.ScriptScore", "NotSet"] - filter: Union[Query, "NotSet"] - weight: Union[float, "NotSet"] + exp: Union["f.DecayFunction", "DefaultType"] + gauss: Union["f.DecayFunction", "DefaultType"] + linear: Union["f.DecayFunction", "DefaultType"] + field_value_factor: Union["f.FieldValueFactor", "DefaultType"] + random_score: Union["f.RandomScore", "DefaultType"] + script_score: Union["f.ScriptScore", "DefaultType"] + filter: Union[Query, "DefaultType"] + weight: Union[float, "DefaultType"] def __init__( self, *, - exp: Union["f.DecayFunction", "NotSet"] = NOT_SET, - gauss: Union["f.DecayFunction", "NotSet"] = NOT_SET, - linear: Union["f.DecayFunction", "NotSet"] = NOT_SET, - field_value_factor: Union["f.FieldValueFactor", "NotSet"] = NOT_SET, - random_score: Union["f.RandomScore", "NotSet"] = NOT_SET, - script_score: Union["f.ScriptScore", "NotSet"] = NOT_SET, - filter: Union[Query, "NotSet"] = NOT_SET, - weight: Union[float, "NotSet"] = NOT_SET, + exp: Union["f.DecayFunction", "DefaultType"] = DEFAULT, + gauss: Union["f.DecayFunction", "DefaultType"] = DEFAULT, + linear: Union["f.DecayFunction", "DefaultType"] = DEFAULT, + field_value_factor: Union["f.FieldValueFactor", "DefaultType"] = DEFAULT, + random_score: Union["f.RandomScore", "DefaultType"] = DEFAULT, + script_score: Union["f.ScriptScore", "DefaultType"] = DEFAULT, + filter: Union[Query, "DefaultType"] = DEFAULT, + weight: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(exp, NotSet): + if exp != DEFAULT: kwargs["exp"] = exp - if not isinstance(gauss, NotSet): + if gauss != DEFAULT: kwargs["gauss"] = gauss - if not isinstance(linear, NotSet): + if linear != DEFAULT: kwargs["linear"] = linear - if not isinstance(field_value_factor, NotSet): + if field_value_factor != DEFAULT: kwargs["field_value_factor"] = field_value_factor - if not isinstance(random_score, NotSet): + if random_score != DEFAULT: kwargs["random_score"] = random_score - if not isinstance(script_score, NotSet): + if script_score != DEFAULT: kwargs["script_score"] = script_score - if not isinstance(filter, NotSet): + if filter != DEFAULT: kwargs["filter"] = filter - if not isinstance(weight, NotSet): + if weight != DEFAULT: kwargs["weight"] = weight super().__init__(kwargs) @@ -175,35 +177,35 @@ class FuzzyQuery(QueryBase): :arg value: (required) Term you wish to find in the provided field. """ - max_expansions: Union[int, "NotSet"] - prefix_length: Union[int, "NotSet"] - rewrite: Union[str, "NotSet"] - transpositions: Union[bool, "NotSet"] - fuzziness: Union[str, int, "NotSet"] - value: Union[str, float, bool, "NotSet"] + max_expansions: Union[int, "DefaultType"] + prefix_length: Union[int, "DefaultType"] + rewrite: Union[str, "DefaultType"] + transpositions: Union[bool, "DefaultType"] + fuzziness: Union[str, int, "DefaultType"] + value: Union[str, float, bool, "DefaultType"] def __init__( self, *, - max_expansions: Union[int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - value: Union[str, float, bool, "NotSet"] = NOT_SET, + max_expansions: Union[int, "DefaultType"] = DEFAULT, + prefix_length: Union[int, "DefaultType"] = DEFAULT, + rewrite: Union[str, "DefaultType"] = DEFAULT, + transpositions: Union[bool, "DefaultType"] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + value: Union[str, float, bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(max_expansions, NotSet): + if max_expansions != DEFAULT: kwargs["max_expansions"] = max_expansions - if not isinstance(prefix_length, NotSet): + if prefix_length != DEFAULT: kwargs["prefix_length"] = prefix_length - if not isinstance(rewrite, NotSet): + if rewrite != DEFAULT: kwargs["rewrite"] = rewrite - if not isinstance(transpositions, NotSet): + if transpositions != DEFAULT: kwargs["transpositions"] = transpositions - if not isinstance(fuzziness, NotSet): + if fuzziness != DEFAULT: kwargs["fuzziness"] = fuzziness - if not isinstance(value, NotSet): + if value != DEFAULT: kwargs["value"] = value super().__init__(**kwargs) @@ -231,107 +233,111 @@ class InnerHits(AttrDict[Any]): :arg version: No documentation available. """ - name: Union[str, "NotSet"] - size: Union[int, "NotSet"] - from_: Union[int, "NotSet"] - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] - docvalue_fields: Union[List["i.FieldAndFormat"], Dict[str, Any], "NotSet"] - explain: Union[bool, "NotSet"] - highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] - ignore_unmapped: Union[bool, "NotSet"] + name: Union[str, "DefaultType"] + size: Union[int, "DefaultType"] + from_: Union[int, "DefaultType"] + collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] + docvalue_fields: Union[List["i.FieldAndFormat"], Dict[str, Any], "DefaultType"] + explain: Union[bool, "DefaultType"] + highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] + ignore_unmapped: Union[bool, "DefaultType"] script_fields: Union[ Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], Dict[str, Any], - "NotSet", + "DefaultType", ] - seq_no_primary_term: Union[bool, "NotSet"] + seq_no_primary_term: Union[bool, "DefaultType"] fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "DefaultType", ] sort: Union[ Union[Union[str, "InstrumentedField"], "i.SortOptions"], List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], Dict[str, Any], - "NotSet", + "DefaultType", ] - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] stored_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "DefaultType", ] - track_scores: Union[bool, "NotSet"] - version: Union[bool, "NotSet"] + track_scores: Union[bool, "DefaultType"] + version: Union[bool, "DefaultType"] def __init__( self, *, - name: Union[str, "NotSet"] = NOT_SET, - size: Union[int, "NotSet"] = NOT_SET, - from_: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + name: Union[str, "DefaultType"] = DEFAULT, + size: Union[int, "DefaultType"] = DEFAULT, + from_: Union[int, "DefaultType"] = DEFAULT, + collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, docvalue_fields: Union[ - List["i.FieldAndFormat"], Dict[str, Any], "NotSet" - ] = NOT_SET, - explain: Union[bool, "NotSet"] = NOT_SET, - highlight: Union["i.Highlight", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + List["i.FieldAndFormat"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + explain: Union[bool, "DefaultType"] = DEFAULT, + highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, script_fields: Union[ Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], Dict[str, Any], - "NotSet", - ] = NOT_SET, - seq_no_primary_term: Union[bool, "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + seq_no_primary_term: Union[bool, "DefaultType"] = DEFAULT, fields: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, + "DefaultType", + ] = DEFAULT, sort: Union[ Union[Union[str, "InstrumentedField"], "i.SortOptions"], List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], Dict[str, Any], - "NotSet", - ] = NOT_SET, - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] = DEFAULT, stored_fields: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - track_scores: Union[bool, "NotSet"] = NOT_SET, - version: Union[bool, "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + track_scores: Union[bool, "DefaultType"] = DEFAULT, + version: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(name, NotSet): + if name != DEFAULT: kwargs["name"] = name - if not isinstance(size, NotSet): + if size != DEFAULT: kwargs["size"] = size - if not isinstance(from_, NotSet): + if from_ != DEFAULT: kwargs["from_"] = from_ - if not isinstance(collapse, NotSet): + if collapse != DEFAULT: kwargs["collapse"] = collapse - if not isinstance(docvalue_fields, NotSet): + if docvalue_fields != DEFAULT: kwargs["docvalue_fields"] = docvalue_fields - if not isinstance(explain, NotSet): + if explain != DEFAULT: kwargs["explain"] = explain - if not isinstance(highlight, NotSet): + if highlight != DEFAULT: kwargs["highlight"] = highlight - if not isinstance(ignore_unmapped, NotSet): + if ignore_unmapped != DEFAULT: kwargs["ignore_unmapped"] = ignore_unmapped - if not isinstance(script_fields, NotSet): + if script_fields != DEFAULT: kwargs["script_fields"] = str(script_fields) - if not isinstance(seq_no_primary_term, NotSet): + if seq_no_primary_term != DEFAULT: kwargs["seq_no_primary_term"] = seq_no_primary_term - if not isinstance(fields, NotSet): + if fields != DEFAULT: kwargs["fields"] = str(fields) - if not isinstance(sort, NotSet): + if sort != DEFAULT: kwargs["sort"] = str(sort) - if not isinstance(_source, NotSet): + if _source != DEFAULT: kwargs["_source"] = _source - if not isinstance(stored_fields, NotSet): + if stored_fields != DEFAULT: kwargs["stored_fields"] = str(stored_fields) - if not isinstance(track_scores, NotSet): + if track_scores != DEFAULT: kwargs["track_scores"] = track_scores - if not isinstance(version, NotSet): + if version != DEFAULT: kwargs["version"] = version super().__init__(kwargs) @@ -348,35 +354,35 @@ class IntervalsQuery(QueryBase): :arg wildcard: Matches terms using a wildcard pattern. """ - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] - match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] + match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] def __init__( self, *, - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, - match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(all_of, NotSet): + if all_of != DEFAULT: kwargs["all_of"] = all_of - if not isinstance(any_of, NotSet): + if any_of != DEFAULT: kwargs["any_of"] = any_of - if not isinstance(fuzzy, NotSet): + if fuzzy != DEFAULT: kwargs["fuzzy"] = fuzzy - if not isinstance(match, NotSet): + if match != DEFAULT: kwargs["match"] = match - if not isinstance(prefix, NotSet): + if prefix != DEFAULT: kwargs["prefix"] = prefix - if not isinstance(wildcard, NotSet): + if wildcard != DEFAULT: kwargs["wildcard"] = wildcard super().__init__(**kwargs) @@ -394,48 +400,50 @@ class LikeDocument(AttrDict[Any]): """ doc: Any - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] - _id: Union[str, "NotSet"] - _index: Union[str, "NotSet"] - per_field_analyzer: Union[Mapping[Union[str, "InstrumentedField"], str], "NotSet"] - routing: Union[str, "NotSet"] - version: Union[int, "NotSet"] + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] + _id: Union[str, "DefaultType"] + _index: Union[str, "DefaultType"] + per_field_analyzer: Union[ + Mapping[Union[str, "InstrumentedField"], str], "DefaultType" + ] + routing: Union[str, "DefaultType"] + version: Union[int, "DefaultType"] version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "NotSet" + Literal["internal", "external", "external_gte", "force"], "DefaultType" ] def __init__( self, *, - doc: Any = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - _id: Union[str, "NotSet"] = NOT_SET, - _index: Union[str, "NotSet"] = NOT_SET, + doc: Any = DEFAULT, + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + _id: Union[str, "DefaultType"] = DEFAULT, + _index: Union[str, "DefaultType"] = DEFAULT, per_field_analyzer: Union[ - Mapping[Union[str, "InstrumentedField"], str], "NotSet" - ] = NOT_SET, - routing: Union[str, "NotSet"] = NOT_SET, - version: Union[int, "NotSet"] = NOT_SET, + Mapping[Union[str, "InstrumentedField"], str], "DefaultType" + ] = DEFAULT, + routing: Union[str, "DefaultType"] = DEFAULT, + version: Union[int, "DefaultType"] = DEFAULT, version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "NotSet" - ] = NOT_SET, + Literal["internal", "external", "external_gte", "force"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(doc, NotSet): + if doc != DEFAULT: kwargs["doc"] = doc - if not isinstance(fields, NotSet): + if fields != DEFAULT: kwargs["fields"] = str(fields) - if not isinstance(_id, NotSet): + if _id != DEFAULT: kwargs["_id"] = _id - if not isinstance(_index, NotSet): + if _index != DEFAULT: kwargs["_index"] = _index - if not isinstance(per_field_analyzer, NotSet): + if per_field_analyzer != DEFAULT: kwargs["per_field_analyzer"] = str(per_field_analyzer) - if not isinstance(routing, NotSet): + if routing != DEFAULT: kwargs["routing"] = routing - if not isinstance(version, NotSet): + if version != DEFAULT: kwargs["version"] = version - if not isinstance(version_type, NotSet): + if version_type != DEFAULT: kwargs["version_type"] = version_type super().__init__(kwargs) @@ -469,47 +477,47 @@ class MatchBoolPrefixQuery(QueryBase): The last term is used in a prefix query. """ - analyzer: Union[str, "NotSet"] - fuzziness: Union[str, int, "NotSet"] - fuzzy_rewrite: Union[str, "NotSet"] - fuzzy_transpositions: Union[bool, "NotSet"] - max_expansions: Union[int, "NotSet"] - minimum_should_match: Union[int, str, "NotSet"] - operator: Union[Literal["and", "or"], "NotSet"] - prefix_length: Union[int, "NotSet"] - query: Union[str, "NotSet"] + analyzer: Union[str, "DefaultType"] + fuzziness: Union[str, int, "DefaultType"] + fuzzy_rewrite: Union[str, "DefaultType"] + fuzzy_transpositions: Union[bool, "DefaultType"] + max_expansions: Union[int, "DefaultType"] + minimum_should_match: Union[int, str, "DefaultType"] + operator: Union[Literal["and", "or"], "DefaultType"] + prefix_length: Union[int, "DefaultType"] + query: Union[str, "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - max_expansions: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, + fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, + max_expansions: Union[int, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + prefix_length: Union[int, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(fuzziness, NotSet): + if fuzziness != DEFAULT: kwargs["fuzziness"] = fuzziness - if not isinstance(fuzzy_rewrite, NotSet): + if fuzzy_rewrite != DEFAULT: kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if not isinstance(fuzzy_transpositions, NotSet): + if fuzzy_transpositions != DEFAULT: kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if not isinstance(max_expansions, NotSet): + if max_expansions != DEFAULT: kwargs["max_expansions"] = max_expansions - if not isinstance(minimum_should_match, NotSet): + if minimum_should_match != DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if not isinstance(operator, NotSet): + if operator != DEFAULT: kwargs["operator"] = operator - if not isinstance(prefix_length, NotSet): + if prefix_length != DEFAULT: kwargs["prefix_length"] = prefix_length - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query super().__init__(**kwargs) @@ -528,31 +536,31 @@ class MatchPhrasePrefixQuery(QueryBase): filter. """ - analyzer: Union[str, "NotSet"] - max_expansions: Union[int, "NotSet"] - query: Union[str, "NotSet"] - slop: Union[int, "NotSet"] - zero_terms_query: Union[Literal["all", "none"], "NotSet"] + analyzer: Union[str, "DefaultType"] + max_expansions: Union[int, "DefaultType"] + query: Union[str, "DefaultType"] + slop: Union[int, "DefaultType"] + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - max_expansions: Union[int, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + max_expansions: Union[int, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, + slop: Union[int, "DefaultType"] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(max_expansions, NotSet): + if max_expansions != DEFAULT: kwargs["max_expansions"] = max_expansions - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query - if not isinstance(slop, NotSet): + if slop != DEFAULT: kwargs["slop"] = slop - if not isinstance(zero_terms_query, NotSet): + if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) @@ -570,27 +578,27 @@ class MatchPhraseQuery(QueryBase): filter. """ - analyzer: Union[str, "NotSet"] - query: Union[str, "NotSet"] - slop: Union[int, "NotSet"] - zero_terms_query: Union[Literal["all", "none"], "NotSet"] + analyzer: Union[str, "DefaultType"] + query: Union[str, "DefaultType"] + slop: Union[int, "DefaultType"] + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, + slop: Union[int, "DefaultType"] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query - if not isinstance(slop, NotSet): + if slop != DEFAULT: kwargs["slop"] = slop - if not isinstance(zero_terms_query, NotSet): + if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) @@ -624,65 +632,65 @@ class MatchQuery(QueryBase): filter. """ - analyzer: Union[str, "NotSet"] - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] - cutoff_frequency: Union[float, "NotSet"] - fuzziness: Union[str, int, "NotSet"] - fuzzy_rewrite: Union[str, "NotSet"] - fuzzy_transpositions: Union[bool, "NotSet"] - lenient: Union[bool, "NotSet"] - max_expansions: Union[int, "NotSet"] - minimum_should_match: Union[int, str, "NotSet"] - operator: Union[Literal["and", "or"], "NotSet"] - prefix_length: Union[int, "NotSet"] - query: Union[str, float, bool, "NotSet"] - zero_terms_query: Union[Literal["all", "none"], "NotSet"] + analyzer: Union[str, "DefaultType"] + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] + cutoff_frequency: Union[float, "DefaultType"] + fuzziness: Union[str, int, "DefaultType"] + fuzzy_rewrite: Union[str, "DefaultType"] + fuzzy_transpositions: Union[bool, "DefaultType"] + lenient: Union[bool, "DefaultType"] + max_expansions: Union[int, "DefaultType"] + minimum_should_match: Union[int, str, "DefaultType"] + operator: Union[Literal["and", "or"], "DefaultType"] + prefix_length: Union[int, "DefaultType"] + query: Union[str, float, bool, "DefaultType"] + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, - max_expansions: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - query: Union[str, float, bool, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, + cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, + fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, + lenient: Union[bool, "DefaultType"] = DEFAULT, + max_expansions: Union[int, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + prefix_length: Union[int, "DefaultType"] = DEFAULT, + query: Union[str, float, bool, "DefaultType"] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(auto_generate_synonyms_phrase_query, NotSet): + if auto_generate_synonyms_phrase_query != DEFAULT: kwargs["auto_generate_synonyms_phrase_query"] = ( auto_generate_synonyms_phrase_query ) - if not isinstance(cutoff_frequency, NotSet): + if cutoff_frequency != DEFAULT: kwargs["cutoff_frequency"] = cutoff_frequency - if not isinstance(fuzziness, NotSet): + if fuzziness != DEFAULT: kwargs["fuzziness"] = fuzziness - if not isinstance(fuzzy_rewrite, NotSet): + if fuzzy_rewrite != DEFAULT: kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if not isinstance(fuzzy_transpositions, NotSet): + if fuzzy_transpositions != DEFAULT: kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if not isinstance(lenient, NotSet): + if lenient != DEFAULT: kwargs["lenient"] = lenient - if not isinstance(max_expansions, NotSet): + if max_expansions != DEFAULT: kwargs["max_expansions"] = max_expansions - if not isinstance(minimum_should_match, NotSet): + if minimum_should_match != DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if not isinstance(operator, NotSet): + if operator != DEFAULT: kwargs["operator"] = operator - if not isinstance(prefix_length, NotSet): + if prefix_length != DEFAULT: kwargs["prefix_length"] = prefix_length - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query - if not isinstance(zero_terms_query, NotSet): + if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query super().__init__(**kwargs) @@ -693,19 +701,19 @@ class PinnedDoc(AttrDict[Any]): :arg _index: (required) The index that contains the document. """ - _id: Union[str, "NotSet"] - _index: Union[str, "NotSet"] + _id: Union[str, "DefaultType"] + _index: Union[str, "DefaultType"] def __init__( self, *, - _id: Union[str, "NotSet"] = NOT_SET, - _index: Union[str, "NotSet"] = NOT_SET, + _id: Union[str, "DefaultType"] = DEFAULT, + _index: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_id, NotSet): + if _id != DEFAULT: kwargs["_id"] = _id - if not isinstance(_index, NotSet): + if _index != DEFAULT: kwargs["_index"] = _index super().__init__(kwargs) @@ -721,23 +729,23 @@ class PrefixQuery(QueryBase): the underlying field’s mapping. """ - rewrite: Union[str, "NotSet"] - value: Union[str, "NotSet"] - case_insensitive: Union[bool, "NotSet"] + rewrite: Union[str, "DefaultType"] + value: Union[str, "DefaultType"] + case_insensitive: Union[bool, "DefaultType"] def __init__( self, *, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, + rewrite: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, "DefaultType"] = DEFAULT, + case_insensitive: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(rewrite, NotSet): + if rewrite != DEFAULT: kwargs["rewrite"] = rewrite - if not isinstance(value, NotSet): + if value != DEFAULT: kwargs["value"] = value - if not isinstance(case_insensitive, NotSet): + if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive super().__init__(**kwargs) @@ -747,15 +755,17 @@ class QueryVectorBuilder(AttrDict[Any]): :arg text_embedding: No documentation available. """ - text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] + text_embedding: Union["i.TextEmbedding", Dict[str, Any], "DefaultType"] def __init__( self, *, - text_embedding: Union["i.TextEmbedding", Dict[str, Any], "NotSet"] = NOT_SET, + text_embedding: Union[ + "i.TextEmbedding", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(text_embedding, NotSet): + if text_embedding != DEFAULT: kwargs["text_embedding"] = text_embedding super().__init__(kwargs) @@ -773,12 +783,12 @@ class RankFeatureFunctionLogarithm(RankFeatureFunction): :arg scaling_factor: (required) Configurable scaling factor. """ - scaling_factor: Union[float, "NotSet"] + scaling_factor: Union[float, "DefaultType"] def __init__( - self, *, scaling_factor: Union[float, "NotSet"] = NOT_SET, **kwargs: Any + self, *, scaling_factor: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any ): - if not isinstance(scaling_factor, NotSet): + if scaling_factor != DEFAULT: kwargs["scaling_factor"] = scaling_factor super().__init__(**kwargs) @@ -789,10 +799,10 @@ class RankFeatureFunctionSaturation(RankFeatureFunction): than 0.5. """ - pivot: Union[float, "NotSet"] + pivot: Union[float, "DefaultType"] - def __init__(self, *, pivot: Union[float, "NotSet"] = NOT_SET, **kwargs: Any): - if not isinstance(pivot, NotSet): + def __init__(self, *, pivot: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any): + if pivot != DEFAULT: kwargs["pivot"] = pivot super().__init__(**kwargs) @@ -804,19 +814,19 @@ class RankFeatureFunctionSigmoid(RankFeatureFunction): :arg exponent: (required) Configurable Exponent. """ - pivot: Union[float, "NotSet"] - exponent: Union[float, "NotSet"] + pivot: Union[float, "DefaultType"] + exponent: Union[float, "DefaultType"] def __init__( self, *, - pivot: Union[float, "NotSet"] = NOT_SET, - exponent: Union[float, "NotSet"] = NOT_SET, + pivot: Union[float, "DefaultType"] = DEFAULT, + exponent: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(pivot, NotSet): + if pivot != DEFAULT: kwargs["pivot"] = pivot - if not isinstance(exponent, NotSet): + if exponent != DEFAULT: kwargs["exponent"] = exponent super().__init__(**kwargs) @@ -835,31 +845,31 @@ class RegexpQuery(QueryBase): in the provided field. """ - case_insensitive: Union[bool, "NotSet"] - flags: Union[str, "NotSet"] - max_determinized_states: Union[int, "NotSet"] - rewrite: Union[str, "NotSet"] - value: Union[str, "NotSet"] + case_insensitive: Union[bool, "DefaultType"] + flags: Union[str, "DefaultType"] + max_determinized_states: Union[int, "DefaultType"] + rewrite: Union[str, "DefaultType"] + value: Union[str, "DefaultType"] def __init__( self, *, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, - flags: Union[str, "NotSet"] = NOT_SET, - max_determinized_states: Union[int, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "DefaultType"] = DEFAULT, + flags: Union[str, "DefaultType"] = DEFAULT, + max_determinized_states: Union[int, "DefaultType"] = DEFAULT, + rewrite: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(case_insensitive, NotSet): + if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive - if not isinstance(flags, NotSet): + if flags != DEFAULT: kwargs["flags"] = flags - if not isinstance(max_determinized_states, NotSet): + if max_determinized_states != DEFAULT: kwargs["max_determinized_states"] = max_determinized_states - if not isinstance(rewrite, NotSet): + if rewrite != DEFAULT: kwargs["rewrite"] = rewrite - if not isinstance(value, NotSet): + if value != DEFAULT: kwargs["value"] = value super().__init__(**kwargs) @@ -875,33 +885,33 @@ class Script(AttrDict[Any]): :arg options: No documentation available. """ - source: Union[str, "NotSet"] - id: Union[str, "NotSet"] - params: Union[Mapping[str, Any], "NotSet"] - lang: Union[Literal["painless", "expression", "mustache", "java"], "NotSet"] - options: Union[Mapping[str, str], "NotSet"] + source: Union[str, "DefaultType"] + id: Union[str, "DefaultType"] + params: Union[Mapping[str, Any], "DefaultType"] + lang: Union[Literal["painless", "expression", "mustache", "java"], "DefaultType"] + options: Union[Mapping[str, str], "DefaultType"] def __init__( self, *, - source: Union[str, "NotSet"] = NOT_SET, - id: Union[str, "NotSet"] = NOT_SET, - params: Union[Mapping[str, Any], "NotSet"] = NOT_SET, + source: Union[str, "DefaultType"] = DEFAULT, + id: Union[str, "DefaultType"] = DEFAULT, + params: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, lang: Union[ - Literal["painless", "expression", "mustache", "java"], "NotSet" - ] = NOT_SET, - options: Union[Mapping[str, str], "NotSet"] = NOT_SET, + Literal["painless", "expression", "mustache", "java"], "DefaultType" + ] = DEFAULT, + options: Union[Mapping[str, str], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(source, NotSet): + if source != DEFAULT: kwargs["source"] = source - if not isinstance(id, NotSet): + if id != DEFAULT: kwargs["id"] = id - if not isinstance(params, NotSet): + if params != DEFAULT: kwargs["params"] = params - if not isinstance(lang, NotSet): + if lang != DEFAULT: kwargs["lang"] = lang - if not isinstance(options, NotSet): + if options != DEFAULT: kwargs["options"] = options super().__init__(kwargs) @@ -931,65 +941,69 @@ class SpanQuery(AttrDict[Any]): other span queries. """ - span_containing: Union["i.SpanContainingQuery", Dict[str, Any], "NotSet"] - span_field_masking: Union["i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet"] - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] - span_gap: Union[Mapping[Union[str, "InstrumentedField"], int], "NotSet"] - span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] - span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] - span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] - span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] + span_containing: Union["i.SpanContainingQuery", Dict[str, Any], "DefaultType"] + span_field_masking: Union["i.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType"] + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "DefaultType"] + span_gap: Union[Mapping[Union[str, "InstrumentedField"], int], "DefaultType"] + span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "DefaultType"] + span_near: Union["i.SpanNearQuery", Dict[str, Any], "DefaultType"] + span_not: Union["i.SpanNotQuery", Dict[str, Any], "DefaultType"] + span_or: Union["i.SpanOrQuery", Dict[str, Any], "DefaultType"] span_term: Union[ Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], Dict[str, Any], - "NotSet", + "DefaultType", ] - span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] + span_within: Union["i.SpanWithinQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, span_containing: Union[ - "i.SpanContainingQuery", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.SpanContainingQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, span_field_masking: Union[ - "i.SpanFieldMaskingQuery", Dict[str, Any], "NotSet" - ] = NOT_SET, - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "NotSet"] = NOT_SET, + "i.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, + span_first: Union["i.SpanFirstQuery", Dict[str, Any], "DefaultType"] = DEFAULT, span_gap: Union[ - Mapping[Union[str, "InstrumentedField"], int], "NotSet" - ] = NOT_SET, - span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_near: Union["i.SpanNearQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_not: Union["i.SpanNotQuery", Dict[str, Any], "NotSet"] = NOT_SET, - span_or: Union["i.SpanOrQuery", Dict[str, Any], "NotSet"] = NOT_SET, + Mapping[Union[str, "InstrumentedField"], int], "DefaultType" + ] = DEFAULT, + span_multi: Union[ + "i.SpanMultiTermQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, + span_near: Union["i.SpanNearQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + span_not: Union["i.SpanNotQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + span_or: Union["i.SpanOrQuery", Dict[str, Any], "DefaultType"] = DEFAULT, span_term: Union[ Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], Dict[str, Any], - "NotSet", - ] = NOT_SET, - span_within: Union["i.SpanWithinQuery", Dict[str, Any], "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + span_within: Union[ + "i.SpanWithinQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(span_containing, NotSet): + if span_containing != DEFAULT: kwargs["span_containing"] = span_containing - if not isinstance(span_field_masking, NotSet): + if span_field_masking != DEFAULT: kwargs["span_field_masking"] = span_field_masking - if not isinstance(span_first, NotSet): + if span_first != DEFAULT: kwargs["span_first"] = span_first - if not isinstance(span_gap, NotSet): + if span_gap != DEFAULT: kwargs["span_gap"] = str(span_gap) - if not isinstance(span_multi, NotSet): + if span_multi != DEFAULT: kwargs["span_multi"] = span_multi - if not isinstance(span_near, NotSet): + if span_near != DEFAULT: kwargs["span_near"] = span_near - if not isinstance(span_not, NotSet): + if span_not != DEFAULT: kwargs["span_not"] = span_not - if not isinstance(span_or, NotSet): + if span_or != DEFAULT: kwargs["span_or"] = span_or - if not isinstance(span_term, NotSet): + if span_term != DEFAULT: kwargs["span_term"] = str(span_term) - if not isinstance(span_within, NotSet): + if span_within != DEFAULT: kwargs["span_within"] = span_within super().__init__(kwargs) @@ -999,10 +1013,10 @@ class SpanTermQuery(QueryBase): :arg value: (required) No documentation available. """ - value: Union[str, "NotSet"] + value: Union[str, "DefaultType"] - def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): - if not isinstance(value, NotSet): + def __init__(self, *, value: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + if value != DEFAULT: kwargs["value"] = value super().__init__(**kwargs) @@ -1016,19 +1030,19 @@ class TermQuery(QueryBase): underlying field’s mapping. """ - value: Union[int, float, str, bool, None, Any, "NotSet"] - case_insensitive: Union[bool, "NotSet"] + value: Union[int, float, str, bool, None, Any, "DefaultType"] + case_insensitive: Union[bool, "DefaultType"] def __init__( self, *, - value: Union[int, float, str, bool, None, Any, "NotSet"] = NOT_SET, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, + value: Union[int, float, str, bool, None, Any, "DefaultType"] = DEFAULT, + case_insensitive: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(value, NotSet): + if value != DEFAULT: kwargs["value"] = value - if not isinstance(case_insensitive, NotSet): + if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive super().__init__(**kwargs) @@ -1043,25 +1057,27 @@ class TermsSetQuery(QueryBase): field. """ - minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] - minimum_should_match_script: Union["i.Script", Dict[str, Any], "NotSet"] - terms: Union[List[str], "NotSet"] + minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] + minimum_should_match_script: Union["i.Script", Dict[str, Any], "DefaultType"] + terms: Union[List[str], "DefaultType"] def __init__( self, *, - minimum_should_match_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + minimum_should_match_field: Union[ + str, "InstrumentedField", "DefaultType" + ] = DEFAULT, minimum_should_match_script: Union[ - "i.Script", Dict[str, Any], "NotSet" - ] = NOT_SET, - terms: Union[List[str], "NotSet"] = NOT_SET, + "i.Script", Dict[str, Any], "DefaultType" + ] = DEFAULT, + terms: Union[List[str], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(minimum_should_match_field, NotSet): + if minimum_should_match_field != DEFAULT: kwargs["minimum_should_match_field"] = str(minimum_should_match_field) - if not isinstance(minimum_should_match_script, NotSet): + if minimum_should_match_script != DEFAULT: kwargs["minimum_should_match_script"] = minimum_should_match_script - if not isinstance(terms, NotSet): + if terms != DEFAULT: kwargs["terms"] = terms super().__init__(**kwargs) @@ -1073,25 +1089,25 @@ class TextExpansionQuery(QueryBase): :arg pruning_config: Token pruning configurations """ - model_id: Union[str, "NotSet"] - model_text: Union[str, "NotSet"] - pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "NotSet"] + model_id: Union[str, "DefaultType"] + model_text: Union[str, "DefaultType"] + pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] def __init__( self, *, - model_id: Union[str, "NotSet"] = NOT_SET, - model_text: Union[str, "NotSet"] = NOT_SET, + model_id: Union[str, "DefaultType"] = DEFAULT, + model_text: Union[str, "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(model_id, NotSet): + if model_id != DEFAULT: kwargs["model_id"] = model_id - if not isinstance(model_text, NotSet): + if model_text != DEFAULT: kwargs["model_text"] = model_text - if not isinstance(pruning_config, NotSet): + if pruning_config != DEFAULT: kwargs["pruning_config"] = pruning_config super().__init__(**kwargs) @@ -1107,23 +1123,23 @@ class TokenPruningConfig(AttrDict[Any]): only scoring kept tokens. """ - tokens_freq_ratio_threshold: Union[int, "NotSet"] - tokens_weight_threshold: Union[float, "NotSet"] - only_score_pruned_tokens: Union[bool, "NotSet"] + tokens_freq_ratio_threshold: Union[int, "DefaultType"] + tokens_weight_threshold: Union[float, "DefaultType"] + only_score_pruned_tokens: Union[bool, "DefaultType"] def __init__( self, *, - tokens_freq_ratio_threshold: Union[int, "NotSet"] = NOT_SET, - tokens_weight_threshold: Union[float, "NotSet"] = NOT_SET, - only_score_pruned_tokens: Union[bool, "NotSet"] = NOT_SET, + tokens_freq_ratio_threshold: Union[int, "DefaultType"] = DEFAULT, + tokens_weight_threshold: Union[float, "DefaultType"] = DEFAULT, + only_score_pruned_tokens: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(tokens_freq_ratio_threshold, NotSet): + if tokens_freq_ratio_threshold != DEFAULT: kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold - if not isinstance(tokens_weight_threshold, NotSet): + if tokens_weight_threshold != DEFAULT: kwargs["tokens_weight_threshold"] = tokens_weight_threshold - if not isinstance(only_score_pruned_tokens, NotSet): + if only_score_pruned_tokens != DEFAULT: kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens super().__init__(kwargs) @@ -1134,21 +1150,21 @@ class WeightedTokensQuery(QueryBase): :arg pruning_config: Token pruning configurations """ - tokens: Union[Mapping[str, float], "NotSet"] - pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "NotSet"] + tokens: Union[Mapping[str, float], "DefaultType"] + pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] def __init__( self, *, - tokens: Union[Mapping[str, float], "NotSet"] = NOT_SET, + tokens: Union[Mapping[str, float], "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(tokens, NotSet): + if tokens != DEFAULT: kwargs["tokens"] = tokens - if not isinstance(pruning_config, NotSet): + if pruning_config != DEFAULT: kwargs["pruning_config"] = pruning_config super().__init__(**kwargs) @@ -1166,27 +1182,27 @@ class WildcardQuery(QueryBase): provided field. Required, when value is not set. """ - case_insensitive: Union[bool, "NotSet"] - rewrite: Union[str, "NotSet"] - value: Union[str, "NotSet"] - wildcard: Union[str, "NotSet"] + case_insensitive: Union[bool, "DefaultType"] + rewrite: Union[str, "DefaultType"] + value: Union[str, "DefaultType"] + wildcard: Union[str, "DefaultType"] def __init__( self, *, - case_insensitive: Union[bool, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - value: Union[str, "NotSet"] = NOT_SET, - wildcard: Union[str, "NotSet"] = NOT_SET, + case_insensitive: Union[bool, "DefaultType"] = DEFAULT, + rewrite: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, "DefaultType"] = DEFAULT, + wildcard: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(case_insensitive, NotSet): + if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive - if not isinstance(rewrite, NotSet): + if rewrite != DEFAULT: kwargs["rewrite"] = rewrite - if not isinstance(value, NotSet): + if value != DEFAULT: kwargs["value"] = value - if not isinstance(wildcard, NotSet): + if wildcard != DEFAULT: kwargs["wildcard"] = wildcard super().__init__(**kwargs) @@ -1200,29 +1216,29 @@ class FieldCollapse(AttrDict[Any]): :arg collapse: No documentation available. """ - field: Union[str, "InstrumentedField", "NotSet"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet"] - max_concurrent_group_searches: Union[int, "NotSet"] - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] + field: Union[str, "InstrumentedField", "DefaultType"] + inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "DefaultType"] + max_concurrent_group_searches: Union[int, "DefaultType"] + collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, inner_hits: Union[ - "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_concurrent_group_searches: Union[int, "NotSet"] = NOT_SET, - collapse: Union["i.FieldCollapse", Dict[str, Any], "NotSet"] = NOT_SET, + "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + max_concurrent_group_searches: Union[int, "DefaultType"] = DEFAULT, + collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(field, NotSet): + if field != DEFAULT: kwargs["field"] = str(field) - if not isinstance(inner_hits, NotSet): + if inner_hits != DEFAULT: kwargs["inner_hits"] = inner_hits - if not isinstance(max_concurrent_group_searches, NotSet): + if max_concurrent_group_searches != DEFAULT: kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches - if not isinstance(collapse, NotSet): + if collapse != DEFAULT: kwargs["collapse"] = collapse super().__init__(kwargs) @@ -1235,23 +1251,23 @@ class FieldAndFormat(AttrDict[Any]): :arg include_unmapped: No documentation available. """ - field: Union[str, "InstrumentedField", "NotSet"] - format: Union[str, "NotSet"] - include_unmapped: Union[bool, "NotSet"] + field: Union[str, "InstrumentedField", "DefaultType"] + format: Union[str, "DefaultType"] + include_unmapped: Union[bool, "DefaultType"] def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - format: Union[str, "NotSet"] = NOT_SET, - include_unmapped: Union[bool, "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + format: Union[str, "DefaultType"] = DEFAULT, + include_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(field, NotSet): + if field != DEFAULT: kwargs["field"] = str(field) - if not isinstance(format, NotSet): + if format != DEFAULT: kwargs["format"] = format - if not isinstance(include_unmapped, NotSet): + if include_unmapped != DEFAULT: kwargs["include_unmapped"] = include_unmapped super().__init__(kwargs) @@ -1319,97 +1335,97 @@ class HighlightBase(AttrDict[Any]): :arg tags_schema: Set to `styled` to use the built-in tag schema. """ - type: Union[Literal["plain", "fvh", "unified"], "NotSet"] - boundary_chars: Union[str, "NotSet"] - boundary_max_scan: Union[int, "NotSet"] - boundary_scanner: Union[Literal["chars", "sentence", "word"], "NotSet"] - boundary_scanner_locale: Union[str, "NotSet"] - force_source: Union[bool, "NotSet"] - fragmenter: Union[Literal["simple", "span"], "NotSet"] - fragment_size: Union[int, "NotSet"] - highlight_filter: Union[bool, "NotSet"] - highlight_query: Union[Query, "NotSet"] - max_fragment_length: Union[int, "NotSet"] - max_analyzed_offset: Union[int, "NotSet"] - no_match_size: Union[int, "NotSet"] - number_of_fragments: Union[int, "NotSet"] - options: Union[Mapping[str, Any], "NotSet"] - order: Union[Literal["score"], "NotSet"] - phrase_limit: Union[int, "NotSet"] - post_tags: Union[List[str], "NotSet"] - pre_tags: Union[List[str], "NotSet"] - require_field_match: Union[bool, "NotSet"] - tags_schema: Union[Literal["styled"], "NotSet"] + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] + boundary_chars: Union[str, "DefaultType"] + boundary_max_scan: Union[int, "DefaultType"] + boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] + boundary_scanner_locale: Union[str, "DefaultType"] + force_source: Union[bool, "DefaultType"] + fragmenter: Union[Literal["simple", "span"], "DefaultType"] + fragment_size: Union[int, "DefaultType"] + highlight_filter: Union[bool, "DefaultType"] + highlight_query: Union[Query, "DefaultType"] + max_fragment_length: Union[int, "DefaultType"] + max_analyzed_offset: Union[int, "DefaultType"] + no_match_size: Union[int, "DefaultType"] + number_of_fragments: Union[int, "DefaultType"] + options: Union[Mapping[str, Any], "DefaultType"] + order: Union[Literal["score"], "DefaultType"] + phrase_limit: Union[int, "DefaultType"] + post_tags: Union[List[str], "DefaultType"] + pre_tags: Union[List[str], "DefaultType"] + require_field_match: Union[bool, "DefaultType"] + tags_schema: Union[Literal["styled"], "DefaultType"] def __init__( self, *, - type: Union[Literal["plain", "fvh", "unified"], "NotSet"] = NOT_SET, - boundary_chars: Union[str, "NotSet"] = NOT_SET, - boundary_max_scan: Union[int, "NotSet"] = NOT_SET, + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, + boundary_chars: Union[str, "DefaultType"] = DEFAULT, + boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "NotSet" - ] = NOT_SET, - boundary_scanner_locale: Union[str, "NotSet"] = NOT_SET, - force_source: Union[bool, "NotSet"] = NOT_SET, - fragmenter: Union[Literal["simple", "span"], "NotSet"] = NOT_SET, - fragment_size: Union[int, "NotSet"] = NOT_SET, - highlight_filter: Union[bool, "NotSet"] = NOT_SET, - highlight_query: Union[Query, "NotSet"] = NOT_SET, - max_fragment_length: Union[int, "NotSet"] = NOT_SET, - max_analyzed_offset: Union[int, "NotSet"] = NOT_SET, - no_match_size: Union[int, "NotSet"] = NOT_SET, - number_of_fragments: Union[int, "NotSet"] = NOT_SET, - options: Union[Mapping[str, Any], "NotSet"] = NOT_SET, - order: Union[Literal["score"], "NotSet"] = NOT_SET, - phrase_limit: Union[int, "NotSet"] = NOT_SET, - post_tags: Union[List[str], "NotSet"] = NOT_SET, - pre_tags: Union[List[str], "NotSet"] = NOT_SET, - require_field_match: Union[bool, "NotSet"] = NOT_SET, - tags_schema: Union[Literal["styled"], "NotSet"] = NOT_SET, + Literal["chars", "sentence", "word"], "DefaultType" + ] = DEFAULT, + boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, + force_source: Union[bool, "DefaultType"] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, + fragment_size: Union[int, "DefaultType"] = DEFAULT, + highlight_filter: Union[bool, "DefaultType"] = DEFAULT, + highlight_query: Union[Query, "DefaultType"] = DEFAULT, + max_fragment_length: Union[int, "DefaultType"] = DEFAULT, + max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, + no_match_size: Union[int, "DefaultType"] = DEFAULT, + number_of_fragments: Union[int, "DefaultType"] = DEFAULT, + options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, + order: Union[Literal["score"], "DefaultType"] = DEFAULT, + phrase_limit: Union[int, "DefaultType"] = DEFAULT, + post_tags: Union[List[str], "DefaultType"] = DEFAULT, + pre_tags: Union[List[str], "DefaultType"] = DEFAULT, + require_field_match: Union[bool, "DefaultType"] = DEFAULT, + tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(type, NotSet): + if type != DEFAULT: kwargs["type"] = type - if not isinstance(boundary_chars, NotSet): + if boundary_chars != DEFAULT: kwargs["boundary_chars"] = boundary_chars - if not isinstance(boundary_max_scan, NotSet): + if boundary_max_scan != DEFAULT: kwargs["boundary_max_scan"] = boundary_max_scan - if not isinstance(boundary_scanner, NotSet): + if boundary_scanner != DEFAULT: kwargs["boundary_scanner"] = boundary_scanner - if not isinstance(boundary_scanner_locale, NotSet): + if boundary_scanner_locale != DEFAULT: kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if not isinstance(force_source, NotSet): + if force_source != DEFAULT: kwargs["force_source"] = force_source - if not isinstance(fragmenter, NotSet): + if fragmenter != DEFAULT: kwargs["fragmenter"] = fragmenter - if not isinstance(fragment_size, NotSet): + if fragment_size != DEFAULT: kwargs["fragment_size"] = fragment_size - if not isinstance(highlight_filter, NotSet): + if highlight_filter != DEFAULT: kwargs["highlight_filter"] = highlight_filter - if not isinstance(highlight_query, NotSet): + if highlight_query != DEFAULT: kwargs["highlight_query"] = highlight_query - if not isinstance(max_fragment_length, NotSet): + if max_fragment_length != DEFAULT: kwargs["max_fragment_length"] = max_fragment_length - if not isinstance(max_analyzed_offset, NotSet): + if max_analyzed_offset != DEFAULT: kwargs["max_analyzed_offset"] = max_analyzed_offset - if not isinstance(no_match_size, NotSet): + if no_match_size != DEFAULT: kwargs["no_match_size"] = no_match_size - if not isinstance(number_of_fragments, NotSet): + if number_of_fragments != DEFAULT: kwargs["number_of_fragments"] = number_of_fragments - if not isinstance(options, NotSet): + if options != DEFAULT: kwargs["options"] = options - if not isinstance(order, NotSet): + if order != DEFAULT: kwargs["order"] = order - if not isinstance(phrase_limit, NotSet): + if phrase_limit != DEFAULT: kwargs["phrase_limit"] = phrase_limit - if not isinstance(post_tags, NotSet): + if post_tags != DEFAULT: kwargs["post_tags"] = post_tags - if not isinstance(pre_tags, NotSet): + if pre_tags != DEFAULT: kwargs["pre_tags"] = pre_tags - if not isinstance(require_field_match, NotSet): + if require_field_match != DEFAULT: kwargs["require_field_match"] = require_field_match - if not isinstance(tags_schema, NotSet): + if tags_schema != DEFAULT: kwargs["tags_schema"] = tags_schema super().__init__(kwargs) @@ -1420,27 +1436,27 @@ class Highlight(HighlightBase): :arg fields: (required) No documentation available. """ - encoder: Union[Literal["default", "html"], "NotSet"] + encoder: Union[Literal["default", "html"], "DefaultType"] fields: Union[ Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], Dict[str, Any], - "NotSet", + "DefaultType", ] def __init__( self, *, - encoder: Union[Literal["default", "html"], "NotSet"] = NOT_SET, + encoder: Union[Literal["default", "html"], "DefaultType"] = DEFAULT, fields: Union[ Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], Dict[str, Any], - "NotSet", - ] = NOT_SET, + "DefaultType", + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(encoder, NotSet): + if encoder != DEFAULT: kwargs["encoder"] = encoder - if not isinstance(fields, NotSet): + if fields != DEFAULT: kwargs["fields"] = str(fields) super().__init__(**kwargs) @@ -1451,19 +1467,19 @@ class ScriptField(AttrDict[Any]): :arg ignore_failure: No documentation available. """ - script: Union["i.Script", Dict[str, Any], "NotSet"] - ignore_failure: Union[bool, "NotSet"] + script: Union["i.Script", Dict[str, Any], "DefaultType"] + ignore_failure: Union[bool, "DefaultType"] def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - ignore_failure: Union[bool, "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + ignore_failure: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(script, NotSet): + if script != DEFAULT: kwargs["script"] = script - if not isinstance(ignore_failure, NotSet): + if ignore_failure != DEFAULT: kwargs["ignore_failure"] = ignore_failure super().__init__(kwargs) @@ -1476,27 +1492,29 @@ class SortOptions(AttrDict[Any]): :arg _script: No documentation available. """ - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] + _score: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] + _doc: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] + _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "DefaultType"] + _script: Union["i.ScriptSort", Dict[str, Any], "DefaultType"] def __init__( self, *, - _score: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _doc: Union["i.ScoreSort", Dict[str, Any], "NotSet"] = NOT_SET, - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "NotSet"] = NOT_SET, - _script: Union["i.ScriptSort", Dict[str, Any], "NotSet"] = NOT_SET, + _score: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _doc: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _geo_distance: Union[ + "i.GeoDistanceSort", Dict[str, Any], "DefaultType" + ] = DEFAULT, + _script: Union["i.ScriptSort", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_score, NotSet): + if _score != DEFAULT: kwargs["_score"] = _score - if not isinstance(_doc, NotSet): + if _doc != DEFAULT: kwargs["_doc"] = _doc - if not isinstance(_geo_distance, NotSet): + if _geo_distance != DEFAULT: kwargs["_geo_distance"] = _geo_distance - if not isinstance(_script, NotSet): + if _script != DEFAULT: kwargs["_script"] = _script super().__init__(kwargs) @@ -1508,10 +1526,14 @@ class SourceFilter(AttrDict[Any]): """ excludes: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "DefaultType", ] includes: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "DefaultType", ] def __init__( @@ -1520,18 +1542,18 @@ def __init__( excludes: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, + "DefaultType", + ] = DEFAULT, includes: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, + "DefaultType", + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(excludes, NotSet): + if excludes != DEFAULT: kwargs["excludes"] = str(excludes) - if not isinstance(includes, NotSet): + if includes != DEFAULT: kwargs["includes"] = str(includes) super().__init__(kwargs) @@ -1549,29 +1571,29 @@ class IntervalsAllOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] - max_gaps: Union[int, "NotSet"] - ordered: Union[bool, "NotSet"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] + max_gaps: Union[int, "DefaultType"] + ordered: Union[bool, "DefaultType"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_gaps: Union[int, "NotSet"] = NOT_SET, - ordered: Union[bool, "NotSet"] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + List["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + max_gaps: Union[int, "DefaultType"] = DEFAULT, + ordered: Union[bool, "DefaultType"] = DEFAULT, + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(intervals, NotSet): + if intervals != DEFAULT: kwargs["intervals"] = intervals - if not isinstance(max_gaps, NotSet): + if max_gaps != DEFAULT: kwargs["max_gaps"] = max_gaps - if not isinstance(ordered, NotSet): + if ordered != DEFAULT: kwargs["ordered"] = ordered - if not isinstance(filter, NotSet): + if filter != DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -1582,21 +1604,21 @@ class IntervalsAnyOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "NotSet"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + List["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(intervals, NotSet): + if intervals != DEFAULT: kwargs["intervals"] = intervals - if not isinstance(filter, NotSet): + if filter != DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -1616,35 +1638,35 @@ class IntervalsFuzzy(AttrDict[Any]): separately. """ - analyzer: Union[str, "NotSet"] - fuzziness: Union[str, int, "NotSet"] - prefix_length: Union[int, "NotSet"] - term: Union[str, "NotSet"] - transpositions: Union[bool, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] + analyzer: Union[str, "DefaultType"] + fuzziness: Union[str, int, "DefaultType"] + prefix_length: Union[int, "DefaultType"] + term: Union[str, "DefaultType"] + transpositions: Union[bool, "DefaultType"] + use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - term: Union[str, "NotSet"] = NOT_SET, - transpositions: Union[bool, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + prefix_length: Union[int, "DefaultType"] = DEFAULT, + term: Union[str, "DefaultType"] = DEFAULT, + transpositions: Union[bool, "DefaultType"] = DEFAULT, + use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(fuzziness, NotSet): + if fuzziness != DEFAULT: kwargs["fuzziness"] = fuzziness - if not isinstance(prefix_length, NotSet): + if prefix_length != DEFAULT: kwargs["prefix_length"] = prefix_length - if not isinstance(term, NotSet): + if term != DEFAULT: kwargs["term"] = term - if not isinstance(transpositions, NotSet): + if transpositions != DEFAULT: kwargs["transpositions"] = transpositions - if not isinstance(use_field, NotSet): + if use_field != DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -1664,35 +1686,35 @@ class IntervalsMatch(AttrDict[Any]): :arg filter: An optional interval filter. """ - analyzer: Union[str, "NotSet"] - max_gaps: Union[int, "NotSet"] - ordered: Union[bool, "NotSet"] - query: Union[str, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] + analyzer: Union[str, "DefaultType"] + max_gaps: Union[int, "DefaultType"] + ordered: Union[bool, "DefaultType"] + query: Union[str, "DefaultType"] + use_field: Union[str, "InstrumentedField", "DefaultType"] + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - max_gaps: Union[int, "NotSet"] = NOT_SET, - ordered: Union[bool, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - filter: Union["i.IntervalsFilter", Dict[str, Any], "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + max_gaps: Union[int, "DefaultType"] = DEFAULT, + ordered: Union[bool, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, + use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(max_gaps, NotSet): + if max_gaps != DEFAULT: kwargs["max_gaps"] = max_gaps - if not isinstance(ordered, NotSet): + if ordered != DEFAULT: kwargs["ordered"] = ordered - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query - if not isinstance(use_field, NotSet): + if use_field != DEFAULT: kwargs["use_field"] = str(use_field) - if not isinstance(filter, NotSet): + if filter != DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -1708,23 +1730,23 @@ class IntervalsPrefix(AttrDict[Any]): separately. """ - analyzer: Union[str, "NotSet"] - prefix: Union[str, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] + analyzer: Union[str, "DefaultType"] + prefix: Union[str, "DefaultType"] + use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - prefix: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + prefix: Union[str, "DefaultType"] = DEFAULT, + use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(prefix, NotSet): + if prefix != DEFAULT: kwargs["prefix"] = prefix - if not isinstance(use_field, NotSet): + if use_field != DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -1740,23 +1762,23 @@ class IntervalsWildcard(AttrDict[Any]): separately. """ - analyzer: Union[str, "NotSet"] - pattern: Union[str, "NotSet"] - use_field: Union[str, "InstrumentedField", "NotSet"] + analyzer: Union[str, "DefaultType"] + pattern: Union[str, "DefaultType"] + use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - analyzer: Union[str, "NotSet"] = NOT_SET, - pattern: Union[str, "NotSet"] = NOT_SET, - use_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + analyzer: Union[str, "DefaultType"] = DEFAULT, + pattern: Union[str, "DefaultType"] = DEFAULT, + use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer - if not isinstance(pattern, NotSet): + if pattern != DEFAULT: kwargs["pattern"] = pattern - if not isinstance(use_field, NotSet): + if use_field != DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -1767,19 +1789,19 @@ class TextEmbedding(AttrDict[Any]): :arg model_text: (required) No documentation available. """ - model_id: Union[str, "NotSet"] - model_text: Union[str, "NotSet"] + model_id: Union[str, "DefaultType"] + model_text: Union[str, "DefaultType"] def __init__( self, *, - model_id: Union[str, "NotSet"] = NOT_SET, - model_text: Union[str, "NotSet"] = NOT_SET, + model_id: Union[str, "DefaultType"] = DEFAULT, + model_text: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(model_id, NotSet): + if model_id != DEFAULT: kwargs["model_id"] = model_id - if not isinstance(model_text, NotSet): + if model_text != DEFAULT: kwargs["model_text"] = model_text super().__init__(kwargs) @@ -1792,19 +1814,19 @@ class SpanContainingQuery(QueryBase): `big` that contain matches from `little` are returned. """ - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(big, NotSet): + if big != DEFAULT: kwargs["big"] = big - if not isinstance(little, NotSet): + if little != DEFAULT: kwargs["little"] = little super().__init__(**kwargs) @@ -1815,19 +1837,19 @@ class SpanFieldMaskingQuery(QueryBase): :arg query: (required) No documentation available. """ - field: Union[str, "InstrumentedField", "NotSet"] - query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + field: Union[str, "InstrumentedField", "DefaultType"] + query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(field, NotSet): + if field != DEFAULT: kwargs["field"] = str(field) - if not isinstance(query, NotSet): + if query != DEFAULT: kwargs["query"] = query super().__init__(**kwargs) @@ -1839,19 +1861,19 @@ class SpanFirstQuery(QueryBase): :arg match: (required) Can be any other span type query. """ - end: Union[int, "NotSet"] - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + end: Union[int, "DefaultType"] + match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, - end: Union[int, "NotSet"] = NOT_SET, - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + end: Union[int, "DefaultType"] = DEFAULT, + match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(end, NotSet): + if end != DEFAULT: kwargs["end"] = end - if not isinstance(match, NotSet): + if match != DEFAULT: kwargs["match"] = match super().__init__(**kwargs) @@ -1862,10 +1884,10 @@ class SpanMultiTermQuery(QueryBase): `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). """ - match: Union[Query, "NotSet"] + match: Union[Query, "DefaultType"] - def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): - if not isinstance(match, NotSet): + def __init__(self, *, match: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): + if match != DEFAULT: kwargs["match"] = match super().__init__(**kwargs) @@ -1878,23 +1900,23 @@ class SpanNearQuery(QueryBase): positions permitted. """ - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] - in_order: Union[bool, "NotSet"] - slop: Union[int, "NotSet"] + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] + in_order: Union[bool, "DefaultType"] + slop: Union[int, "DefaultType"] def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, - in_order: Union[bool, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + in_order: Union[bool, "DefaultType"] = DEFAULT, + slop: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(clauses, NotSet): + if clauses != DEFAULT: kwargs["clauses"] = clauses - if not isinstance(in_order, NotSet): + if in_order != DEFAULT: kwargs["in_order"] = in_order - if not isinstance(slop, NotSet): + if slop != DEFAULT: kwargs["slop"] = slop super().__init__(**kwargs) @@ -1913,31 +1935,31 @@ class SpanNotQuery(QueryBase): overlap with the exclude span. """ - dist: Union[int, "NotSet"] - exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - post: Union[int, "NotSet"] - pre: Union[int, "NotSet"] + dist: Union[int, "DefaultType"] + exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + post: Union[int, "DefaultType"] + pre: Union[int, "DefaultType"] def __init__( self, *, - dist: Union[int, "NotSet"] = NOT_SET, - exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - post: Union[int, "NotSet"] = NOT_SET, - pre: Union[int, "NotSet"] = NOT_SET, + dist: Union[int, "DefaultType"] = DEFAULT, + exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + post: Union[int, "DefaultType"] = DEFAULT, + pre: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(dist, NotSet): + if dist != DEFAULT: kwargs["dist"] = dist - if not isinstance(exclude, NotSet): + if exclude != DEFAULT: kwargs["exclude"] = exclude - if not isinstance(include, NotSet): + if include != DEFAULT: kwargs["include"] = include - if not isinstance(post, NotSet): + if post != DEFAULT: kwargs["post"] = post - if not isinstance(pre, NotSet): + if pre != DEFAULT: kwargs["pre"] = pre super().__init__(**kwargs) @@ -1947,15 +1969,15 @@ class SpanOrQuery(QueryBase): :arg clauses: (required) Array of one or more other span type queries. """ - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(clauses, NotSet): + if clauses != DEFAULT: kwargs["clauses"] = clauses super().__init__(**kwargs) @@ -1968,19 +1990,19 @@ class SpanWithinQuery(QueryBase): `little` that are enclosed within `big` are returned. """ - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(big, NotSet): + if big != DEFAULT: kwargs["big"] = big - if not isinstance(little, NotSet): + if little != DEFAULT: kwargs["little"] = little super().__init__(**kwargs) @@ -1992,29 +2014,31 @@ class HighlightField(HighlightBase): :arg analyzer: No documentation available. """ - fragment_offset: Union[int, "NotSet"] + fragment_offset: Union[int, "DefaultType"] matched_fields: Union[ - Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], "NotSet" + Union[str, "InstrumentedField"], + List[Union[str, "InstrumentedField"]], + "DefaultType", ] - analyzer: Union[str, Dict[str, Any], "NotSet"] + analyzer: Union[str, Dict[str, Any], "DefaultType"] def __init__( self, *, - fragment_offset: Union[int, "NotSet"] = NOT_SET, + fragment_offset: Union[int, "DefaultType"] = DEFAULT, matched_fields: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - analyzer: Union[str, Dict[str, Any], "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + analyzer: Union[str, Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(fragment_offset, NotSet): + if fragment_offset != DEFAULT: kwargs["fragment_offset"] = fragment_offset - if not isinstance(matched_fields, NotSet): + if matched_fields != DEFAULT: kwargs["matched_fields"] = str(matched_fields) - if not isinstance(analyzer, NotSet): + if analyzer != DEFAULT: kwargs["analyzer"] = analyzer super().__init__(**kwargs) @@ -2024,12 +2048,15 @@ class ScoreSort(AttrDict[Any]): :arg order: No documentation available. """ - order: Union[Literal["asc", "desc"], "NotSet"] + order: Union[Literal["asc", "desc"], "DefaultType"] def __init__( - self, *, order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, **kwargs: Any + self, + *, + order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, + **kwargs: Any, ): - if not isinstance(order, NotSet): + if order != DEFAULT: kwargs["order"] = order super().__init__(kwargs) @@ -2044,37 +2071,41 @@ class GeoDistanceSort(AttrDict[Any]): :arg nested: No documentation available. """ - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] - distance_type: Union[Literal["arc", "plane"], "NotSet"] - ignore_unmapped: Union[bool, "NotSet"] - order: Union[Literal["asc", "desc"], "NotSet"] - unit: Union[Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet"] - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] + distance_type: Union[Literal["arc", "plane"], "DefaultType"] + ignore_unmapped: Union[bool, "DefaultType"] + order: Union[Literal["asc", "desc"], "DefaultType"] + unit: Union[ + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" + ] + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] def __init__( self, *, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, + mode: Union[ + Literal["min", "max", "sum", "avg", "median"], "DefaultType" + ] = DEFAULT, + distance_type: Union[Literal["arc", "plane"], "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, unit: Union[ - Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "NotSet" - ] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" + ] = DEFAULT, + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(mode, NotSet): + if mode != DEFAULT: kwargs["mode"] = mode - if not isinstance(distance_type, NotSet): + if distance_type != DEFAULT: kwargs["distance_type"] = distance_type - if not isinstance(ignore_unmapped, NotSet): + if ignore_unmapped != DEFAULT: kwargs["ignore_unmapped"] = ignore_unmapped - if not isinstance(order, NotSet): + if order != DEFAULT: kwargs["order"] = order - if not isinstance(unit, NotSet): + if unit != DEFAULT: kwargs["unit"] = unit - if not isinstance(nested, NotSet): + if nested != DEFAULT: kwargs["nested"] = nested super().__init__(kwargs) @@ -2088,31 +2119,33 @@ class ScriptSort(AttrDict[Any]): :arg nested: No documentation available. """ - order: Union[Literal["asc", "desc"], "NotSet"] - script: Union["i.Script", Dict[str, Any], "NotSet"] - type: Union[Literal["string", "number", "version"], "NotSet"] - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] + order: Union[Literal["asc", "desc"], "DefaultType"] + script: Union["i.Script", Dict[str, Any], "DefaultType"] + type: Union[Literal["string", "number", "version"], "DefaultType"] + mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] def __init__( self, *, - order: Union[Literal["asc", "desc"], "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - type: Union[Literal["string", "number", "version"], "NotSet"] = NOT_SET, - mode: Union[Literal["min", "max", "sum", "avg", "median"], "NotSet"] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, + order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, + script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + type: Union[Literal["string", "number", "version"], "DefaultType"] = DEFAULT, + mode: Union[ + Literal["min", "max", "sum", "avg", "median"], "DefaultType" + ] = DEFAULT, + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(order, NotSet): + if order != DEFAULT: kwargs["order"] = order - if not isinstance(script, NotSet): + if script != DEFAULT: kwargs["script"] = script - if not isinstance(type, NotSet): + if type != DEFAULT: kwargs["type"] = type - if not isinstance(mode, NotSet): + if mode != DEFAULT: kwargs["mode"] = mode - if not isinstance(nested, NotSet): + if nested != DEFAULT: kwargs["nested"] = nested super().__init__(kwargs) @@ -2128,35 +2161,35 @@ class IntervalsContainer(AttrDict[Any]): :arg wildcard: Matches terms using a wildcard pattern. """ - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] - match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] + match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] def __init__( self, *, - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "NotSet"] = NOT_SET, - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "NotSet"] = NOT_SET, - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "NotSet"] = NOT_SET, - match: Union["i.IntervalsMatch", Dict[str, Any], "NotSet"] = NOT_SET, - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "NotSet"] = NOT_SET, - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "NotSet"] = NOT_SET, + all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, + any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, + fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, + prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, + wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(all_of, NotSet): + if all_of != DEFAULT: kwargs["all_of"] = all_of - if not isinstance(any_of, NotSet): + if any_of != DEFAULT: kwargs["any_of"] = any_of - if not isinstance(fuzzy, NotSet): + if fuzzy != DEFAULT: kwargs["fuzzy"] = fuzzy - if not isinstance(match, NotSet): + if match != DEFAULT: kwargs["match"] = match - if not isinstance(prefix, NotSet): + if prefix != DEFAULT: kwargs["prefix"] = prefix - if not isinstance(wildcard, NotSet): + if wildcard != DEFAULT: kwargs["wildcard"] = wildcard super().__init__(kwargs) @@ -2183,53 +2216,59 @@ class IntervalsFilter(AttrDict[Any]): must return a boolean value: `true` or `false`. """ - after: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - before: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - not_contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - not_containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - not_overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] - script: Union["i.Script", Dict[str, Any], "NotSet"] + after: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + before: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + contained_by: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + containing: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_contained_by: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_containing: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_overlapping: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + overlapping: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] + script: Union["i.Script", Dict[str, Any], "DefaultType"] def __init__( self, *, - after: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, - before: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, - contained_by: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, - containing: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, + after: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] = DEFAULT, + before: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] = DEFAULT, + contained_by: Union[ + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, + containing: Union[ + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, not_contained_by: Union[ - "i.IntervalsContainer", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, not_containing: Union[ - "i.IntervalsContainer", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, not_overlapping: Union[ - "i.IntervalsContainer", Dict[str, Any], "NotSet" - ] = NOT_SET, - overlapping: Union["i.IntervalsContainer", Dict[str, Any], "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, + overlapping: Union[ + "i.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, + script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(after, NotSet): + if after != DEFAULT: kwargs["after"] = after - if not isinstance(before, NotSet): + if before != DEFAULT: kwargs["before"] = before - if not isinstance(contained_by, NotSet): + if contained_by != DEFAULT: kwargs["contained_by"] = contained_by - if not isinstance(containing, NotSet): + if containing != DEFAULT: kwargs["containing"] = containing - if not isinstance(not_contained_by, NotSet): + if not_contained_by != DEFAULT: kwargs["not_contained_by"] = not_contained_by - if not isinstance(not_containing, NotSet): + if not_containing != DEFAULT: kwargs["not_containing"] = not_containing - if not isinstance(not_overlapping, NotSet): + if not_overlapping != DEFAULT: kwargs["not_overlapping"] = not_overlapping - if not isinstance(overlapping, NotSet): + if overlapping != DEFAULT: kwargs["overlapping"] = overlapping - if not isinstance(script, NotSet): + if script != DEFAULT: kwargs["script"] = script super().__init__(kwargs) @@ -2242,26 +2281,26 @@ class NestedSortValue(AttrDict[Any]): :arg path: (required) No documentation available. """ - filter: Union[Query, "NotSet"] - max_children: Union[int, "NotSet"] - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] - path: Union[str, "InstrumentedField", "NotSet"] + filter: Union[Query, "DefaultType"] + max_children: Union[int, "DefaultType"] + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] + path: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - filter: Union[Query, "NotSet"] = NOT_SET, - max_children: Union[int, "NotSet"] = NOT_SET, - nested: Union["i.NestedSortValue", Dict[str, Any], "NotSet"] = NOT_SET, - path: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + filter: Union[Query, "DefaultType"] = DEFAULT, + max_children: Union[int, "DefaultType"] = DEFAULT, + nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(filter, NotSet): + if filter != DEFAULT: kwargs["filter"] = filter - if not isinstance(max_children, NotSet): + if max_children != DEFAULT: kwargs["max_children"] = max_children - if not isinstance(nested, NotSet): + if nested != DEFAULT: kwargs["nested"] = nested - if not isinstance(path, NotSet): + if path != DEFAULT: kwargs["path"] = str(path) super().__init__(kwargs) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 0519279d..cef0fab1 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -36,13 +36,17 @@ overload, ) +from elastic_transport.client_utils import DEFAULT + # 'SF' looks unused but the test suite assumes it's available # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import NOT_SET, DslBase, NotSet +from .utils import DslBase if TYPE_CHECKING: + from elastic_transport.client_utils import DefaultType + from elasticsearch_dsl import interfaces as i from elasticsearch_dsl import wrappers @@ -172,11 +176,11 @@ class Bool(Query): def __init__( self, *, - filter: Union[Query, List[Query], "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - must: Union[Query, List[Query], "NotSet"] = NOT_SET, - must_not: Union[Query, List[Query], "NotSet"] = NOT_SET, - should: Union[Query, List[Query], "NotSet"] = NOT_SET, + filter: Union[Query, List[Query], "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + must: Union[Query, List[Query], "DefaultType"] = DEFAULT, + must_not: Union[Query, List[Query], "DefaultType"] = DEFAULT, + should: Union[Query, List[Query], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -320,9 +324,9 @@ class Boosting(Query): def __init__( self, *, - negative: Union[Query, "NotSet"] = NOT_SET, - positive: Union[Query, "NotSet"] = NOT_SET, - negative_boost: Union[float, "NotSet"] = NOT_SET, + negative: Union[Query, "DefaultType"] = DEFAULT, + positive: Union[Query, "DefaultType"] = DEFAULT, + negative_boost: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -345,11 +349,11 @@ class Common(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.CommonTermsQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.CommonTermsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -381,12 +385,12 @@ class CombinedFields(Query): def __init__( self, *, - query: Union[str, "NotSet"] = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - operator: Union[Literal["or", "and"], "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - zero_terms_query: Union[Literal["none", "all"], "NotSet"] = NOT_SET, + query: Union[str, "DefaultType"] = DEFAULT, + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, + operator: Union[Literal["or", "and"], "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + zero_terms_query: Union[Literal["none", "all"], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -416,7 +420,7 @@ class ConstantScore(Query): "filter": {"type": "query"}, } - def __init__(self, *, filter: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): + def __init__(self, *, filter: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): super().__init__(filter=filter, **kwargs) @@ -444,8 +448,8 @@ class DisMax(Query): def __init__( self, *, - queries: Union[List[Query], "NotSet"] = NOT_SET, - tie_breaker: Union[float, "NotSet"] = NOT_SET, + queries: Union[List[Query], "DefaultType"] = DEFAULT, + tie_breaker: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(queries=queries, tie_breaker=tie_breaker, **kwargs) @@ -481,9 +485,9 @@ class DistanceFeature(Query): def __init__( self, *, - pivot: Any = NOT_SET, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - origin: Any = NOT_SET, + pivot: Any = DEFAULT, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + origin: Any = DEFAULT, **kwargs: Any, ): super().__init__(pivot=pivot, field=field, origin=origin, **kwargs) @@ -501,7 +505,7 @@ class Exists(Query): def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(field=field, **kwargs) @@ -536,20 +540,20 @@ def __init__( self, *, boost_mode: Union[ - Literal["multiply", "replace", "sum", "avg", "max", "min"], "NotSet" - ] = NOT_SET, + Literal["multiply", "replace", "sum", "avg", "max", "min"], "DefaultType" + ] = DEFAULT, functions: Union[ - List["i.FunctionScoreContainer"], Dict[str, Any], "NotSet" - ] = NOT_SET, - max_boost: Union[float, "NotSet"] = NOT_SET, - min_score: Union[float, "NotSet"] = NOT_SET, - query: Union[Query, "NotSet"] = NOT_SET, + List["i.FunctionScoreContainer"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + max_boost: Union[float, "DefaultType"] = DEFAULT, + min_score: Union[float, "DefaultType"] = DEFAULT, + query: Union[Query, "DefaultType"] = DEFAULT, score_mode: Union[ - Literal["multiply", "sum", "avg", "first", "max", "min"], "NotSet" - ] = NOT_SET, + Literal["multiply", "sum", "avg", "first", "max", "min"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if isinstance(functions, NotSet): + if functions == DEFAULT: functions = [] for name in ScoreFunction._classes: if name in kwargs: @@ -578,11 +582,11 @@ class Fuzzy(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.FuzzyQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.FuzzyQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -605,11 +609,11 @@ class GeoBoundingBox(Query): def __init__( self, *, - type: Union[Literal["memory", "indexed"], "NotSet"] = NOT_SET, + type: Union[Literal["memory", "indexed"], "DefaultType"] = DEFAULT, validation_method: Union[ - Literal["coerce", "ignore_malformed", "strict"], "NotSet" - ] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + Literal["coerce", "ignore_malformed", "strict"], "DefaultType" + ] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -644,12 +648,12 @@ class GeoDistance(Query): def __init__( self, *, - distance: Union[str, "NotSet"] = NOT_SET, - distance_type: Union[Literal["arc", "plane"], "NotSet"] = NOT_SET, + distance: Union[str, "DefaultType"] = DEFAULT, + distance_type: Union[Literal["arc", "plane"], "DefaultType"] = DEFAULT, validation_method: Union[ - Literal["coerce", "ignore_malformed", "strict"], "NotSet" - ] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + Literal["coerce", "ignore_malformed", "strict"], "DefaultType" + ] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -675,9 +679,9 @@ def __init__( self, *, validation_method: Union[ - Literal["coerce", "ignore_malformed", "strict"], "NotSet" - ] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, + Literal["coerce", "ignore_malformed", "strict"], "DefaultType" + ] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -700,7 +704,7 @@ class GeoShape(Query): name = "geo_shape" def __init__( - self, *, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any + self, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any ): super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) @@ -738,15 +742,15 @@ class HasChild(Query): def __init__( self, *, - query: Union[Query, "NotSet"] = NOT_SET, - type: Union[str, "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, - max_children: Union[int, "NotSet"] = NOT_SET, - min_children: Union[int, "NotSet"] = NOT_SET, + query: Union[Query, "DefaultType"] = DEFAULT, + type: Union[str, "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, + max_children: Union[int, "DefaultType"] = DEFAULT, + min_children: Union[int, "DefaultType"] = DEFAULT, score_mode: Union[ - Literal["none", "avg", "sum", "max", "min"], "NotSet" - ] = NOT_SET, + Literal["none", "avg", "sum", "max", "min"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -788,11 +792,11 @@ class HasParent(Query): def __init__( self, *, - parent_type: Union[str, "NotSet"] = NOT_SET, - query: Union[Query, "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, - score: Union[bool, "NotSet"] = NOT_SET, + parent_type: Union[str, "DefaultType"] = DEFAULT, + query: Union[Query, "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, + score: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -816,7 +820,7 @@ class Ids(Query): name = "ids" def __init__( - self, *, values: Union[str, List[str], "NotSet"] = NOT_SET, **kwargs: Any + self, *, values: Union[str, List[str], "DefaultType"] = DEFAULT, **kwargs: Any ): super().__init__(values=values, **kwargs) @@ -833,11 +837,11 @@ class Intervals(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.IntervalsQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.IntervalsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -868,15 +872,15 @@ class Knn(Query): def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query_vector: Union[List[float], "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + query_vector: Union[List[float], "DefaultType"] = DEFAULT, query_vector_builder: Union[ - "i.QueryVectorBuilder", Dict[str, Any], "NotSet" - ] = NOT_SET, - num_candidates: Union[int, "NotSet"] = NOT_SET, - k: Union[int, "NotSet"] = NOT_SET, - filter: Union[Query, List[Query], "NotSet"] = NOT_SET, - similarity: Union[float, "NotSet"] = NOT_SET, + "i.QueryVectorBuilder", Dict[str, Any], "DefaultType" + ] = DEFAULT, + num_candidates: Union[int, "DefaultType"] = DEFAULT, + k: Union[int, "DefaultType"] = DEFAULT, + filter: Union[Query, List[Query], "DefaultType"] = DEFAULT, + similarity: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -904,11 +908,11 @@ class Match(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.MatchQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -954,11 +958,13 @@ class MatchBoolPrefix(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchBoolPrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union[ + "i.MatchBoolPrefixQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -999,11 +1005,11 @@ class MatchPhrase(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchPhraseQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.MatchPhraseQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1022,11 +1028,13 @@ class MatchPhrasePrefix(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.MatchPhrasePrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union[ + "i.MatchPhrasePrefixQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1084,32 +1092,32 @@ def __init__( Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], Dict[str, Any], - "NotSet", - ] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, - boost_terms: Union[float, "NotSet"] = NOT_SET, - fail_on_unsupported_field: Union[bool, "NotSet"] = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - include: Union[bool, "NotSet"] = NOT_SET, - max_doc_freq: Union[int, "NotSet"] = NOT_SET, - max_query_terms: Union[int, "NotSet"] = NOT_SET, - max_word_length: Union[int, "NotSet"] = NOT_SET, - min_doc_freq: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - min_term_freq: Union[int, "NotSet"] = NOT_SET, - min_word_length: Union[int, "NotSet"] = NOT_SET, - routing: Union[str, "NotSet"] = NOT_SET, - stop_words: Union[str, List[str], "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, + boost_terms: Union[float, "DefaultType"] = DEFAULT, + fail_on_unsupported_field: Union[bool, "DefaultType"] = DEFAULT, + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + include: Union[bool, "DefaultType"] = DEFAULT, + max_doc_freq: Union[int, "DefaultType"] = DEFAULT, + max_query_terms: Union[int, "DefaultType"] = DEFAULT, + max_word_length: Union[int, "DefaultType"] = DEFAULT, + min_doc_freq: Union[int, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + min_term_freq: Union[int, "DefaultType"] = DEFAULT, + min_word_length: Union[int, "DefaultType"] = DEFAULT, + routing: Union[str, "DefaultType"] = DEFAULT, + stop_words: Union[str, List[str], "DefaultType"] = DEFAULT, unlike: Union[ Union[str, "i.LikeDocument"], List[Union[str, "i.LikeDocument"]], Dict[str, Any], - "NotSet", - ] = NOT_SET, - version: Union[int, "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + version: Union[int, "DefaultType"] = DEFAULT, version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "NotSet" - ] = NOT_SET, + Literal["internal", "external", "external_gte", "force"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1182,25 +1190,25 @@ class MultiMatch(Query): def __init__( self, *, - query: Union[str, "NotSet"] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - cutoff_frequency: Union[float, "NotSet"] = NOT_SET, + query: Union[str, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, + cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, fields: Union[ Union[str, "InstrumentedField"], List[Union[str, "InstrumentedField"]], - "NotSet", - ] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, - max_expansions: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - prefix_length: Union[int, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, - tie_breaker: Union[float, "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, + fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, + lenient: Union[bool, "DefaultType"] = DEFAULT, + max_expansions: Union[int, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + prefix_length: Union[int, "DefaultType"] = DEFAULT, + slop: Union[int, "DefaultType"] = DEFAULT, + tie_breaker: Union[float, "DefaultType"] = DEFAULT, type: Union[ Literal[ "best_fields", @@ -1210,9 +1218,9 @@ def __init__( "phrase_prefix", "bool_prefix", ], - "NotSet", - ] = NOT_SET, - zero_terms_query: Union[Literal["all", "none"], "NotSet"] = NOT_SET, + "DefaultType", + ] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1260,13 +1268,13 @@ class Nested(Query): def __init__( self, *, - path: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query: Union[Query, "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - inner_hits: Union["i.InnerHits", Dict[str, Any], "NotSet"] = NOT_SET, + path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + query: Union[Query, "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, score_mode: Union[ - Literal["none", "avg", "sum", "max", "min"], "NotSet" - ] = NOT_SET, + Literal["none", "avg", "sum", "max", "min"], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1294,9 +1302,9 @@ class ParentId(Query): def __init__( self, *, - id: Union[str, "NotSet"] = NOT_SET, - ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, - type: Union[str, "NotSet"] = NOT_SET, + id: Union[str, "DefaultType"] = DEFAULT, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + type: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(id=id, ignore_unmapped=ignore_unmapped, type=type, **kwargs) @@ -1324,15 +1332,15 @@ class Percolate(Query): def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - document: Any = NOT_SET, - documents: Union[List[Any], "NotSet"] = NOT_SET, - id: Union[str, "NotSet"] = NOT_SET, - index: Union[str, "NotSet"] = NOT_SET, - name: Union[str, "NotSet"] = NOT_SET, - preference: Union[str, "NotSet"] = NOT_SET, - routing: Union[str, "NotSet"] = NOT_SET, - version: Union[int, "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + document: Any = DEFAULT, + documents: Union[List[Any], "DefaultType"] = DEFAULT, + id: Union[str, "DefaultType"] = DEFAULT, + index: Union[str, "DefaultType"] = DEFAULT, + name: Union[str, "DefaultType"] = DEFAULT, + preference: Union[str, "DefaultType"] = DEFAULT, + routing: Union[str, "DefaultType"] = DEFAULT, + version: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1370,9 +1378,9 @@ class Pinned(Query): def __init__( self, *, - organic: Union[Query, "NotSet"] = NOT_SET, - ids: Union[List[str], "NotSet"] = NOT_SET, - docs: Union[List["i.PinnedDoc"], Dict[str, Any], "NotSet"] = NOT_SET, + organic: Union[Query, "DefaultType"] = DEFAULT, + ids: Union[List[str], "DefaultType"] = DEFAULT, + docs: Union[List["i.PinnedDoc"], Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(organic=organic, ids=ids, docs=docs, **kwargs) @@ -1390,11 +1398,11 @@ class Prefix(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.PrefixQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.PrefixQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1460,30 +1468,30 @@ class QueryString(Query): def __init__( self, *, - query: Union[str, "NotSet"] = NOT_SET, - allow_leading_wildcard: Union[bool, "NotSet"] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, - analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - default_field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - enable_position_increments: Union[bool, "NotSet"] = NOT_SET, - escape: Union[bool, "NotSet"] = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - fuzziness: Union[str, int, "NotSet"] = NOT_SET, - fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, - fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, - fuzzy_rewrite: Union[str, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, - max_determinized_states: Union[int, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - phrase_slop: Union[float, "NotSet"] = NOT_SET, - quote_analyzer: Union[str, "NotSet"] = NOT_SET, - quote_field_suffix: Union[str, "NotSet"] = NOT_SET, - rewrite: Union[str, "NotSet"] = NOT_SET, - tie_breaker: Union[float, "NotSet"] = NOT_SET, - time_zone: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "DefaultType"] = DEFAULT, + allow_leading_wildcard: Union[bool, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, + analyze_wildcard: Union[bool, "DefaultType"] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, + default_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + default_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + enable_position_increments: Union[bool, "DefaultType"] = DEFAULT, + escape: Union[bool, "DefaultType"] = DEFAULT, + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + fuzziness: Union[str, int, "DefaultType"] = DEFAULT, + fuzzy_max_expansions: Union[int, "DefaultType"] = DEFAULT, + fuzzy_prefix_length: Union[int, "DefaultType"] = DEFAULT, + fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, + fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, + lenient: Union[bool, "DefaultType"] = DEFAULT, + max_determinized_states: Union[int, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + phrase_slop: Union[float, "DefaultType"] = DEFAULT, + quote_analyzer: Union[str, "DefaultType"] = DEFAULT, + quote_field_suffix: Union[str, "DefaultType"] = DEFAULT, + rewrite: Union[str, "DefaultType"] = DEFAULT, + tie_breaker: Union[float, "DefaultType"] = DEFAULT, + time_zone: Union[str, "DefaultType"] = DEFAULT, type: Union[ Literal[ "best_fields", @@ -1493,8 +1501,8 @@ def __init__( "phrase_prefix", "bool_prefix", ], - "NotSet", - ] = NOT_SET, + "DefaultType", + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1539,11 +1547,11 @@ class Range(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["wrappers.Range[Any]", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["wrappers.Range[Any]", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1570,19 +1578,19 @@ class RankFeature(Query): def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, saturation: Union[ - "i.RankFeatureFunctionSaturation", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.RankFeatureFunctionSaturation", Dict[str, Any], "DefaultType" + ] = DEFAULT, log: Union[ - "i.RankFeatureFunctionLogarithm", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.RankFeatureFunctionLogarithm", Dict[str, Any], "DefaultType" + ] = DEFAULT, linear: Union[ - "i.RankFeatureFunctionLinear", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.RankFeatureFunctionLinear", Dict[str, Any], "DefaultType" + ] = DEFAULT, sigmoid: Union[ - "i.RankFeatureFunctionSigmoid", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.RankFeatureFunctionSigmoid", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1607,11 +1615,11 @@ class Regexp(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.RegexpQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.RegexpQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1633,9 +1641,9 @@ class Rule(Query): def __init__( self, *, - ruleset_ids: Union[List[str], "NotSet"] = NOT_SET, - match_criteria: Any = NOT_SET, - organic: Union[Query, "NotSet"] = NOT_SET, + ruleset_ids: Union[List[str], "DefaultType"] = DEFAULT, + match_criteria: Any = DEFAULT, + organic: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1660,7 +1668,7 @@ class Script(Query): def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, + script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(script=script, **kwargs) @@ -1686,9 +1694,9 @@ class ScriptScore(Query): def __init__( self, *, - query: Union[Query, "NotSet"] = NOT_SET, - script: Union["i.Script", Dict[str, Any], "NotSet"] = NOT_SET, - min_score: Union[float, "NotSet"] = NOT_SET, + query: Union[Query, "DefaultType"] = DEFAULT, + script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + min_score: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(query=query, script=script, min_score=min_score, **kwargs) @@ -1708,8 +1716,8 @@ class Semantic(Query): def __init__( self, *, - query: Union[str, "NotSet"] = NOT_SET, - field: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "DefaultType"] = DEFAULT, + field: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(query=query, field=field, **kwargs) @@ -1726,7 +1734,7 @@ class Shape(Query): name = "shape" def __init__( - self, *, ignore_unmapped: Union[bool, "NotSet"] = NOT_SET, **kwargs: Any + self, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any ): super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) @@ -1773,19 +1781,19 @@ class SimpleQueryString(Query): def __init__( self, *, - query: Union[str, "NotSet"] = NOT_SET, - analyzer: Union[str, "NotSet"] = NOT_SET, - analyze_wildcard: Union[bool, "NotSet"] = NOT_SET, - auto_generate_synonyms_phrase_query: Union[bool, "NotSet"] = NOT_SET, - default_operator: Union[Literal["and", "or"], "NotSet"] = NOT_SET, - fields: Union[List[Union[str, "InstrumentedField"]], "NotSet"] = NOT_SET, - flags: Union["i.PipeSeparatedFlags", Dict[str, Any], "NotSet"] = NOT_SET, - fuzzy_max_expansions: Union[int, "NotSet"] = NOT_SET, - fuzzy_prefix_length: Union[int, "NotSet"] = NOT_SET, - fuzzy_transpositions: Union[bool, "NotSet"] = NOT_SET, - lenient: Union[bool, "NotSet"] = NOT_SET, - minimum_should_match: Union[int, str, "NotSet"] = NOT_SET, - quote_field_suffix: Union[str, "NotSet"] = NOT_SET, + query: Union[str, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, + analyze_wildcard: Union[bool, "DefaultType"] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, + default_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, + fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + flags: Union["i.PipeSeparatedFlags", Dict[str, Any], "DefaultType"] = DEFAULT, + fuzzy_max_expansions: Union[int, "DefaultType"] = DEFAULT, + fuzzy_prefix_length: Union[int, "DefaultType"] = DEFAULT, + fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, + lenient: Union[bool, "DefaultType"] = DEFAULT, + minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, + quote_field_suffix: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1821,8 +1829,8 @@ class SpanContaining(Query): def __init__( self, *, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(little=little, big=big, **kwargs) @@ -1842,8 +1850,8 @@ class SpanFieldMasking(Query): def __init__( self, *, - query: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, + query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(query=query, field=field, **kwargs) @@ -1863,8 +1871,8 @@ class SpanFirst(Query): def __init__( self, *, - match: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - end: Union[int, "NotSet"] = NOT_SET, + match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + end: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(match=match, end=end, **kwargs) @@ -1885,7 +1893,7 @@ class SpanMulti(Query): "match": {"type": "query"}, } - def __init__(self, *, match: Union[Query, "NotSet"] = NOT_SET, **kwargs: Any): + def __init__(self, *, match: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): super().__init__(match=match, **kwargs) @@ -1906,9 +1914,9 @@ class SpanNear(Query): def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, - in_order: Union[bool, "NotSet"] = NOT_SET, - slop: Union[int, "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + in_order: Union[bool, "DefaultType"] = DEFAULT, + slop: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(clauses=clauses, in_order=in_order, slop=slop, **kwargs) @@ -1937,11 +1945,11 @@ class SpanNot(Query): def __init__( self, *, - exclude: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - include: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - dist: Union[int, "NotSet"] = NOT_SET, - post: Union[int, "NotSet"] = NOT_SET, - pre: Union[int, "NotSet"] = NOT_SET, + exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + dist: Union[int, "DefaultType"] = DEFAULT, + post: Union[int, "DefaultType"] = DEFAULT, + pre: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1961,7 +1969,7 @@ class SpanOr(Query): def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "NotSet"] = NOT_SET, + clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(clauses=clauses, **kwargs) @@ -1979,11 +1987,11 @@ class SpanTerm(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.SpanTermQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.SpanTermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2003,8 +2011,8 @@ class SpanWithin(Query): def __init__( self, *, - little: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, - big: Union["i.SpanQuery", Dict[str, Any], "NotSet"] = NOT_SET, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__(little=little, big=big, **kwargs) @@ -2046,14 +2054,14 @@ class SparseVector(Query): def __init__( self, *, - field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - query_vector: Union[Mapping[str, float], "NotSet"] = NOT_SET, - inference_id: Union[str, "NotSet"] = NOT_SET, - query: Union[str, "NotSet"] = NOT_SET, - prune: Union[bool, "NotSet"] = NOT_SET, + field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + query_vector: Union[Mapping[str, float], "DefaultType"] = DEFAULT, + inference_id: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, + prune: Union[bool, "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "NotSet" - ] = NOT_SET, + "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -2081,11 +2089,11 @@ class Term(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TermQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.TermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2124,11 +2132,11 @@ class TermsSet(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TermsSetQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.TermsSetQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2147,11 +2155,11 @@ class TextExpansion(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.TextExpansionQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.TextExpansionQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2169,11 +2177,11 @@ class WeightedTokens(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.WeightedTokensQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.WeightedTokensQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2190,11 +2198,11 @@ class Wildcard(Query): def __init__( self, - _field: Union[str, "InstrumentedField", "NotSet"] = NOT_SET, - _value: Union["i.WildcardQuery", Dict[str, Any], "NotSet"] = NOT_SET, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.WildcardQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2209,7 +2217,7 @@ class Wrapper(Query): name = "wrapper" - def __init__(self, *, query: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): + def __init__(self, *, query: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): super().__init__(query=query, **kwargs) @@ -2222,5 +2230,5 @@ class Type(Query): name = "type" - def __init__(self, *, value: Union[str, "NotSet"] = NOT_SET, **kwargs: Any): + def __init__(self, *, value: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): super().__init__(value=value, **kwargs) diff --git a/elasticsearch_dsl/utils.py b/elasticsearch_dsl/utils.py index 18aba77c..3617589c 100644 --- a/elasticsearch_dsl/utils.py +++ b/elasticsearch_dsl/utils.py @@ -35,6 +35,7 @@ cast, ) +from elastic_transport.client_utils import DEFAULT from typing_extensions import Self, TypeAlias, TypeVar from .exceptions import UnknownDslObject, ValidationException @@ -97,13 +98,6 @@ def _recursive_to_dict(value: Any) -> Any: return value -class NotSet: - pass - - -NOT_SET = NotSet() - - class AttrList(Generic[_ValT]): def __init__( self, l: List[_ValT], obj_wrapper: Optional[Callable[[_ValT], Any]] = None @@ -336,7 +330,7 @@ def __init__(self, _expand__to_dot: Optional[bool] = None, **params: Any) -> Non _expand__to_dot = EXPAND__TO_DOT self._params: Dict[str, Any] = {} for pname, pvalue in params.items(): - if isinstance(pvalue, NotSet): + if pvalue == DEFAULT: continue # expand "__" to dots if "__" in pname and _expand__to_dot: diff --git a/utils/generator.py b/utils/generator.py index 4d613c23..c2859d76 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -63,11 +63,11 @@ def add_dict_type(type_): def add_not_set(type_): - """Add NotSet to a Python type hint.""" + """Add DefaultType to a Python type hint.""" if type_.startswith("Union["): - type_ = f'{type_[:-1]}, "NotSet"]' + type_ = f'{type_[:-1]}, "DefaultType"]' else: - type_ = f'Union[{type_}, "NotSet"]' + type_ = f'Union[{type_}, "DefaultType"]' return type_ diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index d178388c..8ec68bd7 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -16,9 +16,12 @@ # under the License. from typing import Any, Dict, List, Literal, Mapping, Union + +from elastic_transport.client_utils import DEFAULT, DefaultType + from elasticsearch_dsl.document_base import InstrumentedField from elasticsearch_dsl import function as f, interfaces as i, Query -from elasticsearch_dsl.utils import AttrDict, NotSet, NOT_SET +from elasticsearch_dsl.utils import AttrDict PipeSeparatedFlags = str @@ -41,12 +44,12 @@ class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endi self, *, {% for arg in k.args %} - {{ arg.name }}: {{ arg.type }} = NOT_SET, + {{ arg.name }}: {{ arg.type }} = DEFAULT, {% endfor %} **kwargs: Any ): {% for arg in k.args %} - if not isinstance({{ arg.name }}, NotSet): + if {{ arg.name }} != DEFAULT: {% if "InstrumentedField" in arg.type %} kwargs["{{ arg.name }}"] = str({{ arg.name }}) {% else %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index bf8899cb..4aa9bade 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -36,13 +36,16 @@ from typing import ( overload, ) +from elastic_transport.client_utils import DEFAULT + # 'SF' looks unused but the test suite assumes it's available # from this module so others are liable to do so as well. from .function import SF # noqa: F401 from .function import ScoreFunction -from .utils import DslBase, NotSet, NOT_SET +from .utils import DslBase if TYPE_CHECKING: + from elastic_transport.client_utils import DefaultType from .document_base import InstrumentedField from elasticsearch_dsl import interfaces as i, wrappers @@ -176,21 +179,21 @@ class {{ k.name }}({{ parent }}): *, {% endif %} {% for arg in k.args %} - {{ arg.name }}: {{ arg.type }} = NOT_SET, + {{ arg.name }}: {{ arg.type }} = DEFAULT, {% endfor %} **kwargs: Any ): {% if k.name == "FunctionScore" %} - if isinstance(functions, NotSet): + if functions == DEFAULT: functions = [] for name in ScoreFunction._classes: if name in kwargs: functions.append({name: kwargs.pop(name)}) # type: ignore {% elif k.is_single_field %} - if not isinstance(_field, NotSet): + if _field != DEFAULT: kwargs[str(_field)] = _value {% elif k.is_multi_field %} - if not isinstance(fields, NotSet): + if _fields != DEFAULT: for field, value in _fields.items(): kwargs[str(field)] = value {% endif %} From 81109e36d82b7140cb25aff7d2a5bf1652aed0dd Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 5 Sep 2024 16:47:07 +0100 Subject: [PATCH 12/27] include inherited properties in docstrings and constructors --- elasticsearch_dsl/faceted_search_base.py | 4 +- elasticsearch_dsl/interfaces.py | 1089 ++++++++++++++++++++-- elasticsearch_dsl/query.py | 714 ++++++++++++-- utils/generator.py | 134 ++- utils/templates/interfaces.py.tpl | 19 +- utils/templates/query.py.tpl | 14 +- 6 files changed, 1783 insertions(+), 191 deletions(-) diff --git a/elasticsearch_dsl/faceted_search_base.py b/elasticsearch_dsl/faceted_search_base.py index 7b370861..45e00a00 100644 --- a/elasticsearch_dsl/faceted_search_base.py +++ b/elasticsearch_dsl/faceted_search_base.py @@ -141,9 +141,7 @@ class TermsFacet(Facet[_R]): def add_filter(self, filter_values: List[FilterValueType]) -> Optional[Query]: """Create a terms filter instead of bool containing term filters.""" if filter_values: - return Terms( - _expand__to_dot=False, **{self._params["field"]: filter_values} - ) + return Terms(self._params["field"], filter_values, _expand__to_dot=False) return None diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index b9a3d58f..2c852fef 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -from typing import Any, Dict, List, Literal, Mapping, Union +from typing import Any, Dict, Literal, Mapping, Sequence, Union from elastic_transport.client_utils import DEFAULT, DefaultType @@ -63,6 +63,12 @@ class CommonTermsQuery(QueryBase): :arg low_freq_operator: No documentation available. :arg minimum_should_match: No documentation available. :arg query: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ analyzer: Union[str, "DefaultType"] @@ -71,6 +77,8 @@ class CommonTermsQuery(QueryBase): low_freq_operator: Union[Literal["and", "or"], "DefaultType"] minimum_should_match: Union[int, str, "DefaultType"] query: Union[str, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -81,6 +89,8 @@ def __init__( low_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, query: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer != DEFAULT: @@ -95,9 +105,46 @@ def __init__( kwargs["minimum_should_match"] = minimum_should_match if query != DEFAULT: kwargs["query"] = query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) +class CoordsGeoBounds(AttrDict[Any]): + """ + :arg top: (required) No documentation available. + :arg bottom: (required) No documentation available. + :arg left: (required) No documentation available. + :arg right: (required) No documentation available. + """ + + top: Union[float, "DefaultType"] + bottom: Union[float, "DefaultType"] + left: Union[float, "DefaultType"] + right: Union[float, "DefaultType"] + + def __init__( + self, + *, + top: Union[float, "DefaultType"] = DEFAULT, + bottom: Union[float, "DefaultType"] = DEFAULT, + left: Union[float, "DefaultType"] = DEFAULT, + right: Union[float, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if top != DEFAULT: + kwargs["top"] = top + if bottom != DEFAULT: + kwargs["bottom"] = bottom + if left != DEFAULT: + kwargs["left"] = left + if right != DEFAULT: + kwargs["right"] = right + super().__init__(kwargs) + + class FunctionScoreContainer(AttrDict[Any]): """ :arg exp: Function that scores a document with a exponential decay, @@ -175,6 +222,12 @@ class FuzzyQuery(QueryBase): two adjacent characters (for example `ab` to `ba`). :arg fuzziness: Maximum edit distance allowed for matching. :arg value: (required) Term you wish to find in the provided field. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ max_expansions: Union[int, "DefaultType"] @@ -183,6 +236,8 @@ class FuzzyQuery(QueryBase): transpositions: Union[bool, "DefaultType"] fuzziness: Union[str, int, "DefaultType"] value: Union[str, float, bool, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -193,6 +248,8 @@ def __init__( transpositions: Union[bool, "DefaultType"] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, value: Union[str, float, bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if max_expansions != DEFAULT: @@ -207,9 +264,89 @@ def __init__( kwargs["fuzziness"] = fuzziness if value != DEFAULT: kwargs["value"] = value + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) +class GeoHashLocation(AttrDict[Any]): + """ + :arg geohash: (required) No documentation available. + """ + + geohash: Union[str, "DefaultType"] + + def __init__(self, *, geohash: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + if geohash != DEFAULT: + kwargs["geohash"] = geohash + super().__init__(kwargs) + + +class GeoPolygonPoints(AttrDict[Any]): + """ + :arg points: (required) No documentation available. + """ + + points: Union[ + Sequence[ + Union["i.LatLonGeoLocation", "i.GeoHashLocation", Sequence[float], str] + ], + Dict[str, Any], + "DefaultType", + ] + + def __init__( + self, + *, + points: Union[ + Sequence[ + Union["i.LatLonGeoLocation", "i.GeoHashLocation", Sequence[float], str] + ], + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + **kwargs: Any, + ): + if points != DEFAULT: + kwargs["points"] = points + super().__init__(kwargs) + + +class GeoShapeFieldQuery(AttrDict[Any]): + """ + :arg shape: No documentation available. + :arg indexed_shape: Query using an indexed shape retrieved from the + the specified document and path. + :arg relation: Spatial relation operator used to search a geo field. + """ + + shape: Any + indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] + relation: Union[ + Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + ] + + def __init__( + self, + *, + shape: Any = DEFAULT, + indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] = DEFAULT, + relation: Union[ + Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + ] = DEFAULT, + **kwargs: Any, + ): + if shape != DEFAULT: + kwargs["shape"] = shape + if indexed_shape != DEFAULT: + kwargs["indexed_shape"] = indexed_shape + if relation != DEFAULT: + kwargs["relation"] = relation + super().__init__(kwargs) + + class InnerHits(AttrDict[Any]): """ :arg name: The name for the particular inner hit definition in the @@ -237,7 +374,7 @@ class InnerHits(AttrDict[Any]): size: Union[int, "DefaultType"] from_: Union[int, "DefaultType"] collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] - docvalue_fields: Union[List["i.FieldAndFormat"], Dict[str, Any], "DefaultType"] + docvalue_fields: Union[Sequence["i.FieldAndFormat"], Dict[str, Any], "DefaultType"] explain: Union[bool, "DefaultType"] highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] ignore_unmapped: Union[bool, "DefaultType"] @@ -249,19 +386,19 @@ class InnerHits(AttrDict[Any]): seq_no_primary_term: Union[bool, "DefaultType"] fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] sort: Union[ Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Sequence[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], Dict[str, Any], "DefaultType", ] _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] stored_fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] track_scores: Union[bool, "DefaultType"] @@ -275,7 +412,7 @@ def __init__( from_: Union[int, "DefaultType"] = DEFAULT, collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, docvalue_fields: Union[ - List["i.FieldAndFormat"], Dict[str, Any], "DefaultType" + Sequence["i.FieldAndFormat"], Dict[str, Any], "DefaultType" ] = DEFAULT, explain: Union[bool, "DefaultType"] = DEFAULT, highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT, @@ -288,19 +425,19 @@ def __init__( seq_no_primary_term: Union[bool, "DefaultType"] = DEFAULT, fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, sort: Union[ Union[Union[str, "InstrumentedField"], "i.SortOptions"], - List[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Sequence[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], Dict[str, Any], "DefaultType", ] = DEFAULT, _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] = DEFAULT, stored_fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, track_scores: Union[bool, "DefaultType"] = DEFAULT, @@ -352,6 +489,12 @@ class IntervalsQuery(QueryBase): :arg prefix: Matches terms that start with a specified set of characters. :arg wildcard: Matches terms using a wildcard pattern. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] @@ -360,6 +503,8 @@ class IntervalsQuery(QueryBase): match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -370,6 +515,8 @@ def __init__( match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if all_of != DEFAULT: @@ -384,9 +531,36 @@ def __init__( kwargs["prefix"] = prefix if wildcard != DEFAULT: kwargs["wildcard"] = wildcard + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) +class LatLonGeoLocation(AttrDict[Any]): + """ + :arg lat: (required) Latitude + :arg lon: (required) Longitude + """ + + lat: Union[float, "DefaultType"] + lon: Union[float, "DefaultType"] + + def __init__( + self, + *, + lat: Union[float, "DefaultType"] = DEFAULT, + lon: Union[float, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if lat != DEFAULT: + kwargs["lat"] = lat + if lon != DEFAULT: + kwargs["lon"] = lon + super().__init__(kwargs) + + class LikeDocument(AttrDict[Any]): """ :arg doc: A document not present in the index. @@ -400,7 +574,7 @@ class LikeDocument(AttrDict[Any]): """ doc: Any - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] + fields: Union[Sequence[Union[str, "InstrumentedField"]], "DefaultType"] _id: Union[str, "DefaultType"] _index: Union[str, "DefaultType"] per_field_analyzer: Union[ @@ -416,7 +590,9 @@ def __init__( self, *, doc: Any = DEFAULT, - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + fields: Union[ + Sequence[Union[str, "InstrumentedField"]], "DefaultType" + ] = DEFAULT, _id: Union[str, "DefaultType"] = DEFAULT, _index: Union[str, "DefaultType"] = DEFAULT, per_field_analyzer: Union[ @@ -475,6 +651,12 @@ class MatchBoolPrefixQuery(QueryBase): for all terms but the final term. :arg query: (required) Terms you wish to find in the provided field. The last term is used in a prefix query. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ analyzer: Union[str, "DefaultType"] @@ -486,6 +668,8 @@ class MatchBoolPrefixQuery(QueryBase): operator: Union[Literal["and", "or"], "DefaultType"] prefix_length: Union[int, "DefaultType"] query: Union[str, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -499,6 +683,8 @@ def __init__( operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, prefix_length: Union[int, "DefaultType"] = DEFAULT, query: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer != DEFAULT: @@ -519,6 +705,10 @@ def __init__( kwargs["prefix_length"] = prefix_length if query != DEFAULT: kwargs["query"] = query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -534,6 +724,12 @@ class MatchPhrasePrefixQuery(QueryBase): :arg zero_terms_query: Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a `stop` filter. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ analyzer: Union[str, "DefaultType"] @@ -541,6 +737,8 @@ class MatchPhrasePrefixQuery(QueryBase): query: Union[str, "DefaultType"] slop: Union[int, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -550,6 +748,8 @@ def __init__( query: Union[str, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer != DEFAULT: @@ -562,6 +762,10 @@ def __init__( kwargs["slop"] = slop if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -576,12 +780,20 @@ class MatchPhraseQuery(QueryBase): :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ analyzer: Union[str, "DefaultType"] query: Union[str, "DefaultType"] slop: Union[int, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -590,6 +802,8 @@ def __init__( query: Union[str, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer != DEFAULT: @@ -600,6 +814,10 @@ def __init__( kwargs["slop"] = slop if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -630,6 +848,12 @@ class MatchQuery(QueryBase): :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ analyzer: Union[str, "DefaultType"] @@ -645,6 +869,8 @@ class MatchQuery(QueryBase): prefix_length: Union[int, "DefaultType"] query: Union[str, float, bool, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -662,6 +888,8 @@ def __init__( prefix_length: Union[int, "DefaultType"] = DEFAULT, query: Union[str, float, bool, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer != DEFAULT: @@ -692,6 +920,10 @@ def __init__( kwargs["query"] = query if zero_terms_query != DEFAULT: kwargs["zero_terms_query"] = zero_terms_query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -727,11 +959,19 @@ class PrefixQuery(QueryBase): value with the indexed field values when set to `true`. Default is `false` which means the case sensitivity of matching depends on the underlying field’s mapping. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ rewrite: Union[str, "DefaultType"] value: Union[str, "DefaultType"] case_insensitive: Union[bool, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -739,6 +979,8 @@ def __init__( rewrite: Union[str, "DefaultType"] = DEFAULT, value: Union[str, "DefaultType"] = DEFAULT, case_insensitive: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if rewrite != DEFAULT: @@ -747,6 +989,10 @@ def __init__( kwargs["value"] = value if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -843,6 +1089,12 @@ class RegexpQuery(QueryBase): :arg rewrite: Method used to rewrite the query. :arg value: (required) Regular expression for terms you wish to find in the provided field. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ case_insensitive: Union[bool, "DefaultType"] @@ -850,6 +1102,8 @@ class RegexpQuery(QueryBase): max_determinized_states: Union[int, "DefaultType"] rewrite: Union[str, "DefaultType"] value: Union[str, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -859,6 +1113,8 @@ def __init__( max_determinized_states: Union[int, "DefaultType"] = DEFAULT, rewrite: Union[str, "DefaultType"] = DEFAULT, value: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if case_insensitive != DEFAULT: @@ -871,6 +1127,10 @@ def __init__( kwargs["rewrite"] = rewrite if value != DEFAULT: kwargs["value"] = value + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -916,6 +1176,40 @@ def __init__( super().__init__(kwargs) +class ShapeFieldQuery(AttrDict[Any]): + """ + :arg indexed_shape: Queries using a pre-indexed shape. + :arg relation: Spatial relation between the query shape and the + document shape. + :arg shape: Queries using an inline shape definition in GeoJSON or + Well Known Text (WKT) format. + """ + + indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] + relation: Union[ + Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + ] + shape: Any + + def __init__( + self, + *, + indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] = DEFAULT, + relation: Union[ + Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + ] = DEFAULT, + shape: Any = DEFAULT, + **kwargs: Any, + ): + if indexed_shape != DEFAULT: + kwargs["indexed_shape"] = indexed_shape + if relation != DEFAULT: + kwargs["relation"] = relation + if shape != DEFAULT: + kwargs["shape"] = shape + super().__init__(kwargs) + + class SpanQuery(AttrDict[Any]): """ :arg span_containing: Accepts a list of span queries, but only returns @@ -1011,13 +1305,32 @@ def __init__( class SpanTermQuery(QueryBase): """ :arg value: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ value: Union[str, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] - def __init__(self, *, value: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + def __init__( + self, + *, + value: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): if value != DEFAULT: kwargs["value"] = value + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1028,49 +1341,106 @@ class TermQuery(QueryBase): value with the indexed field values when set to `true`. When `false`, the case sensitivity of matching depends on the underlying field’s mapping. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ value: Union[int, float, str, bool, None, Any, "DefaultType"] case_insensitive: Union[bool, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, value: Union[int, float, str, bool, None, Any, "DefaultType"] = DEFAULT, case_insensitive: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if value != DEFAULT: kwargs["value"] = value if case_insensitive != DEFAULT: kwargs["case_insensitive"] = case_insensitive + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) -class TermsSetQuery(QueryBase): +class TermsLookup(AttrDict[Any]): """ - :arg minimum_should_match_field: Numeric field containing the number - of matching terms required to return a document. - :arg minimum_should_match_script: Custom script containing the number - of matching terms required to return a document. - :arg terms: (required) Array of terms you wish to find in the provided - field. + :arg index: (required) No documentation available. + :arg id: (required) No documentation available. + :arg path: (required) No documentation available. + :arg routing: No documentation available. """ - minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] - minimum_should_match_script: Union["i.Script", Dict[str, Any], "DefaultType"] - terms: Union[List[str], "DefaultType"] + index: Union[str, "DefaultType"] + id: Union[str, "DefaultType"] + path: Union[str, "InstrumentedField", "DefaultType"] + routing: Union[str, "DefaultType"] def __init__( self, *, - minimum_should_match_field: Union[ - str, "InstrumentedField", "DefaultType" - ] = DEFAULT, + index: Union[str, "DefaultType"] = DEFAULT, + id: Union[str, "DefaultType"] = DEFAULT, + path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + routing: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if index != DEFAULT: + kwargs["index"] = index + if id != DEFAULT: + kwargs["id"] = id + if path != DEFAULT: + kwargs["path"] = str(path) + if routing != DEFAULT: + kwargs["routing"] = routing + super().__init__(kwargs) + + +class TermsSetQuery(QueryBase): + """ + :arg minimum_should_match_field: Numeric field containing the number + of matching terms required to return a document. + :arg minimum_should_match_script: Custom script containing the number + of matching terms required to return a document. + :arg terms: (required) Array of terms you wish to find in the provided + field. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. + """ + + minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] + minimum_should_match_script: Union["i.Script", Dict[str, Any], "DefaultType"] + terms: Union[Sequence[str], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] + + def __init__( + self, + *, + minimum_should_match_field: Union[ + str, "InstrumentedField", "DefaultType" + ] = DEFAULT, minimum_should_match_script: Union[ "i.Script", Dict[str, Any], "DefaultType" ] = DEFAULT, - terms: Union[List[str], "DefaultType"] = DEFAULT, + terms: Union[Sequence[str], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if minimum_should_match_field != DEFAULT: @@ -1079,6 +1449,10 @@ def __init__( kwargs["minimum_should_match_script"] = minimum_should_match_script if terms != DEFAULT: kwargs["terms"] = terms + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1087,11 +1461,19 @@ class TextExpansionQuery(QueryBase): :arg model_id: (required) The text expansion NLP model to use :arg model_text: (required) The query text :arg pruning_config: Token pruning configurations + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ model_id: Union[str, "DefaultType"] model_text: Union[str, "DefaultType"] pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -1101,6 +1483,8 @@ def __init__( pruning_config: Union[ "i.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if model_id != DEFAULT: @@ -1109,6 +1493,10 @@ def __init__( kwargs["model_text"] = model_text if pruning_config != DEFAULT: kwargs["pruning_config"] = pruning_config + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1144,14 +1532,124 @@ def __init__( super().__init__(kwargs) +class TopLeftBottomRightGeoBounds(AttrDict[Any]): + """ + :arg top_left: (required) No documentation available. + :arg bottom_right: (required) No documentation available. + """ + + top_left: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] + bottom_right: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] + + def __init__( + self, + *, + top_left: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + bottom_right: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + **kwargs: Any, + ): + if top_left != DEFAULT: + kwargs["top_left"] = top_left + if bottom_right != DEFAULT: + kwargs["bottom_right"] = bottom_right + super().__init__(kwargs) + + +class TopRightBottomLeftGeoBounds(AttrDict[Any]): + """ + :arg top_right: (required) No documentation available. + :arg bottom_left: (required) No documentation available. + """ + + top_right: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] + bottom_left: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] + + def __init__( + self, + *, + top_right: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + bottom_left: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + **kwargs: Any, + ): + if top_right != DEFAULT: + kwargs["top_right"] = top_right + if bottom_left != DEFAULT: + kwargs["bottom_left"] = bottom_left + super().__init__(kwargs) + + class WeightedTokensQuery(QueryBase): """ :arg tokens: (required) The tokens representing this query :arg pruning_config: Token pruning configurations + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ tokens: Union[Mapping[str, float], "DefaultType"] pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -1160,12 +1658,18 @@ def __init__( pruning_config: Union[ "i.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if tokens != DEFAULT: kwargs["tokens"] = tokens if pruning_config != DEFAULT: kwargs["pruning_config"] = pruning_config + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1180,12 +1684,20 @@ class WildcardQuery(QueryBase): provided field. Required, when wildcard is not set. :arg wildcard: Wildcard pattern for terms you wish to find in the provided field. Required, when value is not set. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ case_insensitive: Union[bool, "DefaultType"] rewrite: Union[str, "DefaultType"] value: Union[str, "DefaultType"] wildcard: Union[str, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -1194,6 +1706,8 @@ def __init__( rewrite: Union[str, "DefaultType"] = DEFAULT, value: Union[str, "DefaultType"] = DEFAULT, wildcard: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if case_insensitive != DEFAULT: @@ -1204,9 +1718,59 @@ def __init__( kwargs["value"] = value if wildcard != DEFAULT: kwargs["wildcard"] = wildcard + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) +class WktGeoBounds(AttrDict[Any]): + """ + :arg wkt: (required) No documentation available. + """ + + wkt: Union[str, "DefaultType"] + + def __init__(self, *, wkt: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + if wkt != DEFAULT: + kwargs["wkt"] = wkt + super().__init__(kwargs) + + +class FieldLookup(AttrDict[Any]): + """ + :arg id: (required) `id` of the document. + :arg index: Index from which to retrieve the document. + :arg path: Name of the field. + :arg routing: Custom routing value. + """ + + id: Union[str, "DefaultType"] + index: Union[str, "DefaultType"] + path: Union[str, "InstrumentedField", "DefaultType"] + routing: Union[str, "DefaultType"] + + def __init__( + self, + *, + id: Union[str, "DefaultType"] = DEFAULT, + index: Union[str, "DefaultType"] = DEFAULT, + path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + routing: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if id != DEFAULT: + kwargs["id"] = id + if index != DEFAULT: + kwargs["index"] = index + if path != DEFAULT: + kwargs["path"] = str(path) + if routing != DEFAULT: + kwargs["routing"] = routing + super().__init__(kwargs) + + class FieldCollapse(AttrDict[Any]): """ :arg field: (required) The field to collapse the result set on @@ -1217,7 +1781,9 @@ class FieldCollapse(AttrDict[Any]): """ field: Union[str, "InstrumentedField", "DefaultType"] - inner_hits: Union["i.InnerHits", List["i.InnerHits"], Dict[str, Any], "DefaultType"] + inner_hits: Union[ + "i.InnerHits", Sequence["i.InnerHits"], Dict[str, Any], "DefaultType" + ] max_concurrent_group_searches: Union[int, "DefaultType"] collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] @@ -1226,7 +1792,7 @@ def __init__( *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, inner_hits: Union[ - "i.InnerHits", List["i.InnerHits"], Dict[str, Any], "DefaultType" + "i.InnerHits", Sequence["i.InnerHits"], Dict[str, Any], "DefaultType" ] = DEFAULT, max_concurrent_group_searches: Union[int, "DefaultType"] = DEFAULT, collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, @@ -1352,8 +1918,8 @@ class HighlightBase(AttrDict[Any]): options: Union[Mapping[str, Any], "DefaultType"] order: Union[Literal["score"], "DefaultType"] phrase_limit: Union[int, "DefaultType"] - post_tags: Union[List[str], "DefaultType"] - pre_tags: Union[List[str], "DefaultType"] + post_tags: Union[Sequence[str], "DefaultType"] + pre_tags: Union[Sequence[str], "DefaultType"] require_field_match: Union[bool, "DefaultType"] tags_schema: Union[Literal["styled"], "DefaultType"] @@ -1379,8 +1945,8 @@ def __init__( options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, order: Union[Literal["score"], "DefaultType"] = DEFAULT, phrase_limit: Union[int, "DefaultType"] = DEFAULT, - post_tags: Union[List[str], "DefaultType"] = DEFAULT, - pre_tags: Union[List[str], "DefaultType"] = DEFAULT, + post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, + pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, require_field_match: Union[bool, "DefaultType"] = DEFAULT, tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, @@ -1434,6 +2000,65 @@ class Highlight(HighlightBase): """ :arg encoder: No documentation available. :arg fields: (required) No documentation available. + :arg type: No documentation available. + :arg boundary_chars: A string that contains each boundary character. + :arg boundary_max_scan: How far to scan for boundary characters. + :arg boundary_scanner: Specifies how to break the highlighted + fragments: chars, sentence, or word. Only valid for the unified + and fvh highlighters. Defaults to `sentence` for the `unified` + highlighter. Defaults to `chars` for the `fvh` highlighter. + :arg boundary_scanner_locale: Controls which locale is used to search + for sentence and word boundaries. This parameter takes a form of a + language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + :arg force_source: No documentation available. + :arg fragmenter: Specifies how text should be broken up in highlight + snippets: `simple` or `span`. Only valid for the `plain` + highlighter. + :arg fragment_size: The size of the highlighted fragment in + characters. + :arg highlight_filter: No documentation available. + :arg highlight_query: Highlight matches for a query other than the + search query. This is especially useful if you use a rescore query + because those are not taken into account by highlighting by + default. + :arg max_fragment_length: No documentation available. + :arg max_analyzed_offset: If set to a non-negative value, highlighting + stops at this defined maximum limit. The rest of the text is not + processed, thus not highlighted and no error is returned The + `max_analyzed_offset` query setting does not override the + `index.highlight.max_analyzed_offset` setting, which prevails when + it’s set to lower value than the query setting. + :arg no_match_size: The amount of text you want to return from the + beginning of the field if there are no matching fragments to + highlight. + :arg number_of_fragments: The maximum number of fragments to return. + If the number of fragments is set to `0`, no fragments are + returned. Instead, the entire field contents are highlighted and + returned. This can be handy when you need to highlight short texts + such as a title or address, but fragmentation is not required. If + `number_of_fragments` is `0`, `fragment_size` is ignored. + :arg options: No documentation available. + :arg order: Sorts highlighted fragments by score when set to `score`. + By default, fragments will be output in the order they appear in + the field (order: `none`). Setting this option to `score` will + output the most relevant fragments first. Each highlighter applies + its own logic to compute relevancy scores. + :arg phrase_limit: Controls the number of matching phrases in a + document that are considered. Prevents the `fvh` highlighter from + analyzing too many phrases and consuming too much memory. When + using `matched_fields`, `phrase_limit` phrases per matched field + are considered. Raising the limit increases query time and + consumes more memory. Only supported by the `fvh` highlighter. + :arg post_tags: Use in conjunction with `pre_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg pre_tags: Use in conjunction with `post_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg require_field_match: By default, only fields that contains a + query match are highlighted. Set to `false` to highlight all + fields. + :arg tags_schema: Set to `styled` to use the built-in tag schema. """ encoder: Union[Literal["default", "html"], "DefaultType"] @@ -1442,6 +2067,27 @@ class Highlight(HighlightBase): Dict[str, Any], "DefaultType", ] + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] + boundary_chars: Union[str, "DefaultType"] + boundary_max_scan: Union[int, "DefaultType"] + boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] + boundary_scanner_locale: Union[str, "DefaultType"] + force_source: Union[bool, "DefaultType"] + fragmenter: Union[Literal["simple", "span"], "DefaultType"] + fragment_size: Union[int, "DefaultType"] + highlight_filter: Union[bool, "DefaultType"] + highlight_query: Union[Query, "DefaultType"] + max_fragment_length: Union[int, "DefaultType"] + max_analyzed_offset: Union[int, "DefaultType"] + no_match_size: Union[int, "DefaultType"] + number_of_fragments: Union[int, "DefaultType"] + options: Union[Mapping[str, Any], "DefaultType"] + order: Union[Literal["score"], "DefaultType"] + phrase_limit: Union[int, "DefaultType"] + post_tags: Union[Sequence[str], "DefaultType"] + pre_tags: Union[Sequence[str], "DefaultType"] + require_field_match: Union[bool, "DefaultType"] + tags_schema: Union[Literal["styled"], "DefaultType"] def __init__( self, @@ -1452,15 +2098,80 @@ def __init__( Dict[str, Any], "DefaultType", ] = DEFAULT, - **kwargs: Any, - ): - if encoder != DEFAULT: - kwargs["encoder"] = encoder - if fields != DEFAULT: - kwargs["fields"] = str(fields) - super().__init__(**kwargs) - - + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, + boundary_chars: Union[str, "DefaultType"] = DEFAULT, + boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, + boundary_scanner: Union[ + Literal["chars", "sentence", "word"], "DefaultType" + ] = DEFAULT, + boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, + force_source: Union[bool, "DefaultType"] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, + fragment_size: Union[int, "DefaultType"] = DEFAULT, + highlight_filter: Union[bool, "DefaultType"] = DEFAULT, + highlight_query: Union[Query, "DefaultType"] = DEFAULT, + max_fragment_length: Union[int, "DefaultType"] = DEFAULT, + max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, + no_match_size: Union[int, "DefaultType"] = DEFAULT, + number_of_fragments: Union[int, "DefaultType"] = DEFAULT, + options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, + order: Union[Literal["score"], "DefaultType"] = DEFAULT, + phrase_limit: Union[int, "DefaultType"] = DEFAULT, + post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, + pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, + require_field_match: Union[bool, "DefaultType"] = DEFAULT, + tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if encoder != DEFAULT: + kwargs["encoder"] = encoder + if fields != DEFAULT: + kwargs["fields"] = str(fields) + if type != DEFAULT: + kwargs["type"] = type + if boundary_chars != DEFAULT: + kwargs["boundary_chars"] = boundary_chars + if boundary_max_scan != DEFAULT: + kwargs["boundary_max_scan"] = boundary_max_scan + if boundary_scanner != DEFAULT: + kwargs["boundary_scanner"] = boundary_scanner + if boundary_scanner_locale != DEFAULT: + kwargs["boundary_scanner_locale"] = boundary_scanner_locale + if force_source != DEFAULT: + kwargs["force_source"] = force_source + if fragmenter != DEFAULT: + kwargs["fragmenter"] = fragmenter + if fragment_size != DEFAULT: + kwargs["fragment_size"] = fragment_size + if highlight_filter != DEFAULT: + kwargs["highlight_filter"] = highlight_filter + if highlight_query != DEFAULT: + kwargs["highlight_query"] = highlight_query + if max_fragment_length != DEFAULT: + kwargs["max_fragment_length"] = max_fragment_length + if max_analyzed_offset != DEFAULT: + kwargs["max_analyzed_offset"] = max_analyzed_offset + if no_match_size != DEFAULT: + kwargs["no_match_size"] = no_match_size + if number_of_fragments != DEFAULT: + kwargs["number_of_fragments"] = number_of_fragments + if options != DEFAULT: + kwargs["options"] = options + if order != DEFAULT: + kwargs["order"] = order + if phrase_limit != DEFAULT: + kwargs["phrase_limit"] = phrase_limit + if post_tags != DEFAULT: + kwargs["post_tags"] = post_tags + if pre_tags != DEFAULT: + kwargs["pre_tags"] = pre_tags + if require_field_match != DEFAULT: + kwargs["require_field_match"] = require_field_match + if tags_schema != DEFAULT: + kwargs["tags_schema"] = tags_schema + super().__init__(**kwargs) + + class ScriptField(AttrDict[Any]): """ :arg script: (required) No documentation available. @@ -1527,12 +2238,12 @@ class SourceFilter(AttrDict[Any]): excludes: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] includes: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] @@ -1541,12 +2252,12 @@ def __init__( *, excludes: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, includes: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, **kwargs: Any, @@ -1571,7 +2282,7 @@ class IntervalsAllOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] + intervals: Union[Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] max_gaps: Union[int, "DefaultType"] ordered: Union[bool, "DefaultType"] filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] @@ -1580,7 +2291,7 @@ def __init__( self, *, intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, max_gaps: Union[int, "DefaultType"] = DEFAULT, ordered: Union[bool, "DefaultType"] = DEFAULT, @@ -1604,14 +2315,14 @@ class IntervalsAnyOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[List["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] + intervals: Union[Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, intervals: Union[ - List["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, @@ -1812,22 +2523,36 @@ class SpanContainingQuery(QueryBase): that contain matches from `little` are returned. :arg little: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if big != DEFAULT: kwargs["big"] = big if little != DEFAULT: kwargs["little"] = little + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1835,22 +2560,36 @@ class SpanFieldMaskingQuery(QueryBase): """ :arg field: (required) No documentation available. :arg query: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ field: Union[str, "InstrumentedField", "DefaultType"] query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if field != DEFAULT: kwargs["field"] = str(field) if query != DEFAULT: kwargs["query"] = query + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1859,22 +2598,36 @@ class SpanFirstQuery(QueryBase): :arg end: (required) Controls the maximum end position permitted in a match. :arg match: (required) Can be any other span type query. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ end: Union[int, "DefaultType"] match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, end: Union[int, "DefaultType"] = DEFAULT, match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if end != DEFAULT: kwargs["end"] = end if match != DEFAULT: kwargs["match"] = match + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1882,13 +2635,32 @@ class SpanMultiTermQuery(QueryBase): """ :arg match: (required) Should be a multi term query (one of `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ match: Union[Query, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] - def __init__(self, *, match: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): + def __init__( + self, + *, + match: Union[Query, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): if match != DEFAULT: kwargs["match"] = match + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1898,18 +2670,30 @@ class SpanNearQuery(QueryBase): :arg in_order: Controls whether matches are required to be in-order. :arg slop: Controls the maximum number of intervening unmatched positions permitted. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] + clauses: Union[Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType"] in_order: Union[bool, "DefaultType"] slop: Union[int, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + clauses: Union[ + Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + ] = DEFAULT, in_order: Union[bool, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if clauses != DEFAULT: @@ -1918,6 +2702,10 @@ def __init__( kwargs["in_order"] = in_order if slop != DEFAULT: kwargs["slop"] = slop + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1933,6 +2721,12 @@ class SpanNotQuery(QueryBase): overlap with the exclude span. :arg pre: The number of tokens before the include span that can’t have overlap with the exclude span. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ dist: Union[int, "DefaultType"] @@ -1940,6 +2734,8 @@ class SpanNotQuery(QueryBase): include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] post: Union[int, "DefaultType"] pre: Union[int, "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, @@ -1949,6 +2745,8 @@ def __init__( include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, post: Union[int, "DefaultType"] = DEFAULT, pre: Union[int, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if dist != DEFAULT: @@ -1961,24 +2759,44 @@ def __init__( kwargs["post"] = post if pre != DEFAULT: kwargs["pre"] = pre + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) class SpanOrQuery(QueryBase): """ :arg clauses: (required) Array of one or more other span type queries. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] + clauses: Union[Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + clauses: Union[ + Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if clauses != DEFAULT: kwargs["clauses"] = clauses + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -1988,22 +2806,36 @@ class SpanWithinQuery(QueryBase): `little` that are enclosed within `big` are returned. :arg little: (required) Can be any span query. Matching spans from `little` that are enclosed within `big` are returned. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + boost: Union[float, "DefaultType"] + _name: Union[str, "DefaultType"] def __init__( self, *, big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if big != DEFAULT: kwargs["big"] = big if little != DEFAULT: kwargs["little"] = little + if boost != DEFAULT: + kwargs["boost"] = boost + if _name != DEFAULT: + kwargs["_name"] = _name super().__init__(**kwargs) @@ -2012,15 +2844,95 @@ class HighlightField(HighlightBase): :arg fragment_offset: No documentation available. :arg matched_fields: No documentation available. :arg analyzer: No documentation available. + :arg type: No documentation available. + :arg boundary_chars: A string that contains each boundary character. + :arg boundary_max_scan: How far to scan for boundary characters. + :arg boundary_scanner: Specifies how to break the highlighted + fragments: chars, sentence, or word. Only valid for the unified + and fvh highlighters. Defaults to `sentence` for the `unified` + highlighter. Defaults to `chars` for the `fvh` highlighter. + :arg boundary_scanner_locale: Controls which locale is used to search + for sentence and word boundaries. This parameter takes a form of a + language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + :arg force_source: No documentation available. + :arg fragmenter: Specifies how text should be broken up in highlight + snippets: `simple` or `span`. Only valid for the `plain` + highlighter. + :arg fragment_size: The size of the highlighted fragment in + characters. + :arg highlight_filter: No documentation available. + :arg highlight_query: Highlight matches for a query other than the + search query. This is especially useful if you use a rescore query + because those are not taken into account by highlighting by + default. + :arg max_fragment_length: No documentation available. + :arg max_analyzed_offset: If set to a non-negative value, highlighting + stops at this defined maximum limit. The rest of the text is not + processed, thus not highlighted and no error is returned The + `max_analyzed_offset` query setting does not override the + `index.highlight.max_analyzed_offset` setting, which prevails when + it’s set to lower value than the query setting. + :arg no_match_size: The amount of text you want to return from the + beginning of the field if there are no matching fragments to + highlight. + :arg number_of_fragments: The maximum number of fragments to return. + If the number of fragments is set to `0`, no fragments are + returned. Instead, the entire field contents are highlighted and + returned. This can be handy when you need to highlight short texts + such as a title or address, but fragmentation is not required. If + `number_of_fragments` is `0`, `fragment_size` is ignored. + :arg options: No documentation available. + :arg order: Sorts highlighted fragments by score when set to `score`. + By default, fragments will be output in the order they appear in + the field (order: `none`). Setting this option to `score` will + output the most relevant fragments first. Each highlighter applies + its own logic to compute relevancy scores. + :arg phrase_limit: Controls the number of matching phrases in a + document that are considered. Prevents the `fvh` highlighter from + analyzing too many phrases and consuming too much memory. When + using `matched_fields`, `phrase_limit` phrases per matched field + are considered. Raising the limit increases query time and + consumes more memory. Only supported by the `fvh` highlighter. + :arg post_tags: Use in conjunction with `pre_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg pre_tags: Use in conjunction with `post_tags` to define the HTML + tags to use for the highlighted text. By default, highlighted text + is wrapped in `` and `` tags. + :arg require_field_match: By default, only fields that contains a + query match are highlighted. Set to `false` to highlight all + fields. + :arg tags_schema: Set to `styled` to use the built-in tag schema. """ fragment_offset: Union[int, "DefaultType"] matched_fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] analyzer: Union[str, Dict[str, Any], "DefaultType"] + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] + boundary_chars: Union[str, "DefaultType"] + boundary_max_scan: Union[int, "DefaultType"] + boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] + boundary_scanner_locale: Union[str, "DefaultType"] + force_source: Union[bool, "DefaultType"] + fragmenter: Union[Literal["simple", "span"], "DefaultType"] + fragment_size: Union[int, "DefaultType"] + highlight_filter: Union[bool, "DefaultType"] + highlight_query: Union[Query, "DefaultType"] + max_fragment_length: Union[int, "DefaultType"] + max_analyzed_offset: Union[int, "DefaultType"] + no_match_size: Union[int, "DefaultType"] + number_of_fragments: Union[int, "DefaultType"] + options: Union[Mapping[str, Any], "DefaultType"] + order: Union[Literal["score"], "DefaultType"] + phrase_limit: Union[int, "DefaultType"] + post_tags: Union[Sequence[str], "DefaultType"] + pre_tags: Union[Sequence[str], "DefaultType"] + require_field_match: Union[bool, "DefaultType"] + tags_schema: Union[Literal["styled"], "DefaultType"] def __init__( self, @@ -2028,10 +2940,33 @@ def __init__( fragment_offset: Union[int, "DefaultType"] = DEFAULT, matched_fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, analyzer: Union[str, Dict[str, Any], "DefaultType"] = DEFAULT, + type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, + boundary_chars: Union[str, "DefaultType"] = DEFAULT, + boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, + boundary_scanner: Union[ + Literal["chars", "sentence", "word"], "DefaultType" + ] = DEFAULT, + boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, + force_source: Union[bool, "DefaultType"] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, + fragment_size: Union[int, "DefaultType"] = DEFAULT, + highlight_filter: Union[bool, "DefaultType"] = DEFAULT, + highlight_query: Union[Query, "DefaultType"] = DEFAULT, + max_fragment_length: Union[int, "DefaultType"] = DEFAULT, + max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, + no_match_size: Union[int, "DefaultType"] = DEFAULT, + number_of_fragments: Union[int, "DefaultType"] = DEFAULT, + options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, + order: Union[Literal["score"], "DefaultType"] = DEFAULT, + phrase_limit: Union[int, "DefaultType"] = DEFAULT, + post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, + pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, + require_field_match: Union[bool, "DefaultType"] = DEFAULT, + tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): if fragment_offset != DEFAULT: @@ -2040,6 +2975,48 @@ def __init__( kwargs["matched_fields"] = str(matched_fields) if analyzer != DEFAULT: kwargs["analyzer"] = analyzer + if type != DEFAULT: + kwargs["type"] = type + if boundary_chars != DEFAULT: + kwargs["boundary_chars"] = boundary_chars + if boundary_max_scan != DEFAULT: + kwargs["boundary_max_scan"] = boundary_max_scan + if boundary_scanner != DEFAULT: + kwargs["boundary_scanner"] = boundary_scanner + if boundary_scanner_locale != DEFAULT: + kwargs["boundary_scanner_locale"] = boundary_scanner_locale + if force_source != DEFAULT: + kwargs["force_source"] = force_source + if fragmenter != DEFAULT: + kwargs["fragmenter"] = fragmenter + if fragment_size != DEFAULT: + kwargs["fragment_size"] = fragment_size + if highlight_filter != DEFAULT: + kwargs["highlight_filter"] = highlight_filter + if highlight_query != DEFAULT: + kwargs["highlight_query"] = highlight_query + if max_fragment_length != DEFAULT: + kwargs["max_fragment_length"] = max_fragment_length + if max_analyzed_offset != DEFAULT: + kwargs["max_analyzed_offset"] = max_analyzed_offset + if no_match_size != DEFAULT: + kwargs["no_match_size"] = no_match_size + if number_of_fragments != DEFAULT: + kwargs["number_of_fragments"] = number_of_fragments + if options != DEFAULT: + kwargs["options"] = options + if order != DEFAULT: + kwargs["order"] = order + if phrase_limit != DEFAULT: + kwargs["phrase_limit"] = phrase_limit + if post_tags != DEFAULT: + kwargs["post_tags"] = post_tags + if pre_tags != DEFAULT: + kwargs["pre_tags"] = pre_tags + if require_field_match != DEFAULT: + kwargs["require_field_match"] = require_field_match + if tags_schema != DEFAULT: + kwargs["tags_schema"] = tags_schema super().__init__(**kwargs) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index cef0fab1..cb642a84 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -30,6 +30,7 @@ MutableMapping, Optional, Protocol, + Sequence, TypeVar, Union, cast, @@ -163,6 +164,12 @@ class Bool(Query): for all documents. :arg should: The clause (query) should appear in the matching document. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "bool" @@ -176,11 +183,13 @@ class Bool(Query): def __init__( self, *, - filter: Union[Query, List[Query], "DefaultType"] = DEFAULT, + filter: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT, minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, - must: Union[Query, List[Query], "DefaultType"] = DEFAULT, - must_not: Union[Query, List[Query], "DefaultType"] = DEFAULT, - should: Union[Query, List[Query], "DefaultType"] = DEFAULT, + must: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT, + must_not: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT, + should: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -189,6 +198,8 @@ def __init__( must=must, must_not=must_not, should=should, + boost=boost, + _name=_name, **kwargs, ) @@ -306,13 +317,19 @@ class Boosting(Query): Returns documents matching a `positive` query while reducing the relevance score of documents that also match a `negative` query. + :arg negative_boost: (required) Floating point number between 0 and + 1.0 used to decrease the relevance scores of documents matching + the `negative` query. :arg negative: (required) Query used to decrease the relevance score of matching documents. :arg positive: (required) Any returned documents must match this query. - :arg negative_boost: (required) Floating point number between 0 and - 1.0 used to decrease the relevance scores of documents matching - the `negative` query. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "boosting" @@ -324,15 +341,19 @@ class Boosting(Query): def __init__( self, *, + negative_boost: Union[float, "DefaultType"] = DEFAULT, negative: Union[Query, "DefaultType"] = DEFAULT, positive: Union[Query, "DefaultType"] = DEFAULT, - negative_boost: Union[float, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( + negative_boost=negative_boost, negative=negative, positive=positive, - negative_boost=negative_boost, + boost=boost, + _name=_name, **kwargs, ) @@ -363,12 +384,12 @@ class CombinedFields(Query): The `combined_fields` query supports searching multiple text fields as if their contents had been indexed into one combined field. - :arg query: (required) Text to search for in the provided `fields`. - The `combined_fields` query analyzes the provided text before - performing a search. :arg fields: (required) List of fields to search. Field wildcard patterns are allowed. Only `text` fields are supported, and they must all have the same search `analyzer`. + :arg query: (required) Text to search for in the provided `fields`. + The `combined_fields` query analyzes the provided text before + performing a search. :arg auto_generate_synonyms_phrase_query: If true, match phrase queries are automatically created for multi-term synonyms. :arg operator: Boolean logic used to interpret text in the query @@ -378,6 +399,12 @@ class CombinedFields(Query): :arg zero_terms_query: Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a `stop` filter. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "combined_fields" @@ -385,21 +412,27 @@ class CombinedFields(Query): def __init__( self, *, + fields: Union[ + Sequence[Union[str, "InstrumentedField"]], "DefaultType" + ] = DEFAULT, query: Union[str, "DefaultType"] = DEFAULT, - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, operator: Union[Literal["or", "and"], "DefaultType"] = DEFAULT, minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["none", "all"], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( - query=query, fields=fields, + query=query, auto_generate_synonyms_phrase_query=auto_generate_synonyms_phrase_query, operator=operator, minimum_should_match=minimum_should_match, zero_terms_query=zero_terms_query, + boost=boost, + _name=_name, **kwargs, ) @@ -413,6 +446,12 @@ class ConstantScore(Query): documents must match this query. Filter queries do not calculate relevance scores. To speed up performance, Elasticsearch automatically caches frequently used filter queries. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "constant_score" @@ -420,8 +459,15 @@ class ConstantScore(Query): "filter": {"type": "query"}, } - def __init__(self, *, filter: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): - super().__init__(filter=filter, **kwargs) + def __init__( + self, + *, + filter: Union[Query, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(filter=filter, boost=boost, _name=_name, **kwargs) class DisMax(Query): @@ -438,6 +484,12 @@ class DisMax(Query): :arg tie_breaker: Floating point number between 0 and 1.0 used to increase the relevance scores of documents matching multiple query clauses. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "dis_max" @@ -448,11 +500,15 @@ class DisMax(Query): def __init__( self, *, - queries: Union[List[Query], "DefaultType"] = DEFAULT, + queries: Union[Sequence[Query], "DefaultType"] = DEFAULT, tie_breaker: Union[float, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(queries=queries, tie_breaker=tie_breaker, **kwargs) + super().__init__( + queries=queries, tie_breaker=tie_breaker, boost=boost, _name=_name, **kwargs + ) class DistanceFeature(Query): @@ -461,6 +517,11 @@ class DistanceFeature(Query): date or point. For example, you can use this query to give more weight to documents closer to a certain date or location. + :arg origin: (required) Date or point of origin used to calculate + distances. If the `field` value is a `date` or `date_nanos` field, + the `origin` value must be a date. Date Math, such as `now-1h`, is + supported. If the field value is a `geo_point` field, the `origin` + value must be a geopoint. :arg pivot: (required) Distance from the `origin` at which relevance scores receive half of the `boost` value. If the `field` value is a `date` or `date_nanos` field, the `pivot` value must be a time @@ -473,11 +534,12 @@ class DistanceFeature(Query): parameter value of `true`, which is the default; have an `doc_values` mapping parameter value of `true`, which is the default. - :arg origin: (required) Date or point of origin used to calculate - distances. If the `field` value is a `date` or `date_nanos` field, - the `origin` value must be a date. Date Math, such as `now-1h`, is - supported. If the field value is a `geo_point` field, the `origin` - value must be a geopoint. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "distance_feature" @@ -485,12 +547,16 @@ class DistanceFeature(Query): def __init__( self, *, + origin: Any = DEFAULT, pivot: Any = DEFAULT, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - origin: Any = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(pivot=pivot, field=field, origin=origin, **kwargs) + super().__init__( + origin=origin, pivot=pivot, field=field, boost=boost, _name=_name, **kwargs + ) class Exists(Query): @@ -498,6 +564,12 @@ class Exists(Query): Returns documents that contain an indexed value for a field. :arg field: (required) Name of the field you wish to search. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "exists" @@ -506,9 +578,11 @@ def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(field=field, **kwargs) + super().__init__(field=field, boost=boost, _name=_name, **kwargs) class FunctionScore(Query): @@ -527,6 +601,12 @@ class FunctionScore(Query): :arg query: A query that determines the documents for which a new score is computed. :arg score_mode: Specifies how the computed scores are combined + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "function_score" @@ -543,7 +623,7 @@ def __init__( Literal["multiply", "replace", "sum", "avg", "max", "min"], "DefaultType" ] = DEFAULT, functions: Union[ - List["i.FunctionScoreContainer"], Dict[str, Any], "DefaultType" + Sequence["i.FunctionScoreContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, max_boost: Union[float, "DefaultType"] = DEFAULT, min_score: Union[float, "DefaultType"] = DEFAULT, @@ -551,6 +631,8 @@ def __init__( score_mode: Union[ Literal["multiply", "sum", "avg", "first", "max", "min"], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): if functions == DEFAULT: @@ -565,6 +647,8 @@ def __init__( min_score=min_score, query=query, score_mode=score_mode, + boost=boost, + _name=_name, **kwargs, ) @@ -595,6 +679,8 @@ class GeoBoundingBox(Query): """ Matches geo_point and geo_shape values that intersect a bounding box. + :arg _field: The field to use in this query. + :arg _value: The query value for the field. :arg type: No documentation available. :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude. Set to `COERCE` to also try to @@ -602,24 +688,45 @@ class GeoBoundingBox(Query): :arg ignore_unmapped: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "geo_bounding_box" def __init__( self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union[ + "i.CoordsGeoBounds", + "i.TopLeftBottomRightGeoBounds", + "i.TopRightBottomLeftGeoBounds", + "i.WktGeoBounds", + Dict[str, Any], + "DefaultType", + ] = DEFAULT, *, type: Union[Literal["memory", "indexed"], "DefaultType"] = DEFAULT, validation_method: Union[ Literal["coerce", "ignore_malformed", "strict"], "DefaultType" ] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if _field != DEFAULT: + kwargs[str(_field)] = _value super().__init__( type=type, validation_method=validation_method, ignore_unmapped=ignore_unmapped, + boost=boost, + _name=_name, **kwargs, ) @@ -629,6 +736,8 @@ class GeoDistance(Query): Matches `geo_point` and `geo_shape` values within a given distance of a geopoint. + :arg _field: The field to use in this query. + :arg _value: The query value for the field. :arg distance: (required) The radius of the circle centred on the specified location. Points which fall into this circle are considered to be matches. @@ -641,12 +750,27 @@ class GeoDistance(Query): :arg ignore_unmapped: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "geo_distance" def __init__( self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union[ + "i.LatLonGeoLocation", + "i.GeoHashLocation", + Sequence[float], + str, + Dict[str, Any], + "DefaultType", + ] = DEFAULT, *, distance: Union[str, "DefaultType"] = DEFAULT, distance_type: Union[Literal["arc", "plane"], "DefaultType"] = DEFAULT, @@ -654,13 +778,19 @@ def __init__( Literal["coerce", "ignore_malformed", "strict"], "DefaultType" ] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if _field != DEFAULT: + kwargs[str(_field)] = _value super().__init__( distance=distance, distance_type=distance_type, validation_method=validation_method, ignore_unmapped=ignore_unmapped, + boost=boost, + _name=_name, **kwargs, ) @@ -669,24 +799,40 @@ class GeoPolygon(Query): """ No documentation available. + :arg _field: The field to use in this query. + :arg _value: The query value for the field. :arg validation_method: No documentation available. :arg ignore_unmapped: No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "geo_polygon" def __init__( self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.GeoPolygonPoints", Dict[str, Any], "DefaultType"] = DEFAULT, *, validation_method: Union[ Literal["coerce", "ignore_malformed", "strict"], "DefaultType" ] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if _field != DEFAULT: + kwargs[str(_field)] = _value super().__init__( validation_method=validation_method, ignore_unmapped=ignore_unmapped, + boost=boost, + _name=_name, **kwargs, ) @@ -696,17 +842,36 @@ class GeoShape(Query): Filter documents indexed using either the `geo_shape` or the `geo_point` type. + :arg _field: The field to use in this query. + :arg _value: The query value for the field. :arg ignore_unmapped: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "geo_shape" def __init__( - self, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any + self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.GeoShapeFieldQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + *, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, ): - super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) + if _field != DEFAULT: + kwargs[str(_field)] = _value + super().__init__( + ignore_unmapped=ignore_unmapped, boost=boost, _name=_name, **kwargs + ) class HasChild(Query): @@ -732,6 +897,12 @@ class HasChild(Query): from the search results. :arg score_mode: Indicates how scores for matching child documents affect the root parent document’s relevance score. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "has_child" @@ -751,6 +922,8 @@ def __init__( score_mode: Union[ Literal["none", "avg", "sum", "max", "min"], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -761,6 +934,8 @@ def __init__( max_children=max_children, min_children=min_children, score_mode=score_mode, + boost=boost, + _name=_name, **kwargs, ) @@ -782,6 +957,12 @@ class HasParent(Query): :arg inner_hits: If defined, each search hit will contain inner hits. :arg score: Indicates whether the relevance score of a matching parent document is aggregated into its child documents. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "has_parent" @@ -797,6 +978,8 @@ def __init__( ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, score: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -805,6 +988,8 @@ def __init__( ignore_unmapped=ignore_unmapped, inner_hits=inner_hits, score=score, + boost=boost, + _name=_name, **kwargs, ) @@ -815,14 +1000,25 @@ class Ids(Query): stored in the `_id` field. :arg values: An array of document IDs. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "ids" def __init__( - self, *, values: Union[str, List[str], "DefaultType"] = DEFAULT, **kwargs: Any + self, + *, + values: Union[str, Sequence[str], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, ): - super().__init__(values=values, **kwargs) + super().__init__(values=values, boost=boost, _name=_name, **kwargs) class Intervals(Query): @@ -862,6 +1058,12 @@ class Knn(Query): :arg filter: Filters for the kNN search query :arg similarity: The minimum similarity for a vector to be considered a match + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "knn" @@ -873,14 +1075,16 @@ def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - query_vector: Union[List[float], "DefaultType"] = DEFAULT, + query_vector: Union[Sequence[float], "DefaultType"] = DEFAULT, query_vector_builder: Union[ "i.QueryVectorBuilder", Dict[str, Any], "DefaultType" ] = DEFAULT, num_candidates: Union[int, "DefaultType"] = DEFAULT, k: Union[int, "DefaultType"] = DEFAULT, - filter: Union[Query, List[Query], "DefaultType"] = DEFAULT, + filter: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT, similarity: Union[float, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -891,6 +1095,8 @@ def __init__( k=k, filter=filter, similarity=similarity, + boost=boost, + _name=_name, **kwargs, ) @@ -920,12 +1126,25 @@ def __init__( class MatchAll(Query): """ Matches all documents, giving them all a `_score` of 1.0. + + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "match_all" - def __init__(self, **kwargs: Any): - super().__init__(**kwargs) + def __init__( + self, + *, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(boost=boost, _name=_name, **kwargs) def __add__(self, other: "Query") -> "Query": return other._clone() @@ -972,12 +1191,25 @@ def __init__( class MatchNone(Query): """ Matches no documents. + + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "match_none" - def __init__(self, **kwargs: Any): - super().__init__(**kwargs) + def __init__( + self, + *, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(boost=boost, _name=_name, **kwargs) def __add__(self, other: "Query") -> "MatchNone": return self @@ -1081,6 +1313,12 @@ class MoreLikeThis(Query): match a set of terms. :arg version: No documentation available. :arg version_type: No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "more_like_this" @@ -1090,14 +1328,16 @@ def __init__( *, like: Union[ Union[str, "i.LikeDocument"], - List[Union[str, "i.LikeDocument"]], + Sequence[Union[str, "i.LikeDocument"]], Dict[str, Any], "DefaultType", ] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, boost_terms: Union[float, "DefaultType"] = DEFAULT, fail_on_unsupported_field: Union[bool, "DefaultType"] = DEFAULT, - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + fields: Union[ + Sequence[Union[str, "InstrumentedField"]], "DefaultType" + ] = DEFAULT, include: Union[bool, "DefaultType"] = DEFAULT, max_doc_freq: Union[int, "DefaultType"] = DEFAULT, max_query_terms: Union[int, "DefaultType"] = DEFAULT, @@ -1107,10 +1347,10 @@ def __init__( min_term_freq: Union[int, "DefaultType"] = DEFAULT, min_word_length: Union[int, "DefaultType"] = DEFAULT, routing: Union[str, "DefaultType"] = DEFAULT, - stop_words: Union[str, List[str], "DefaultType"] = DEFAULT, + stop_words: Union[str, Sequence[str], "DefaultType"] = DEFAULT, unlike: Union[ Union[str, "i.LikeDocument"], - List[Union[str, "i.LikeDocument"]], + Sequence[Union[str, "i.LikeDocument"]], Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -1118,6 +1358,8 @@ def __init__( version_type: Union[ Literal["internal", "external", "external_gte", "force"], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1139,6 +1381,8 @@ def __init__( unlike=unlike, version=version, version_type=version_type, + boost=boost, + _name=_name, **kwargs, ) @@ -1183,6 +1427,12 @@ class MultiMatch(Query): :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "multi_match" @@ -1196,7 +1446,7 @@ def __init__( cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, fields: Union[ Union[str, "InstrumentedField"], - List[Union[str, "InstrumentedField"]], + Sequence[Union[str, "InstrumentedField"]], "DefaultType", ] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, @@ -1221,6 +1471,8 @@ def __init__( "DefaultType", ] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1241,6 +1493,8 @@ def __init__( tie_breaker=tie_breaker, type=type, zero_terms_query=zero_terms_query, + boost=boost, + _name=_name, **kwargs, ) @@ -1258,6 +1512,12 @@ class Nested(Query): :arg inner_hits: If defined, each search hit will contain inner hits. :arg score_mode: How scores for matching child objects affect the root parent document’s relevance score. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "nested" @@ -1275,6 +1535,8 @@ def __init__( score_mode: Union[ Literal["none", "avg", "sum", "max", "min"], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1283,6 +1545,8 @@ def __init__( ignore_unmapped=ignore_unmapped, inner_hits=inner_hits, score_mode=score_mode, + boost=boost, + _name=_name, **kwargs, ) @@ -1295,6 +1559,12 @@ class ParentId(Query): :arg ignore_unmapped: Indicates whether to ignore an unmapped `type` and not return any documents instead of an error. :arg type: Name of the child relationship mapped for the `join` field. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "parent_id" @@ -1305,9 +1575,18 @@ def __init__( id: Union[str, "DefaultType"] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, type: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(id=id, ignore_unmapped=ignore_unmapped, type=type, **kwargs) + super().__init__( + id=id, + ignore_unmapped=ignore_unmapped, + type=type, + boost=boost, + _name=_name, + **kwargs, + ) class Percolate(Query): @@ -1325,6 +1604,12 @@ class Percolate(Query): :arg preference: Preference used to fetch document to percolate. :arg routing: Routing used to fetch document to percolate. :arg version: The expected version of a stored document to percolate. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "percolate" @@ -1334,13 +1619,15 @@ def __init__( *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, document: Any = DEFAULT, - documents: Union[List[Any], "DefaultType"] = DEFAULT, + documents: Union[Sequence[Any], "DefaultType"] = DEFAULT, id: Union[str, "DefaultType"] = DEFAULT, index: Union[str, "DefaultType"] = DEFAULT, name: Union[str, "DefaultType"] = DEFAULT, preference: Union[str, "DefaultType"] = DEFAULT, routing: Union[str, "DefaultType"] = DEFAULT, version: Union[int, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1353,6 +1640,8 @@ def __init__( preference=preference, routing=routing, version=version, + boost=boost, + _name=_name, **kwargs, ) @@ -1368,6 +1657,12 @@ class Pinned(Query): results. Required if `docs` is not specified. :arg docs: Documents listed in the order they are to appear in results. Required if `ids` is not specified. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "pinned" @@ -1379,11 +1674,15 @@ def __init__( self, *, organic: Union[Query, "DefaultType"] = DEFAULT, - ids: Union[List[str], "DefaultType"] = DEFAULT, - docs: Union[List["i.PinnedDoc"], Dict[str, Any], "DefaultType"] = DEFAULT, + ids: Union[Sequence[str], "DefaultType"] = DEFAULT, + docs: Union[Sequence["i.PinnedDoc"], Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(organic=organic, ids=ids, docs=docs, **kwargs) + super().__init__( + organic=organic, ids=ids, docs=docs, boost=boost, _name=_name, **kwargs + ) class Prefix(Query): @@ -1461,6 +1760,12 @@ class QueryString(Query): :arg time_zone: Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query string to UTC. :arg type: Determines how the query matches and scores documents. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "query_string" @@ -1477,7 +1782,9 @@ def __init__( default_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, enable_position_increments: Union[bool, "DefaultType"] = DEFAULT, escape: Union[bool, "DefaultType"] = DEFAULT, - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + fields: Union[ + Sequence[Union[str, "InstrumentedField"]], "DefaultType" + ] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, fuzzy_max_expansions: Union[int, "DefaultType"] = DEFAULT, fuzzy_prefix_length: Union[int, "DefaultType"] = DEFAULT, @@ -1503,6 +1810,8 @@ def __init__( ], "DefaultType", ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1531,6 +1840,8 @@ def __init__( tie_breaker=tie_breaker, time_zone=time_zone, type=type, + boost=boost, + _name=_name, **kwargs, ) @@ -1571,6 +1882,12 @@ class RankFeature(Query): the value of the rank feature `field`. :arg sigmoid: Sigmoid function used to boost relevance scores based on the value of the rank feature `field`. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "rank_feature" @@ -1591,6 +1908,8 @@ def __init__( sigmoid: Union[ "i.RankFeatureFunctionSigmoid", Dict[str, Any], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1599,6 +1918,8 @@ def __init__( log=log, linear=linear, sigmoid=sigmoid, + boost=boost, + _name=_name, **kwargs, ) @@ -1628,9 +1949,15 @@ class Rule(Query): """ No documentation available. + :arg organic: (required) No documentation available. :arg ruleset_ids: (required) No documentation available. :arg match_criteria: (required) No documentation available. - :arg organic: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "rule" @@ -1641,15 +1968,19 @@ class Rule(Query): def __init__( self, *, - ruleset_ids: Union[List[str], "DefaultType"] = DEFAULT, - match_criteria: Any = DEFAULT, organic: Union[Query, "DefaultType"] = DEFAULT, + ruleset_ids: Union[Sequence[str], "DefaultType"] = DEFAULT, + match_criteria: Any = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( + organic=organic, ruleset_ids=ruleset_ids, match_criteria=match_criteria, - organic=organic, + boost=boost, + _name=_name, **kwargs, ) @@ -1661,6 +1992,12 @@ class Script(Query): :arg script: (required) Contains a script to run as a query. This script must return a boolean value, `true` or `false`. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "script" @@ -1669,9 +2006,11 @@ def __init__( self, *, script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(script=script, **kwargs) + super().__init__(script=script, boost=boost, _name=_name, **kwargs) class ScriptScore(Query): @@ -1684,6 +2023,12 @@ class ScriptScore(Query): `script_score` query cannot be negative. :arg min_score: Documents with a score lower than this floating point number are excluded from the search results. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "script_score" @@ -1697,18 +2042,33 @@ def __init__( query: Union[Query, "DefaultType"] = DEFAULT, script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, min_score: Union[float, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(query=query, script=script, min_score=min_score, **kwargs) + super().__init__( + query=query, + script=script, + min_score=min_score, + boost=boost, + _name=_name, + **kwargs, + ) class Semantic(Query): """ A semantic query to semantic_text field types - :arg query: (required) The query text :arg field: (required) The field to query, which must be a semantic_text field type + :arg query: (required) The query text + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "semantic" @@ -1716,27 +2076,48 @@ class Semantic(Query): def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, field: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(query=query, field=field, **kwargs) + super().__init__(field=field, query=query, boost=boost, _name=_name, **kwargs) class Shape(Query): """ Queries documents that contain fields indexed using the `shape` type. + :arg _field: The field to use in this query. + :arg _value: The query value for the field. :arg ignore_unmapped: When set to `true` the query ignores an unmapped field and will not match any documents. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "shape" def __init__( - self, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any + self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union["i.ShapeFieldQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + *, + ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, ): - super().__init__(ignore_unmapped=ignore_unmapped, **kwargs) + if _field != DEFAULT: + kwargs[str(_field)] = _value + super().__init__( + ignore_unmapped=ignore_unmapped, boost=boost, _name=_name, **kwargs + ) class SimpleQueryString(Query): @@ -1774,6 +2155,12 @@ class SimpleQueryString(Query): for a document to be returned. :arg quote_field_suffix: Suffix appended to quoted text in the query string. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "simple_query_string" @@ -1786,7 +2173,9 @@ def __init__( analyze_wildcard: Union[bool, "DefaultType"] = DEFAULT, auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, default_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, - fields: Union[List[Union[str, "InstrumentedField"]], "DefaultType"] = DEFAULT, + fields: Union[ + Sequence[Union[str, "InstrumentedField"]], "DefaultType" + ] = DEFAULT, flags: Union["i.PipeSeparatedFlags", Dict[str, Any], "DefaultType"] = DEFAULT, fuzzy_max_expansions: Union[int, "DefaultType"] = DEFAULT, fuzzy_prefix_length: Union[int, "DefaultType"] = DEFAULT, @@ -1794,6 +2183,8 @@ def __init__( lenient: Union[bool, "DefaultType"] = DEFAULT, minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, quote_field_suffix: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -1810,6 +2201,8 @@ def __init__( lenient=lenient, minimum_should_match=minimum_should_match, quote_field_suffix=quote_field_suffix, + boost=boost, + _name=_name, **kwargs, ) @@ -1818,10 +2211,16 @@ class SpanContaining(Query): """ Returns matches which enclose another span query. - :arg little: (required) Can be any span query. Matching spans from - `big` that contain matches from `little` are returned. :arg big: (required) Can be any span query. Matching spans from `big` that contain matches from `little` are returned. + :arg little: (required) Can be any span query. Matching spans from + `big` that contain matches from `little` are returned. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_containing" @@ -1829,11 +2228,13 @@ class SpanContaining(Query): def __init__( self, *, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(little=little, big=big, **kwargs) + super().__init__(big=big, little=little, boost=boost, _name=_name, **kwargs) class SpanFieldMasking(Query): @@ -1841,8 +2242,14 @@ class SpanFieldMasking(Query): Wrapper to allow span queries to participate in composite single-field span queries by _lying_ about their search field. - :arg query: (required) No documentation available. :arg field: (required) No documentation available. + :arg query: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_field_masking" @@ -1850,20 +2257,28 @@ class SpanFieldMasking(Query): def __init__( self, *, - query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(query=query, field=field, **kwargs) + super().__init__(field=field, query=query, boost=boost, _name=_name, **kwargs) class SpanFirst(Query): """ Matches spans near the beginning of a field. - :arg match: (required) Can be any other span type query. :arg end: (required) Controls the maximum end position permitted in a match. + :arg match: (required) Can be any other span type query. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_first" @@ -1871,11 +2286,13 @@ class SpanFirst(Query): def __init__( self, *, - match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, end: Union[int, "DefaultType"] = DEFAULT, + match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(match=match, end=end, **kwargs) + super().__init__(end=end, match=match, boost=boost, _name=_name, **kwargs) class SpanMulti(Query): @@ -1886,6 +2303,12 @@ class SpanMulti(Query): :arg match: (required) Should be a multi term query (one of `wildcard`, `fuzzy`, `prefix`, `range`, or `regexp` query). + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_multi" @@ -1893,8 +2316,15 @@ class SpanMulti(Query): "match": {"type": "query"}, } - def __init__(self, *, match: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any): - super().__init__(match=match, **kwargs) + def __init__( + self, + *, + match: Union[Query, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(match=match, boost=boost, _name=_name, **kwargs) class SpanNear(Query): @@ -1907,6 +2337,12 @@ class SpanNear(Query): :arg in_order: Controls whether matches are required to be in-order. :arg slop: Controls the maximum number of intervening unmatched positions permitted. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_near" @@ -1914,12 +2350,23 @@ class SpanNear(Query): def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + clauses: Union[ + Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + ] = DEFAULT, in_order: Union[bool, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(clauses=clauses, in_order=in_order, slop=slop, **kwargs) + super().__init__( + clauses=clauses, + in_order=in_order, + slop=slop, + boost=boost, + _name=_name, + **kwargs, + ) class SpanNot(Query): @@ -1938,6 +2385,12 @@ class SpanNot(Query): overlap with the exclude span. :arg pre: The number of tokens before the include span that can’t have overlap with the exclude span. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_not" @@ -1950,10 +2403,19 @@ def __init__( dist: Union[int, "DefaultType"] = DEFAULT, post: Union[int, "DefaultType"] = DEFAULT, pre: Union[int, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( - exclude=exclude, include=include, dist=dist, post=post, pre=pre, **kwargs + exclude=exclude, + include=include, + dist=dist, + post=post, + pre=pre, + boost=boost, + _name=_name, + **kwargs, ) @@ -1962,6 +2424,12 @@ class SpanOr(Query): Matches the union of its span clauses. :arg clauses: (required) Array of one or more other span type queries. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_or" @@ -1969,10 +2437,14 @@ class SpanOr(Query): def __init__( self, *, - clauses: Union[List["i.SpanQuery"], Dict[str, Any], "DefaultType"] = DEFAULT, + clauses: Union[ + Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(clauses=clauses, **kwargs) + super().__init__(clauses=clauses, boost=boost, _name=_name, **kwargs) class SpanTerm(Query): @@ -2000,10 +2472,16 @@ class SpanWithin(Query): """ Returns matches which are enclosed inside another span query. - :arg little: (required) Can be any span query. Matching spans from - `little` that are enclosed within `big` are returned. :arg big: (required) Can be any span query. Matching spans from `little` that are enclosed within `big` are returned. + :arg little: (required) Can be any span query. Matching spans from + `little` that are enclosed within `big` are returned. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "span_within" @@ -2011,11 +2489,13 @@ class SpanWithin(Query): def __init__( self, *, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - super().__init__(little=little, big=big, **kwargs) + super().__init__(big=big, little=little, boost=boost, _name=_name, **kwargs) class SparseVector(Query): @@ -2047,6 +2527,12 @@ class SparseVector(Query): improve query performance. This is only used if prune is set to true. If prune is set to true but pruning_config is not specified, default values will be used. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "sparse_vector" @@ -2062,6 +2548,8 @@ def __init__( pruning_config: Union[ "i.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): super().__init__( @@ -2071,6 +2559,8 @@ def __init__( query=query, prune=prune, pruning_config=pruning_config, + boost=boost, + _name=_name, **kwargs, ) @@ -2103,12 +2593,36 @@ class Terms(Query): Returns documents that contain one or more exact terms in a provided field. To return a document, one or more terms must exactly match a field value, including whitespace and capitalization. + + :arg _field: The field to use in this query. + :arg _value: The query value for the field. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "terms" - def __init__(self, **kwargs: Any): - super().__init__(**kwargs) + def __init__( + self, + _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + _value: Union[ + Sequence[Union[int, float, str, bool, None, Any]], + "i.TermsLookup", + Dict[str, Any], + "DefaultType", + ] = DEFAULT, + *, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + if _field != DEFAULT: + kwargs[str(_field)] = _value + super().__init__(boost=boost, _name=_name, **kwargs) def _setattr(self, name: str, value: Any) -> None: # here we convert any iterables that are not strings to lists @@ -2213,12 +2727,25 @@ class Wrapper(Query): :arg query: (required) A base64 encoded query. The binary data format can be any of JSON, YAML, CBOR or SMILE encodings + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "wrapper" - def __init__(self, *, query: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): - super().__init__(query=query, **kwargs) + def __init__( + self, + *, + query: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(query=query, boost=boost, _name=_name, **kwargs) class Type(Query): @@ -2226,9 +2753,22 @@ class Type(Query): No documentation available. :arg value: (required) No documentation available. + :arg boost: Floating point number used to decrease or increase the + relevance scores of the query. Boost values are relative to the + default value of 1.0. A boost value between 0 and 1.0 decreases + the relevance score. A value greater than 1.0 increases the + relevance score. + :arg _name: No documentation available. """ name = "type" - def __init__(self, *, value: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): - super().__init__(value=value, **kwargs) + def __init__( + self, + *, + value: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, "DefaultType"] = DEFAULT, + _name: Union[str, "DefaultType"] = DEFAULT, + **kwargs: Any, + ): + super().__init__(value=value, boost=boost, _name=_name, **kwargs) diff --git a/utils/generator.py b/utils/generator.py index c2859d76..0090d628 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -147,9 +147,9 @@ def get_python_type(self, schema_type): return self.get_python_type(schema_type["type"]) elif schema_type["kind"] == "array_of": - # for arrays we use List[element_type] + # for arrays we use Sequence[element_type] type_, param = self.get_python_type(schema_type["value"]) - return f"List[{type_}]", {**param, "multi": True} if param else None + return f"Sequence[{type_}]", {**param, "multi": True} if param else None elif schema_type["kind"] == "dictionary_of": # for dicts we use Mapping[key_type, value_type] @@ -164,10 +164,10 @@ def get_python_type(self, schema_type): and schema_type["items"][1]["kind"] == "array_of" and schema_type["items"][0] == schema_type["items"][1]["value"] ): - # special kind of unions in the form Union[type, List[type]] + # special kind of unions in the form Union[type, Sequence[type]] type_, param = self.get_python_type(schema_type["items"][0]) return ( - f"Union[{type_}, List[{type_}]]", + f"Union[{type_}, Sequence[{type_}]]", ({"type": param["type"], "multi": True} if param else None), ) elif ( @@ -286,7 +286,8 @@ def property_to_python_class(self, p): "name": "the name of the attribute", "type": "the Python type hint for the attribute", "doc": ["formatted lines of documentation to add to class docstring"], - "required": bool + "required": bool, + "positional": bool, ], "params": [ "name": "the attribute name", @@ -308,27 +309,79 @@ def property_to_python_class(self, p): name = p["type"]["type"]["name"] if f"{namespace}:{name}" in TYPE_REPLACEMENTS: namespace, name = TYPE_REPLACEMENTS[f"{namespace}:{name}"].split(":") - instance = schema.find_type(name, namespace) - if instance["kind"] == "interface": + type_ = schema.find_type(name, namespace) + if type_["kind"] == "interface": k["args"] = [] k["params"] = [] - for arg in instance["properties"]: - python_arg, param = self.get_attribute_data(arg) - if python_arg["required"]: - # insert in the right place so that all required arguments - # appear at the top of the argument list - i = 0 - for i in range(len(k["args"])): - if k["args"][i]["required"] is False: - break - k["args"].insert(i, python_arg) + if "behaviors" in type_: + for behavior in type_["behaviors"]: + if ( + behavior["type"]["name"] != "AdditionalProperty" + or behavior["type"]["namespace"] != "_spec_utils" + ): + # we do not support this behavior, so we ignore it + continue + key_type, _ = schema.get_python_type(behavior["generics"][0]) + if "InstrumentedField" in key_type: + value_type, _ = schema.get_python_type( + behavior["generics"][1] + ) + k["args"].append( + { + "name": "_field", + "type": add_not_set(key_type), + "doc": [ + ":arg _field: The field to use in this query." + ], + "required": False, + "positional": True, + } + ) + k["args"].append( + { + "name": "_value", + "type": add_not_set(add_dict_type(value_type)), + "doc": [ + ":arg _value: The query value for the field." + ], + "required": False, + "positional": True, + } + ) + k["is_single_field"] = True + else: + raise RuntimeError( + f"Non-field AdditionalProperty are not supported for interface {namespace}:{name}." + ) + while True: + for arg in type_["properties"]: + python_arg, param = self.get_attribute_data(arg) + if python_arg["required"]: + # insert in the right place so that all required arguments + # appear at the top of the argument list + i = 0 + for i in range(len(k["args"]) + 1): + if i == len(k["args"]): + break + if k["args"][i].get("positional"): + continue + if k["args"][i]["required"] is False: + break + k["args"].insert(i, python_arg) + else: + k["args"].append(python_arg) + if param: + k["params"].append(param) + if "inherits" in type_ and "type" in type_["inherits"]: + type_ = schema.find_type( + type_["inherits"]["type"]["name"], + type_["inherits"]["type"]["namespace"], + ) else: - k["args"].append(python_arg) - if param: - k["params"].append(param) + break else: raise RuntimeError( - f"Cannot generate code for instances of kind '{instance['kind']}'" + f"Cannot generate code for instances of kind '{type_['kind']}'" ) elif kind == "dictionary_of": @@ -343,12 +396,14 @@ def property_to_python_class(self, p): "type": add_not_set(key_type), "doc": [":arg _field: The field to use in this query."], "required": False, + "positional": True, }, { "name": "_value", "type": add_not_set(add_dict_type(value_type)), "doc": [":arg _value: The query value for the field."], "required": False, + "positional": True, }, ] k["is_single_field"] = True @@ -362,6 +417,7 @@ def property_to_python_class(self, p): ":arg _fields: A dictionary of fields with their values." ], "required": False, + "positional": True, }, ] k["is_multi_field"] = True @@ -391,7 +447,8 @@ def interface_to_python_class(self, interface, interfaces): "name": "the name of the attribute", "type": "the Python type hint for the attribute", "doc": ["formatted lines of documentation to add to class docstring"], - "required": bool + "required": bool, + "positional": bool, ], } ``` @@ -399,25 +456,22 @@ def interface_to_python_class(self, interface, interfaces): type_ = schema.find_type(interface) if type_["kind"] != "interface": raise RuntimeError(f"Type {interface} is not an interface") - if "inherits" in type_ and "type" in type_["inherits"]: - # this class has parents, make sure we have all the parents in our - # list of interfaces to render - parent = type_["inherits"]["type"]["name"] - base = type_ - while base and "inherits" in base and "type" in base["inherits"]: - if base["inherits"]["type"]["name"] not in interfaces: - interfaces.append(base["inherits"]["type"]["name"]) - base = schema.find_type( - base["inherits"]["type"]["name"], - base["inherits"]["type"]["namespace"], + k = {"name": interface, "args": []} + while True: + for arg in type_["properties"]: + arg_type, _ = schema.get_attribute_data(arg) + k["args"].append(arg_type) + if "inherits" in type_ and "type" in type_["inherits"]: + if "parent" not in k: + k["parent"] = type_["inherits"]["type"]["name"] + if type_["inherits"]["type"]["name"] not in interfaces: + interfaces.append(type_["inherits"]["type"]["name"]) + type_ = schema.find_type( + type_["inherits"]["type"]["name"], + type_["inherits"]["type"]["namespace"], ) - else: - # no parent, will inherit from AttrDict - parent = None - k = {"name": interface, "parent": parent, "args": []} - for arg in type_["properties"]: - arg_type, _ = schema.get_attribute_data(arg) - k["args"].append(arg_type) + else: + break return k diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index 8ec68bd7..4732c104 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -from typing import Any, Dict, List, Literal, Mapping, Union +from typing import Any, Dict, Literal, Mapping, Sequence, Union from elastic_transport.client_utils import DEFAULT, DefaultType @@ -42,19 +42,34 @@ class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endi def __init__( self, + {% for arg in k.args %} + {% if arg.positional %}{{ arg.name }}: {{ arg.type }} = DEFAULT,{% endif %} + {% endfor %} + {% if k.args and not k.args[-1].positional %} *, + {% endif %} {% for arg in k.args %} - {{ arg.name }}: {{ arg.type }} = DEFAULT, + {% if not arg.positional %}{{ arg.name }}: {{ arg.type }} = DEFAULT,{% endif %} {% endfor %} **kwargs: Any ): + {% if k.is_single_field %} + if _field != DEFAULT: + kwargs[str(_field)] = _value + {% elif k.is_multi_field %} + if _fields != DEFAULT: + for field, value in _fields.items(): + kwargs[str(field)] = value + {% endif %} {% for arg in k.args %} + {% if not arg.positional %} if {{ arg.name }} != DEFAULT: {% if "InstrumentedField" in arg.type %} kwargs["{{ arg.name }}"] = str({{ arg.name }}) {% else %} kwargs["{{ arg.name }}"] = {{ arg.name }} {% endif %} + {% endif %} {% endfor %} {% if k.parent %} super().__init__(**kwargs) diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 4aa9bade..483066d9 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -30,6 +30,7 @@ from typing import ( MutableMapping, Optional, Protocol, + Sequence, TypeVar, Union, cast, @@ -175,11 +176,18 @@ class {{ k.name }}({{ parent }}): def __init__( self, - {% if k.args and not k.is_single_field and not k.is_multi_field %} + {% for arg in k.args %} + {% if arg.positional %} + {{ arg.name }}: {{ arg.type }} = DEFAULT, + {% endif %} + {% endfor %} + {% if k.args and not k.args[-1].positional %} *, {% endif %} {% for arg in k.args %} + {% if not arg.positional %} {{ arg.name }}: {{ arg.type }} = DEFAULT, + {% endif %} {% endfor %} **kwargs: Any ): @@ -198,11 +206,11 @@ class {{ k.name }}({{ parent }}): kwargs[str(field)] = value {% endif %} super().__init__( - {% if not k.is_single_field and not k.is_multi_field %} {% for arg in k.args %} + {% if not arg.positional %} {{ arg.name }}={{ arg.name }}, - {% endfor %} {% endif %} + {% endfor %} **kwargs ) From 976653875ad3e5bfd5b0cb3be610feb43b253669 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 5 Sep 2024 19:01:46 +0100 Subject: [PATCH 13/27] support legacy FieldValueFactor name for FieldValueFactorScore --- elasticsearch_dsl/function.py | 6 +++++- elasticsearch_dsl/interfaces.py | 4 ++-- utils/generator.py | 2 -- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/elasticsearch_dsl/function.py b/elasticsearch_dsl/function.py index 47d07da8..9744e6f8 100644 --- a/elasticsearch_dsl/function.py +++ b/elasticsearch_dsl/function.py @@ -134,10 +134,14 @@ class RandomScore(ScoreFunction): name = "random_score" -class FieldValueFactor(ScoreFunction): +class FieldValueFactorScore(ScoreFunction): name = "field_value_factor" +class FieldValueFactor(FieldValueFactorScore): # alias of the above + pass + + class Linear(ScoreFunction): name = "linear" diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index 2c852fef..25e5ce2f 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -173,7 +173,7 @@ class FunctionScoreContainer(AttrDict[Any]): exp: Union["f.DecayFunction", "DefaultType"] gauss: Union["f.DecayFunction", "DefaultType"] linear: Union["f.DecayFunction", "DefaultType"] - field_value_factor: Union["f.FieldValueFactor", "DefaultType"] + field_value_factor: Union["f.FieldValueFactorScore", "DefaultType"] random_score: Union["f.RandomScore", "DefaultType"] script_score: Union["f.ScriptScore", "DefaultType"] filter: Union[Query, "DefaultType"] @@ -185,7 +185,7 @@ def __init__( exp: Union["f.DecayFunction", "DefaultType"] = DEFAULT, gauss: Union["f.DecayFunction", "DefaultType"] = DEFAULT, linear: Union["f.DecayFunction", "DefaultType"] = DEFAULT, - field_value_factor: Union["f.FieldValueFactor", "DefaultType"] = DEFAULT, + field_value_factor: Union["f.FieldValueFactorScore", "DefaultType"] = DEFAULT, random_score: Union["f.RandomScore", "DefaultType"] = DEFAULT, script_score: Union["f.ScriptScore", "DefaultType"] = DEFAULT, filter: Union[Query, "DefaultType"] = DEFAULT, diff --git a/utils/generator.py b/utils/generator.py index 0090d628..1b1b1eba 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -211,8 +211,6 @@ def get_python_type(self, schema_type): return '"wrappers.Range[Any]"', None elif schema_type["name"]["name"].endswith("ScoreFunction"): name = schema_type["name"]["name"][:-8] - if name == "FieldValueFactorScore": - name = "FieldValueFactor" # Python DSL uses different name return f'"f.{name}"', None elif schema_type["name"]["name"].endswith("DecayFunction"): return '"f.DecayFunction"', None From 984993cbc9713041fcf0d62aec32d8f7db369360 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 17:06:38 +0100 Subject: [PATCH 14/27] Update utils/generator.py Co-authored-by: Quentin Pradet --- utils/generator.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/generator.py b/utils/generator.py index 1b1b1eba..67fdf53c 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -500,11 +500,8 @@ def generate_interfaces_py(schema, filename): classes_list = [] for n in classes: k = classes[n] - try: - classes_list.index(k) + if k in classes_list: continue - except ValueError: - pass classes_list.append(k) parent = k.get("parent") parent_index = len(classes_list) - 1 From 55e3fc8c05d549ceffcb665f93f3ca146a8af914 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 14:24:00 +0100 Subject: [PATCH 15/27] use the identity operator to check for defaults --- elasticsearch_dsl/interfaces.py | 724 +++++++++++++++--------------- elasticsearch_dsl/query.py | 46 +- utils/templates/interfaces.py.tpl | 6 +- utils/templates/query.py.tpl | 6 +- 4 files changed, 391 insertions(+), 391 deletions(-) diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/interfaces.py index 25e5ce2f..c657bded 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/interfaces.py @@ -48,9 +48,9 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(kwargs) @@ -93,21 +93,21 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if cutoff_frequency != DEFAULT: + if cutoff_frequency is not DEFAULT: kwargs["cutoff_frequency"] = cutoff_frequency - if high_freq_operator != DEFAULT: + if high_freq_operator is not DEFAULT: kwargs["high_freq_operator"] = high_freq_operator - if low_freq_operator != DEFAULT: + if low_freq_operator is not DEFAULT: kwargs["low_freq_operator"] = low_freq_operator - if minimum_should_match != DEFAULT: + if minimum_should_match is not DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -134,13 +134,13 @@ def __init__( right: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if top != DEFAULT: + if top is not DEFAULT: kwargs["top"] = top - if bottom != DEFAULT: + if bottom is not DEFAULT: kwargs["bottom"] = bottom - if left != DEFAULT: + if left is not DEFAULT: kwargs["left"] = left - if right != DEFAULT: + if right is not DEFAULT: kwargs["right"] = right super().__init__(kwargs) @@ -192,21 +192,21 @@ def __init__( weight: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if exp != DEFAULT: + if exp is not DEFAULT: kwargs["exp"] = exp - if gauss != DEFAULT: + if gauss is not DEFAULT: kwargs["gauss"] = gauss - if linear != DEFAULT: + if linear is not DEFAULT: kwargs["linear"] = linear - if field_value_factor != DEFAULT: + if field_value_factor is not DEFAULT: kwargs["field_value_factor"] = field_value_factor - if random_score != DEFAULT: + if random_score is not DEFAULT: kwargs["random_score"] = random_score - if script_score != DEFAULT: + if script_score is not DEFAULT: kwargs["script_score"] = script_score - if filter != DEFAULT: + if filter is not DEFAULT: kwargs["filter"] = filter - if weight != DEFAULT: + if weight is not DEFAULT: kwargs["weight"] = weight super().__init__(kwargs) @@ -252,21 +252,21 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if max_expansions != DEFAULT: + if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions - if prefix_length != DEFAULT: + if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if rewrite != DEFAULT: + if rewrite is not DEFAULT: kwargs["rewrite"] = rewrite - if transpositions != DEFAULT: + if transpositions is not DEFAULT: kwargs["transpositions"] = transpositions - if fuzziness != DEFAULT: + if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -279,7 +279,7 @@ class GeoHashLocation(AttrDict[Any]): geohash: Union[str, "DefaultType"] def __init__(self, *, geohash: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): - if geohash != DEFAULT: + if geohash is not DEFAULT: kwargs["geohash"] = geohash super().__init__(kwargs) @@ -309,7 +309,7 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if points != DEFAULT: + if points is not DEFAULT: kwargs["points"] = points super().__init__(kwargs) @@ -338,11 +338,11 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if shape != DEFAULT: + if shape is not DEFAULT: kwargs["shape"] = shape - if indexed_shape != DEFAULT: + if indexed_shape is not DEFAULT: kwargs["indexed_shape"] = indexed_shape - if relation != DEFAULT: + if relation is not DEFAULT: kwargs["relation"] = relation super().__init__(kwargs) @@ -444,37 +444,37 @@ def __init__( version: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if name != DEFAULT: + if name is not DEFAULT: kwargs["name"] = name - if size != DEFAULT: + if size is not DEFAULT: kwargs["size"] = size - if from_ != DEFAULT: + if from_ is not DEFAULT: kwargs["from_"] = from_ - if collapse != DEFAULT: + if collapse is not DEFAULT: kwargs["collapse"] = collapse - if docvalue_fields != DEFAULT: + if docvalue_fields is not DEFAULT: kwargs["docvalue_fields"] = docvalue_fields - if explain != DEFAULT: + if explain is not DEFAULT: kwargs["explain"] = explain - if highlight != DEFAULT: + if highlight is not DEFAULT: kwargs["highlight"] = highlight - if ignore_unmapped != DEFAULT: + if ignore_unmapped is not DEFAULT: kwargs["ignore_unmapped"] = ignore_unmapped - if script_fields != DEFAULT: + if script_fields is not DEFAULT: kwargs["script_fields"] = str(script_fields) - if seq_no_primary_term != DEFAULT: + if seq_no_primary_term is not DEFAULT: kwargs["seq_no_primary_term"] = seq_no_primary_term - if fields != DEFAULT: + if fields is not DEFAULT: kwargs["fields"] = str(fields) - if sort != DEFAULT: + if sort is not DEFAULT: kwargs["sort"] = str(sort) - if _source != DEFAULT: + if _source is not DEFAULT: kwargs["_source"] = _source - if stored_fields != DEFAULT: + if stored_fields is not DEFAULT: kwargs["stored_fields"] = str(stored_fields) - if track_scores != DEFAULT: + if track_scores is not DEFAULT: kwargs["track_scores"] = track_scores - if version != DEFAULT: + if version is not DEFAULT: kwargs["version"] = version super().__init__(kwargs) @@ -519,21 +519,21 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if all_of != DEFAULT: + if all_of is not DEFAULT: kwargs["all_of"] = all_of - if any_of != DEFAULT: + if any_of is not DEFAULT: kwargs["any_of"] = any_of - if fuzzy != DEFAULT: + if fuzzy is not DEFAULT: kwargs["fuzzy"] = fuzzy - if match != DEFAULT: + if match is not DEFAULT: kwargs["match"] = match - if prefix != DEFAULT: + if prefix is not DEFAULT: kwargs["prefix"] = prefix - if wildcard != DEFAULT: + if wildcard is not DEFAULT: kwargs["wildcard"] = wildcard - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -554,9 +554,9 @@ def __init__( lon: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if lat != DEFAULT: + if lat is not DEFAULT: kwargs["lat"] = lat - if lon != DEFAULT: + if lon is not DEFAULT: kwargs["lon"] = lon super().__init__(kwargs) @@ -605,21 +605,21 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if doc != DEFAULT: + if doc is not DEFAULT: kwargs["doc"] = doc - if fields != DEFAULT: + if fields is not DEFAULT: kwargs["fields"] = str(fields) - if _id != DEFAULT: + if _id is not DEFAULT: kwargs["_id"] = _id - if _index != DEFAULT: + if _index is not DEFAULT: kwargs["_index"] = _index - if per_field_analyzer != DEFAULT: + if per_field_analyzer is not DEFAULT: kwargs["per_field_analyzer"] = str(per_field_analyzer) - if routing != DEFAULT: + if routing is not DEFAULT: kwargs["routing"] = routing - if version != DEFAULT: + if version is not DEFAULT: kwargs["version"] = version - if version_type != DEFAULT: + if version_type is not DEFAULT: kwargs["version_type"] = version_type super().__init__(kwargs) @@ -687,27 +687,27 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if fuzziness != DEFAULT: + if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness - if fuzzy_rewrite != DEFAULT: + if fuzzy_rewrite is not DEFAULT: kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if fuzzy_transpositions != DEFAULT: + if fuzzy_transpositions is not DEFAULT: kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if max_expansions != DEFAULT: + if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions - if minimum_should_match != DEFAULT: + if minimum_should_match is not DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if operator != DEFAULT: + if operator is not DEFAULT: kwargs["operator"] = operator - if prefix_length != DEFAULT: + if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -752,19 +752,19 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if max_expansions != DEFAULT: + if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if slop != DEFAULT: + if slop is not DEFAULT: kwargs["slop"] = slop - if zero_terms_query != DEFAULT: + if zero_terms_query is not DEFAULT: kwargs["zero_terms_query"] = zero_terms_query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -806,17 +806,17 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if slop != DEFAULT: + if slop is not DEFAULT: kwargs["slop"] = slop - if zero_terms_query != DEFAULT: + if zero_terms_query is not DEFAULT: kwargs["zero_terms_query"] = zero_terms_query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -892,37 +892,37 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if auto_generate_synonyms_phrase_query != DEFAULT: + if auto_generate_synonyms_phrase_query is not DEFAULT: kwargs["auto_generate_synonyms_phrase_query"] = ( auto_generate_synonyms_phrase_query ) - if cutoff_frequency != DEFAULT: + if cutoff_frequency is not DEFAULT: kwargs["cutoff_frequency"] = cutoff_frequency - if fuzziness != DEFAULT: + if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness - if fuzzy_rewrite != DEFAULT: + if fuzzy_rewrite is not DEFAULT: kwargs["fuzzy_rewrite"] = fuzzy_rewrite - if fuzzy_transpositions != DEFAULT: + if fuzzy_transpositions is not DEFAULT: kwargs["fuzzy_transpositions"] = fuzzy_transpositions - if lenient != DEFAULT: + if lenient is not DEFAULT: kwargs["lenient"] = lenient - if max_expansions != DEFAULT: + if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions - if minimum_should_match != DEFAULT: + if minimum_should_match is not DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if operator != DEFAULT: + if operator is not DEFAULT: kwargs["operator"] = operator - if prefix_length != DEFAULT: + if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if zero_terms_query != DEFAULT: + if zero_terms_query is not DEFAULT: kwargs["zero_terms_query"] = zero_terms_query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -943,9 +943,9 @@ def __init__( _index: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _id != DEFAULT: + if _id is not DEFAULT: kwargs["_id"] = _id - if _index != DEFAULT: + if _index is not DEFAULT: kwargs["_index"] = _index super().__init__(kwargs) @@ -983,15 +983,15 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if rewrite != DEFAULT: + if rewrite is not DEFAULT: kwargs["rewrite"] = rewrite - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if case_insensitive != DEFAULT: + if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1011,7 +1011,7 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if text_embedding != DEFAULT: + if text_embedding is not DEFAULT: kwargs["text_embedding"] = text_embedding super().__init__(kwargs) @@ -1034,7 +1034,7 @@ class RankFeatureFunctionLogarithm(RankFeatureFunction): def __init__( self, *, scaling_factor: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any ): - if scaling_factor != DEFAULT: + if scaling_factor is not DEFAULT: kwargs["scaling_factor"] = scaling_factor super().__init__(**kwargs) @@ -1048,7 +1048,7 @@ class RankFeatureFunctionSaturation(RankFeatureFunction): pivot: Union[float, "DefaultType"] def __init__(self, *, pivot: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any): - if pivot != DEFAULT: + if pivot is not DEFAULT: kwargs["pivot"] = pivot super().__init__(**kwargs) @@ -1070,9 +1070,9 @@ def __init__( exponent: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if pivot != DEFAULT: + if pivot is not DEFAULT: kwargs["pivot"] = pivot - if exponent != DEFAULT: + if exponent is not DEFAULT: kwargs["exponent"] = exponent super().__init__(**kwargs) @@ -1117,19 +1117,19 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if case_insensitive != DEFAULT: + if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive - if flags != DEFAULT: + if flags is not DEFAULT: kwargs["flags"] = flags - if max_determinized_states != DEFAULT: + if max_determinized_states is not DEFAULT: kwargs["max_determinized_states"] = max_determinized_states - if rewrite != DEFAULT: + if rewrite is not DEFAULT: kwargs["rewrite"] = rewrite - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1163,15 +1163,15 @@ def __init__( options: Union[Mapping[str, str], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if source != DEFAULT: + if source is not DEFAULT: kwargs["source"] = source - if id != DEFAULT: + if id is not DEFAULT: kwargs["id"] = id - if params != DEFAULT: + if params is not DEFAULT: kwargs["params"] = params - if lang != DEFAULT: + if lang is not DEFAULT: kwargs["lang"] = lang - if options != DEFAULT: + if options is not DEFAULT: kwargs["options"] = options super().__init__(kwargs) @@ -1201,11 +1201,11 @@ def __init__( shape: Any = DEFAULT, **kwargs: Any, ): - if indexed_shape != DEFAULT: + if indexed_shape is not DEFAULT: kwargs["indexed_shape"] = indexed_shape - if relation != DEFAULT: + if relation is not DEFAULT: kwargs["relation"] = relation - if shape != DEFAULT: + if shape is not DEFAULT: kwargs["shape"] = shape super().__init__(kwargs) @@ -1279,25 +1279,25 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if span_containing != DEFAULT: + if span_containing is not DEFAULT: kwargs["span_containing"] = span_containing - if span_field_masking != DEFAULT: + if span_field_masking is not DEFAULT: kwargs["span_field_masking"] = span_field_masking - if span_first != DEFAULT: + if span_first is not DEFAULT: kwargs["span_first"] = span_first - if span_gap != DEFAULT: + if span_gap is not DEFAULT: kwargs["span_gap"] = str(span_gap) - if span_multi != DEFAULT: + if span_multi is not DEFAULT: kwargs["span_multi"] = span_multi - if span_near != DEFAULT: + if span_near is not DEFAULT: kwargs["span_near"] = span_near - if span_not != DEFAULT: + if span_not is not DEFAULT: kwargs["span_not"] = span_not - if span_or != DEFAULT: + if span_or is not DEFAULT: kwargs["span_or"] = span_or - if span_term != DEFAULT: + if span_term is not DEFAULT: kwargs["span_term"] = str(span_term) - if span_within != DEFAULT: + if span_within is not DEFAULT: kwargs["span_within"] = span_within super().__init__(kwargs) @@ -1325,11 +1325,11 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1363,13 +1363,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if case_insensitive != DEFAULT: + if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1396,13 +1396,13 @@ def __init__( routing: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if index != DEFAULT: + if index is not DEFAULT: kwargs["index"] = index - if id != DEFAULT: + if id is not DEFAULT: kwargs["id"] = id - if path != DEFAULT: + if path is not DEFAULT: kwargs["path"] = str(path) - if routing != DEFAULT: + if routing is not DEFAULT: kwargs["routing"] = routing super().__init__(kwargs) @@ -1443,15 +1443,15 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if minimum_should_match_field != DEFAULT: + if minimum_should_match_field is not DEFAULT: kwargs["minimum_should_match_field"] = str(minimum_should_match_field) - if minimum_should_match_script != DEFAULT: + if minimum_should_match_script is not DEFAULT: kwargs["minimum_should_match_script"] = minimum_should_match_script - if terms != DEFAULT: + if terms is not DEFAULT: kwargs["terms"] = terms - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1487,15 +1487,15 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if model_id != DEFAULT: + if model_id is not DEFAULT: kwargs["model_id"] = model_id - if model_text != DEFAULT: + if model_text is not DEFAULT: kwargs["model_text"] = model_text - if pruning_config != DEFAULT: + if pruning_config is not DEFAULT: kwargs["pruning_config"] = pruning_config - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1523,11 +1523,11 @@ def __init__( only_score_pruned_tokens: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if tokens_freq_ratio_threshold != DEFAULT: + if tokens_freq_ratio_threshold is not DEFAULT: kwargs["tokens_freq_ratio_threshold"] = tokens_freq_ratio_threshold - if tokens_weight_threshold != DEFAULT: + if tokens_weight_threshold is not DEFAULT: kwargs["tokens_weight_threshold"] = tokens_weight_threshold - if only_score_pruned_tokens != DEFAULT: + if only_score_pruned_tokens is not DEFAULT: kwargs["only_score_pruned_tokens"] = only_score_pruned_tokens super().__init__(kwargs) @@ -1576,9 +1576,9 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if top_left != DEFAULT: + if top_left is not DEFAULT: kwargs["top_left"] = top_left - if bottom_right != DEFAULT: + if bottom_right is not DEFAULT: kwargs["bottom_right"] = bottom_right super().__init__(kwargs) @@ -1627,9 +1627,9 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if top_right != DEFAULT: + if top_right is not DEFAULT: kwargs["top_right"] = top_right - if bottom_left != DEFAULT: + if bottom_left is not DEFAULT: kwargs["bottom_left"] = bottom_left super().__init__(kwargs) @@ -1662,13 +1662,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if tokens != DEFAULT: + if tokens is not DEFAULT: kwargs["tokens"] = tokens - if pruning_config != DEFAULT: + if pruning_config is not DEFAULT: kwargs["pruning_config"] = pruning_config - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1710,17 +1710,17 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if case_insensitive != DEFAULT: + if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive - if rewrite != DEFAULT: + if rewrite is not DEFAULT: kwargs["rewrite"] = rewrite - if value != DEFAULT: + if value is not DEFAULT: kwargs["value"] = value - if wildcard != DEFAULT: + if wildcard is not DEFAULT: kwargs["wildcard"] = wildcard - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -1733,7 +1733,7 @@ class WktGeoBounds(AttrDict[Any]): wkt: Union[str, "DefaultType"] def __init__(self, *, wkt: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): - if wkt != DEFAULT: + if wkt is not DEFAULT: kwargs["wkt"] = wkt super().__init__(kwargs) @@ -1760,13 +1760,13 @@ def __init__( routing: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if id != DEFAULT: + if id is not DEFAULT: kwargs["id"] = id - if index != DEFAULT: + if index is not DEFAULT: kwargs["index"] = index - if path != DEFAULT: + if path is not DEFAULT: kwargs["path"] = str(path) - if routing != DEFAULT: + if routing is not DEFAULT: kwargs["routing"] = routing super().__init__(kwargs) @@ -1798,13 +1798,13 @@ def __init__( collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if field != DEFAULT: + if field is not DEFAULT: kwargs["field"] = str(field) - if inner_hits != DEFAULT: + if inner_hits is not DEFAULT: kwargs["inner_hits"] = inner_hits - if max_concurrent_group_searches != DEFAULT: + if max_concurrent_group_searches is not DEFAULT: kwargs["max_concurrent_group_searches"] = max_concurrent_group_searches - if collapse != DEFAULT: + if collapse is not DEFAULT: kwargs["collapse"] = collapse super().__init__(kwargs) @@ -1829,11 +1829,11 @@ def __init__( include_unmapped: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if field != DEFAULT: + if field is not DEFAULT: kwargs["field"] = str(field) - if format != DEFAULT: + if format is not DEFAULT: kwargs["format"] = format - if include_unmapped != DEFAULT: + if include_unmapped is not DEFAULT: kwargs["include_unmapped"] = include_unmapped super().__init__(kwargs) @@ -1951,47 +1951,47 @@ def __init__( tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if type != DEFAULT: + if type is not DEFAULT: kwargs["type"] = type - if boundary_chars != DEFAULT: + if boundary_chars is not DEFAULT: kwargs["boundary_chars"] = boundary_chars - if boundary_max_scan != DEFAULT: + if boundary_max_scan is not DEFAULT: kwargs["boundary_max_scan"] = boundary_max_scan - if boundary_scanner != DEFAULT: + if boundary_scanner is not DEFAULT: kwargs["boundary_scanner"] = boundary_scanner - if boundary_scanner_locale != DEFAULT: + if boundary_scanner_locale is not DEFAULT: kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if force_source != DEFAULT: + if force_source is not DEFAULT: kwargs["force_source"] = force_source - if fragmenter != DEFAULT: + if fragmenter is not DEFAULT: kwargs["fragmenter"] = fragmenter - if fragment_size != DEFAULT: + if fragment_size is not DEFAULT: kwargs["fragment_size"] = fragment_size - if highlight_filter != DEFAULT: + if highlight_filter is not DEFAULT: kwargs["highlight_filter"] = highlight_filter - if highlight_query != DEFAULT: + if highlight_query is not DEFAULT: kwargs["highlight_query"] = highlight_query - if max_fragment_length != DEFAULT: + if max_fragment_length is not DEFAULT: kwargs["max_fragment_length"] = max_fragment_length - if max_analyzed_offset != DEFAULT: + if max_analyzed_offset is not DEFAULT: kwargs["max_analyzed_offset"] = max_analyzed_offset - if no_match_size != DEFAULT: + if no_match_size is not DEFAULT: kwargs["no_match_size"] = no_match_size - if number_of_fragments != DEFAULT: + if number_of_fragments is not DEFAULT: kwargs["number_of_fragments"] = number_of_fragments - if options != DEFAULT: + if options is not DEFAULT: kwargs["options"] = options - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order - if phrase_limit != DEFAULT: + if phrase_limit is not DEFAULT: kwargs["phrase_limit"] = phrase_limit - if post_tags != DEFAULT: + if post_tags is not DEFAULT: kwargs["post_tags"] = post_tags - if pre_tags != DEFAULT: + if pre_tags is not DEFAULT: kwargs["pre_tags"] = pre_tags - if require_field_match != DEFAULT: + if require_field_match is not DEFAULT: kwargs["require_field_match"] = require_field_match - if tags_schema != DEFAULT: + if tags_schema is not DEFAULT: kwargs["tags_schema"] = tags_schema super().__init__(kwargs) @@ -2123,51 +2123,51 @@ def __init__( tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if encoder != DEFAULT: + if encoder is not DEFAULT: kwargs["encoder"] = encoder - if fields != DEFAULT: + if fields is not DEFAULT: kwargs["fields"] = str(fields) - if type != DEFAULT: + if type is not DEFAULT: kwargs["type"] = type - if boundary_chars != DEFAULT: + if boundary_chars is not DEFAULT: kwargs["boundary_chars"] = boundary_chars - if boundary_max_scan != DEFAULT: + if boundary_max_scan is not DEFAULT: kwargs["boundary_max_scan"] = boundary_max_scan - if boundary_scanner != DEFAULT: + if boundary_scanner is not DEFAULT: kwargs["boundary_scanner"] = boundary_scanner - if boundary_scanner_locale != DEFAULT: + if boundary_scanner_locale is not DEFAULT: kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if force_source != DEFAULT: + if force_source is not DEFAULT: kwargs["force_source"] = force_source - if fragmenter != DEFAULT: + if fragmenter is not DEFAULT: kwargs["fragmenter"] = fragmenter - if fragment_size != DEFAULT: + if fragment_size is not DEFAULT: kwargs["fragment_size"] = fragment_size - if highlight_filter != DEFAULT: + if highlight_filter is not DEFAULT: kwargs["highlight_filter"] = highlight_filter - if highlight_query != DEFAULT: + if highlight_query is not DEFAULT: kwargs["highlight_query"] = highlight_query - if max_fragment_length != DEFAULT: + if max_fragment_length is not DEFAULT: kwargs["max_fragment_length"] = max_fragment_length - if max_analyzed_offset != DEFAULT: + if max_analyzed_offset is not DEFAULT: kwargs["max_analyzed_offset"] = max_analyzed_offset - if no_match_size != DEFAULT: + if no_match_size is not DEFAULT: kwargs["no_match_size"] = no_match_size - if number_of_fragments != DEFAULT: + if number_of_fragments is not DEFAULT: kwargs["number_of_fragments"] = number_of_fragments - if options != DEFAULT: + if options is not DEFAULT: kwargs["options"] = options - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order - if phrase_limit != DEFAULT: + if phrase_limit is not DEFAULT: kwargs["phrase_limit"] = phrase_limit - if post_tags != DEFAULT: + if post_tags is not DEFAULT: kwargs["post_tags"] = post_tags - if pre_tags != DEFAULT: + if pre_tags is not DEFAULT: kwargs["pre_tags"] = pre_tags - if require_field_match != DEFAULT: + if require_field_match is not DEFAULT: kwargs["require_field_match"] = require_field_match - if tags_schema != DEFAULT: + if tags_schema is not DEFAULT: kwargs["tags_schema"] = tags_schema super().__init__(**kwargs) @@ -2188,9 +2188,9 @@ def __init__( ignore_failure: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if script != DEFAULT: + if script is not DEFAULT: kwargs["script"] = script - if ignore_failure != DEFAULT: + if ignore_failure is not DEFAULT: kwargs["ignore_failure"] = ignore_failure super().__init__(kwargs) @@ -2219,13 +2219,13 @@ def __init__( _script: Union["i.ScriptSort", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _score != DEFAULT: + if _score is not DEFAULT: kwargs["_score"] = _score - if _doc != DEFAULT: + if _doc is not DEFAULT: kwargs["_doc"] = _doc - if _geo_distance != DEFAULT: + if _geo_distance is not DEFAULT: kwargs["_geo_distance"] = _geo_distance - if _script != DEFAULT: + if _script is not DEFAULT: kwargs["_script"] = _script super().__init__(kwargs) @@ -2262,9 +2262,9 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if excludes != DEFAULT: + if excludes is not DEFAULT: kwargs["excludes"] = str(excludes) - if includes != DEFAULT: + if includes is not DEFAULT: kwargs["includes"] = str(includes) super().__init__(kwargs) @@ -2298,13 +2298,13 @@ def __init__( filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if intervals != DEFAULT: + if intervals is not DEFAULT: kwargs["intervals"] = intervals - if max_gaps != DEFAULT: + if max_gaps is not DEFAULT: kwargs["max_gaps"] = max_gaps - if ordered != DEFAULT: + if ordered is not DEFAULT: kwargs["ordered"] = ordered - if filter != DEFAULT: + if filter is not DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -2327,9 +2327,9 @@ def __init__( filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if intervals != DEFAULT: + if intervals is not DEFAULT: kwargs["intervals"] = intervals - if filter != DEFAULT: + if filter is not DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -2367,17 +2367,17 @@ def __init__( use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if fuzziness != DEFAULT: + if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness - if prefix_length != DEFAULT: + if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if term != DEFAULT: + if term is not DEFAULT: kwargs["term"] = term - if transpositions != DEFAULT: + if transpositions is not DEFAULT: kwargs["transpositions"] = transpositions - if use_field != DEFAULT: + if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -2415,17 +2415,17 @@ def __init__( filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if max_gaps != DEFAULT: + if max_gaps is not DEFAULT: kwargs["max_gaps"] = max_gaps - if ordered != DEFAULT: + if ordered is not DEFAULT: kwargs["ordered"] = ordered - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if use_field != DEFAULT: + if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) - if filter != DEFAULT: + if filter is not DEFAULT: kwargs["filter"] = filter super().__init__(kwargs) @@ -2453,11 +2453,11 @@ def __init__( use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if prefix != DEFAULT: + if prefix is not DEFAULT: kwargs["prefix"] = prefix - if use_field != DEFAULT: + if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -2485,11 +2485,11 @@ def __init__( use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if pattern != DEFAULT: + if pattern is not DEFAULT: kwargs["pattern"] = pattern - if use_field != DEFAULT: + if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -2510,9 +2510,9 @@ def __init__( model_text: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if model_id != DEFAULT: + if model_id is not DEFAULT: kwargs["model_id"] = model_id - if model_text != DEFAULT: + if model_text is not DEFAULT: kwargs["model_text"] = model_text super().__init__(kwargs) @@ -2545,13 +2545,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if big != DEFAULT: + if big is not DEFAULT: kwargs["big"] = big - if little != DEFAULT: + if little is not DEFAULT: kwargs["little"] = little - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2582,13 +2582,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if field != DEFAULT: + if field is not DEFAULT: kwargs["field"] = str(field) - if query != DEFAULT: + if query is not DEFAULT: kwargs["query"] = query - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2620,13 +2620,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if end != DEFAULT: + if end is not DEFAULT: kwargs["end"] = end - if match != DEFAULT: + if match is not DEFAULT: kwargs["match"] = match - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2655,11 +2655,11 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if match != DEFAULT: + if match is not DEFAULT: kwargs["match"] = match - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2696,15 +2696,15 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if clauses != DEFAULT: + if clauses is not DEFAULT: kwargs["clauses"] = clauses - if in_order != DEFAULT: + if in_order is not DEFAULT: kwargs["in_order"] = in_order - if slop != DEFAULT: + if slop is not DEFAULT: kwargs["slop"] = slop - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2749,19 +2749,19 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if dist != DEFAULT: + if dist is not DEFAULT: kwargs["dist"] = dist - if exclude != DEFAULT: + if exclude is not DEFAULT: kwargs["exclude"] = exclude - if include != DEFAULT: + if include is not DEFAULT: kwargs["include"] = include - if post != DEFAULT: + if post is not DEFAULT: kwargs["post"] = post - if pre != DEFAULT: + if pre is not DEFAULT: kwargs["pre"] = pre - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2791,11 +2791,11 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if clauses != DEFAULT: + if clauses is not DEFAULT: kwargs["clauses"] = clauses - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2828,13 +2828,13 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if big != DEFAULT: + if big is not DEFAULT: kwargs["big"] = big - if little != DEFAULT: + if little is not DEFAULT: kwargs["little"] = little - if boost != DEFAULT: + if boost is not DEFAULT: kwargs["boost"] = boost - if _name != DEFAULT: + if _name is not DEFAULT: kwargs["_name"] = _name super().__init__(**kwargs) @@ -2969,53 +2969,53 @@ def __init__( tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if fragment_offset != DEFAULT: + if fragment_offset is not DEFAULT: kwargs["fragment_offset"] = fragment_offset - if matched_fields != DEFAULT: + if matched_fields is not DEFAULT: kwargs["matched_fields"] = str(matched_fields) - if analyzer != DEFAULT: + if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer - if type != DEFAULT: + if type is not DEFAULT: kwargs["type"] = type - if boundary_chars != DEFAULT: + if boundary_chars is not DEFAULT: kwargs["boundary_chars"] = boundary_chars - if boundary_max_scan != DEFAULT: + if boundary_max_scan is not DEFAULT: kwargs["boundary_max_scan"] = boundary_max_scan - if boundary_scanner != DEFAULT: + if boundary_scanner is not DEFAULT: kwargs["boundary_scanner"] = boundary_scanner - if boundary_scanner_locale != DEFAULT: + if boundary_scanner_locale is not DEFAULT: kwargs["boundary_scanner_locale"] = boundary_scanner_locale - if force_source != DEFAULT: + if force_source is not DEFAULT: kwargs["force_source"] = force_source - if fragmenter != DEFAULT: + if fragmenter is not DEFAULT: kwargs["fragmenter"] = fragmenter - if fragment_size != DEFAULT: + if fragment_size is not DEFAULT: kwargs["fragment_size"] = fragment_size - if highlight_filter != DEFAULT: + if highlight_filter is not DEFAULT: kwargs["highlight_filter"] = highlight_filter - if highlight_query != DEFAULT: + if highlight_query is not DEFAULT: kwargs["highlight_query"] = highlight_query - if max_fragment_length != DEFAULT: + if max_fragment_length is not DEFAULT: kwargs["max_fragment_length"] = max_fragment_length - if max_analyzed_offset != DEFAULT: + if max_analyzed_offset is not DEFAULT: kwargs["max_analyzed_offset"] = max_analyzed_offset - if no_match_size != DEFAULT: + if no_match_size is not DEFAULT: kwargs["no_match_size"] = no_match_size - if number_of_fragments != DEFAULT: + if number_of_fragments is not DEFAULT: kwargs["number_of_fragments"] = number_of_fragments - if options != DEFAULT: + if options is not DEFAULT: kwargs["options"] = options - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order - if phrase_limit != DEFAULT: + if phrase_limit is not DEFAULT: kwargs["phrase_limit"] = phrase_limit - if post_tags != DEFAULT: + if post_tags is not DEFAULT: kwargs["post_tags"] = post_tags - if pre_tags != DEFAULT: + if pre_tags is not DEFAULT: kwargs["pre_tags"] = pre_tags - if require_field_match != DEFAULT: + if require_field_match is not DEFAULT: kwargs["require_field_match"] = require_field_match - if tags_schema != DEFAULT: + if tags_schema is not DEFAULT: kwargs["tags_schema"] = tags_schema super().__init__(**kwargs) @@ -3033,7 +3033,7 @@ def __init__( order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order super().__init__(kwargs) @@ -3072,17 +3072,17 @@ def __init__( nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if mode != DEFAULT: + if mode is not DEFAULT: kwargs["mode"] = mode - if distance_type != DEFAULT: + if distance_type is not DEFAULT: kwargs["distance_type"] = distance_type - if ignore_unmapped != DEFAULT: + if ignore_unmapped is not DEFAULT: kwargs["ignore_unmapped"] = ignore_unmapped - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order - if unit != DEFAULT: + if unit is not DEFAULT: kwargs["unit"] = unit - if nested != DEFAULT: + if nested is not DEFAULT: kwargs["nested"] = nested super().__init__(kwargs) @@ -3114,15 +3114,15 @@ def __init__( nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if order != DEFAULT: + if order is not DEFAULT: kwargs["order"] = order - if script != DEFAULT: + if script is not DEFAULT: kwargs["script"] = script - if type != DEFAULT: + if type is not DEFAULT: kwargs["type"] = type - if mode != DEFAULT: + if mode is not DEFAULT: kwargs["mode"] = mode - if nested != DEFAULT: + if nested is not DEFAULT: kwargs["nested"] = nested super().__init__(kwargs) @@ -3156,17 +3156,17 @@ def __init__( wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if all_of != DEFAULT: + if all_of is not DEFAULT: kwargs["all_of"] = all_of - if any_of != DEFAULT: + if any_of is not DEFAULT: kwargs["any_of"] = any_of - if fuzzy != DEFAULT: + if fuzzy is not DEFAULT: kwargs["fuzzy"] = fuzzy - if match != DEFAULT: + if match is not DEFAULT: kwargs["match"] = match - if prefix != DEFAULT: + if prefix is not DEFAULT: kwargs["prefix"] = prefix - if wildcard != DEFAULT: + if wildcard is not DEFAULT: kwargs["wildcard"] = wildcard super().__init__(kwargs) @@ -3229,23 +3229,23 @@ def __init__( script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if after != DEFAULT: + if after is not DEFAULT: kwargs["after"] = after - if before != DEFAULT: + if before is not DEFAULT: kwargs["before"] = before - if contained_by != DEFAULT: + if contained_by is not DEFAULT: kwargs["contained_by"] = contained_by - if containing != DEFAULT: + if containing is not DEFAULT: kwargs["containing"] = containing - if not_contained_by != DEFAULT: + if not_contained_by is not DEFAULT: kwargs["not_contained_by"] = not_contained_by - if not_containing != DEFAULT: + if not_containing is not DEFAULT: kwargs["not_containing"] = not_containing - if not_overlapping != DEFAULT: + if not_overlapping is not DEFAULT: kwargs["not_overlapping"] = not_overlapping - if overlapping != DEFAULT: + if overlapping is not DEFAULT: kwargs["overlapping"] = overlapping - if script != DEFAULT: + if script is not DEFAULT: kwargs["script"] = script super().__init__(kwargs) @@ -3272,12 +3272,12 @@ def __init__( path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if filter != DEFAULT: + if filter is not DEFAULT: kwargs["filter"] = filter - if max_children != DEFAULT: + if max_children is not DEFAULT: kwargs["max_children"] = max_children - if nested != DEFAULT: + if nested is not DEFAULT: kwargs["nested"] = nested - if path != DEFAULT: + if path is not DEFAULT: kwargs["path"] = str(path) super().__init__(kwargs) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index cb642a84..5930c0ca 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -374,7 +374,7 @@ def __init__( _value: Union["i.CommonTermsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -635,7 +635,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if functions == DEFAULT: + if functions is DEFAULT: functions = [] for name in ScoreFunction._classes: if name in kwargs: @@ -670,7 +670,7 @@ def __init__( _value: Union["i.FuzzyQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -719,7 +719,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__( type=type, @@ -782,7 +782,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__( distance=distance, @@ -826,7 +826,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__( validation_method=validation_method, @@ -867,7 +867,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__( ignore_unmapped=ignore_unmapped, boost=boost, _name=_name, **kwargs @@ -1037,7 +1037,7 @@ def __init__( _value: Union["i.IntervalsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1118,7 +1118,7 @@ def __init__( _value: Union["i.MatchQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1183,7 +1183,7 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1241,7 +1241,7 @@ def __init__( _value: Union["i.MatchPhraseQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1266,7 +1266,7 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1701,7 +1701,7 @@ def __init__( _value: Union["i.PrefixQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1862,7 +1862,7 @@ def __init__( _value: Union["wrappers.Range[Any]", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -1940,7 +1940,7 @@ def __init__( _value: Union["i.RegexpQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2113,7 +2113,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__( ignore_unmapped=ignore_unmapped, boost=boost, _name=_name, **kwargs @@ -2463,7 +2463,7 @@ def __init__( _value: Union["i.SpanTermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2583,7 +2583,7 @@ def __init__( _value: Union["i.TermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2620,7 +2620,7 @@ def __init__( _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(boost=boost, _name=_name, **kwargs) @@ -2650,7 +2650,7 @@ def __init__( _value: Union["i.TermsSetQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2673,7 +2673,7 @@ def __init__( _value: Union["i.TextExpansionQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2695,7 +2695,7 @@ def __init__( _value: Union["i.WeightedTokensQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) @@ -2716,7 +2716,7 @@ def __init__( _value: Union["i.WildcardQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value super().__init__(**kwargs) diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/interfaces.py.tpl index 4732c104..cb595930 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/interfaces.py.tpl @@ -54,16 +54,16 @@ class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endi **kwargs: Any ): {% if k.is_single_field %} - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value {% elif k.is_multi_field %} - if _fields != DEFAULT: + if _fields is not DEFAULT: for field, value in _fields.items(): kwargs[str(field)] = value {% endif %} {% for arg in k.args %} {% if not arg.positional %} - if {{ arg.name }} != DEFAULT: + if {{ arg.name }} is not DEFAULT: {% if "InstrumentedField" in arg.type %} kwargs["{{ arg.name }}"] = str({{ arg.name }}) {% else %} diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 483066d9..abff5f6a 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -192,16 +192,16 @@ class {{ k.name }}({{ parent }}): **kwargs: Any ): {% if k.name == "FunctionScore" %} - if functions == DEFAULT: + if functions is DEFAULT: functions = [] for name in ScoreFunction._classes: if name in kwargs: functions.append({name: kwargs.pop(name)}) # type: ignore {% elif k.is_single_field %} - if _field != DEFAULT: + if _field is not DEFAULT: kwargs[str(_field)] = _value {% elif k.is_multi_field %} - if _fields != DEFAULT: + if _fields is not DEFAULT: for field, value in _fields.items(): kwargs[str(field)] = value {% endif %} From 7c812631ad3bc92ccd837367e7102fc6ddc0233a Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 16:09:44 +0100 Subject: [PATCH 16/27] rename interfaces.py to types.py --- elasticsearch_dsl/query.py | 125 +++--- elasticsearch_dsl/{interfaces.py => types.py} | 382 ++++++++++-------- tests/_async/test_search.py | 10 +- tests/_sync/test_search.py | 18 +- utils/generator.py | 24 +- utils/templates/query.py.tpl | 2 +- .../{interfaces.py.tpl => types.py.tpl} | 2 +- 7 files changed, 303 insertions(+), 260 deletions(-) rename elasticsearch_dsl/{interfaces.py => types.py} (90%) rename utils/templates/{interfaces.py.tpl => types.py.tpl} (97%) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 5930c0ca..4f1dc393 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -48,8 +48,7 @@ if TYPE_CHECKING: from elastic_transport.client_utils import DefaultType - from elasticsearch_dsl import interfaces as i - from elasticsearch_dsl import wrappers + from elasticsearch_dsl import types, wrappers from .document_base import InstrumentedField @@ -371,7 +370,9 @@ class Common(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.CommonTermsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.CommonTermsQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -623,7 +624,7 @@ def __init__( Literal["multiply", "replace", "sum", "avg", "max", "min"], "DefaultType" ] = DEFAULT, functions: Union[ - Sequence["i.FunctionScoreContainer"], Dict[str, Any], "DefaultType" + Sequence["types.FunctionScoreContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, max_boost: Union[float, "DefaultType"] = DEFAULT, min_score: Union[float, "DefaultType"] = DEFAULT, @@ -667,7 +668,7 @@ class Fuzzy(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.FuzzyQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.FuzzyQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -702,10 +703,10 @@ def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, _value: Union[ - "i.CoordsGeoBounds", - "i.TopLeftBottomRightGeoBounds", - "i.TopRightBottomLeftGeoBounds", - "i.WktGeoBounds", + "types.CoordsGeoBounds", + "types.TopLeftBottomRightGeoBounds", + "types.TopRightBottomLeftGeoBounds", + "types.WktGeoBounds", Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -764,8 +765,8 @@ def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, _value: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], @@ -816,7 +817,9 @@ class GeoPolygon(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.GeoPolygonPoints", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.GeoPolygonPoints", Dict[str, Any], "DefaultType" + ] = DEFAULT, *, validation_method: Union[ Literal["coerce", "ignore_malformed", "strict"], "DefaultType" @@ -860,7 +863,9 @@ class GeoShape(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.GeoShapeFieldQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.GeoShapeFieldQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, @@ -916,7 +921,7 @@ def __init__( query: Union[Query, "DefaultType"] = DEFAULT, type: Union[str, "DefaultType"] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, - inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, + inner_hits: Union["types.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, max_children: Union[int, "DefaultType"] = DEFAULT, min_children: Union[int, "DefaultType"] = DEFAULT, score_mode: Union[ @@ -976,7 +981,7 @@ def __init__( parent_type: Union[str, "DefaultType"] = DEFAULT, query: Union[Query, "DefaultType"] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, - inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, + inner_hits: Union["types.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, score: Union[bool, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -1034,7 +1039,7 @@ class Intervals(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.IntervalsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.IntervalsQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -1077,7 +1082,7 @@ def __init__( field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, query_vector: Union[Sequence[float], "DefaultType"] = DEFAULT, query_vector_builder: Union[ - "i.QueryVectorBuilder", Dict[str, Any], "DefaultType" + "types.QueryVectorBuilder", Dict[str, Any], "DefaultType" ] = DEFAULT, num_candidates: Union[int, "DefaultType"] = DEFAULT, k: Union[int, "DefaultType"] = DEFAULT, @@ -1115,7 +1120,7 @@ class Match(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.MatchQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.MatchQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -1179,7 +1184,7 @@ def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, _value: Union[ - "i.MatchBoolPrefixQuery", Dict[str, Any], "DefaultType" + "types.MatchBoolPrefixQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, **kwargs: Any, ): @@ -1238,7 +1243,9 @@ class MatchPhrase(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.MatchPhraseQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.MatchPhraseQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -1262,7 +1269,7 @@ def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, _value: Union[ - "i.MatchPhrasePrefixQuery", Dict[str, Any], "DefaultType" + "types.MatchPhrasePrefixQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, **kwargs: Any, ): @@ -1327,8 +1334,8 @@ def __init__( self, *, like: Union[ - Union[str, "i.LikeDocument"], - Sequence[Union[str, "i.LikeDocument"]], + Union[str, "types.LikeDocument"], + Sequence[Union[str, "types.LikeDocument"]], Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -1349,8 +1356,8 @@ def __init__( routing: Union[str, "DefaultType"] = DEFAULT, stop_words: Union[str, Sequence[str], "DefaultType"] = DEFAULT, unlike: Union[ - Union[str, "i.LikeDocument"], - Sequence[Union[str, "i.LikeDocument"]], + Union[str, "types.LikeDocument"], + Sequence[Union[str, "types.LikeDocument"]], Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -1531,7 +1538,7 @@ def __init__( path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, query: Union[Query, "DefaultType"] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, - inner_hits: Union["i.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, + inner_hits: Union["types.InnerHits", Dict[str, Any], "DefaultType"] = DEFAULT, score_mode: Union[ Literal["none", "avg", "sum", "max", "min"], "DefaultType" ] = DEFAULT, @@ -1675,7 +1682,9 @@ def __init__( *, organic: Union[Query, "DefaultType"] = DEFAULT, ids: Union[Sequence[str], "DefaultType"] = DEFAULT, - docs: Union[Sequence["i.PinnedDoc"], Dict[str, Any], "DefaultType"] = DEFAULT, + docs: Union[ + Sequence["types.PinnedDoc"], Dict[str, Any], "DefaultType" + ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -1698,7 +1707,7 @@ class Prefix(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.PrefixQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.PrefixQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -1897,16 +1906,16 @@ def __init__( *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, saturation: Union[ - "i.RankFeatureFunctionSaturation", Dict[str, Any], "DefaultType" + "types.RankFeatureFunctionSaturation", Dict[str, Any], "DefaultType" ] = DEFAULT, log: Union[ - "i.RankFeatureFunctionLogarithm", Dict[str, Any], "DefaultType" + "types.RankFeatureFunctionLogarithm", Dict[str, Any], "DefaultType" ] = DEFAULT, linear: Union[ - "i.RankFeatureFunctionLinear", Dict[str, Any], "DefaultType" + "types.RankFeatureFunctionLinear", Dict[str, Any], "DefaultType" ] = DEFAULT, sigmoid: Union[ - "i.RankFeatureFunctionSigmoid", Dict[str, Any], "DefaultType" + "types.RankFeatureFunctionSigmoid", Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -1937,7 +1946,7 @@ class Regexp(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.RegexpQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.RegexpQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2005,7 +2014,7 @@ class Script(Query): def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2040,7 +2049,7 @@ def __init__( self, *, query: Union[Query, "DefaultType"] = DEFAULT, - script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, min_score: Union[float, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -2106,7 +2115,7 @@ class Shape(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.ShapeFieldQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.ShapeFieldQuery", Dict[str, Any], "DefaultType"] = DEFAULT, *, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, @@ -2176,7 +2185,9 @@ def __init__( fields: Union[ Sequence[Union[str, "InstrumentedField"]], "DefaultType" ] = DEFAULT, - flags: Union["i.PipeSeparatedFlags", Dict[str, Any], "DefaultType"] = DEFAULT, + flags: Union[ + "types.PipeSeparatedFlags", Dict[str, Any], "DefaultType" + ] = DEFAULT, fuzzy_max_expansions: Union[int, "DefaultType"] = DEFAULT, fuzzy_prefix_length: Union[int, "DefaultType"] = DEFAULT, fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, @@ -2228,8 +2239,8 @@ class SpanContaining(Query): def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2258,7 +2269,7 @@ def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + query: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2287,7 +2298,7 @@ def __init__( self, *, end: Union[int, "DefaultType"] = DEFAULT, - match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2351,7 +2362,7 @@ def __init__( self, *, clauses: Union[ - Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" ] = DEFAULT, in_order: Union[bool, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, @@ -2398,8 +2409,8 @@ class SpanNot(Query): def __init__( self, *, - exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, dist: Union[int, "DefaultType"] = DEFAULT, post: Union[int, "DefaultType"] = DEFAULT, pre: Union[int, "DefaultType"] = DEFAULT, @@ -2438,7 +2449,7 @@ def __init__( self, *, clauses: Union[ - Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -2460,7 +2471,7 @@ class SpanTerm(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.SpanTermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.SpanTermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2489,8 +2500,8 @@ class SpanWithin(Query): def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2546,7 +2557,7 @@ def __init__( query: Union[str, "DefaultType"] = DEFAULT, prune: Union[bool, "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + "types.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -2580,7 +2591,7 @@ class Term(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.TermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.TermQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2611,7 +2622,7 @@ def __init__( _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, _value: Union[ Sequence[Union[int, float, str, bool, None, Any]], - "i.TermsLookup", + "types.TermsLookup", Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -2647,7 +2658,7 @@ class TermsSet(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.TermsSetQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.TermsSetQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2670,7 +2681,9 @@ class TextExpansion(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.TextExpansionQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.TextExpansionQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2692,7 +2705,9 @@ class WeightedTokens(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.WeightedTokensQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union[ + "types.WeightedTokensQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: @@ -2713,7 +2728,7 @@ class Wildcard(Query): def __init__( self, _field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - _value: Union["i.WildcardQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + _value: Union["types.WildcardQuery", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _field is not DEFAULT: diff --git a/elasticsearch_dsl/interfaces.py b/elasticsearch_dsl/types.py similarity index 90% rename from elasticsearch_dsl/interfaces.py rename to elasticsearch_dsl/types.py index c657bded..7a051c4d 100644 --- a/elasticsearch_dsl/interfaces.py +++ b/elasticsearch_dsl/types.py @@ -19,9 +19,7 @@ from elastic_transport.client_utils import DEFAULT, DefaultType -from elasticsearch_dsl import Query -from elasticsearch_dsl import function as f -from elasticsearch_dsl import interfaces as i +from elasticsearch_dsl import Query, function, types from elasticsearch_dsl.document_base import InstrumentedField from elasticsearch_dsl.utils import AttrDict @@ -170,24 +168,26 @@ class FunctionScoreContainer(AttrDict[Any]): :arg weight: No documentation available. """ - exp: Union["f.DecayFunction", "DefaultType"] - gauss: Union["f.DecayFunction", "DefaultType"] - linear: Union["f.DecayFunction", "DefaultType"] - field_value_factor: Union["f.FieldValueFactorScore", "DefaultType"] - random_score: Union["f.RandomScore", "DefaultType"] - script_score: Union["f.ScriptScore", "DefaultType"] + exp: Union["function.DecayFunction", "DefaultType"] + gauss: Union["function.DecayFunction", "DefaultType"] + linear: Union["function.DecayFunction", "DefaultType"] + field_value_factor: Union["function.FieldValueFactorScore", "DefaultType"] + random_score: Union["function.RandomScore", "DefaultType"] + script_score: Union["function.ScriptScore", "DefaultType"] filter: Union[Query, "DefaultType"] weight: Union[float, "DefaultType"] def __init__( self, *, - exp: Union["f.DecayFunction", "DefaultType"] = DEFAULT, - gauss: Union["f.DecayFunction", "DefaultType"] = DEFAULT, - linear: Union["f.DecayFunction", "DefaultType"] = DEFAULT, - field_value_factor: Union["f.FieldValueFactorScore", "DefaultType"] = DEFAULT, - random_score: Union["f.RandomScore", "DefaultType"] = DEFAULT, - script_score: Union["f.ScriptScore", "DefaultType"] = DEFAULT, + exp: Union["function.DecayFunction", "DefaultType"] = DEFAULT, + gauss: Union["function.DecayFunction", "DefaultType"] = DEFAULT, + linear: Union["function.DecayFunction", "DefaultType"] = DEFAULT, + field_value_factor: Union[ + "function.FieldValueFactorScore", "DefaultType" + ] = DEFAULT, + random_score: Union["function.RandomScore", "DefaultType"] = DEFAULT, + script_score: Union["function.ScriptScore", "DefaultType"] = DEFAULT, filter: Union[Query, "DefaultType"] = DEFAULT, weight: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -291,7 +291,9 @@ class GeoPolygonPoints(AttrDict[Any]): points: Union[ Sequence[ - Union["i.LatLonGeoLocation", "i.GeoHashLocation", Sequence[float], str] + Union[ + "types.LatLonGeoLocation", "types.GeoHashLocation", Sequence[float], str + ] ], Dict[str, Any], "DefaultType", @@ -302,7 +304,12 @@ def __init__( *, points: Union[ Sequence[ - Union["i.LatLonGeoLocation", "i.GeoHashLocation", Sequence[float], str] + Union[ + "types.LatLonGeoLocation", + "types.GeoHashLocation", + Sequence[float], + str, + ] ], Dict[str, Any], "DefaultType", @@ -323,7 +330,7 @@ class GeoShapeFieldQuery(AttrDict[Any]): """ shape: Any - indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] + indexed_shape: Union["types.FieldLookup", Dict[str, Any], "DefaultType"] relation: Union[ Literal["intersects", "disjoint", "within", "contains"], "DefaultType" ] @@ -332,7 +339,9 @@ def __init__( self, *, shape: Any = DEFAULT, - indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] = DEFAULT, + indexed_shape: Union[ + "types.FieldLookup", Dict[str, Any], "DefaultType" + ] = DEFAULT, relation: Union[ Literal["intersects", "disjoint", "within", "contains"], "DefaultType" ] = DEFAULT, @@ -373,13 +382,15 @@ class InnerHits(AttrDict[Any]): name: Union[str, "DefaultType"] size: Union[int, "DefaultType"] from_: Union[int, "DefaultType"] - collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] - docvalue_fields: Union[Sequence["i.FieldAndFormat"], Dict[str, Any], "DefaultType"] + collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] + docvalue_fields: Union[ + Sequence["types.FieldAndFormat"], Dict[str, Any], "DefaultType" + ] explain: Union[bool, "DefaultType"] - highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] + highlight: Union["types.Highlight", Dict[str, Any], "DefaultType"] ignore_unmapped: Union[bool, "DefaultType"] script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Mapping[Union[str, "InstrumentedField"], "types.ScriptField"], Dict[str, Any], "DefaultType", ] @@ -390,12 +401,12 @@ class InnerHits(AttrDict[Any]): "DefaultType", ] sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - Sequence[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Union[Union[str, "InstrumentedField"], "types.SortOptions"], + Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]], Dict[str, Any], "DefaultType", ] - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] + _source: Union[bool, "types.SourceFilter", Dict[str, Any], "DefaultType"] stored_fields: Union[ Union[str, "InstrumentedField"], Sequence[Union[str, "InstrumentedField"]], @@ -410,15 +421,15 @@ def __init__( name: Union[str, "DefaultType"] = DEFAULT, size: Union[int, "DefaultType"] = DEFAULT, from_: Union[int, "DefaultType"] = DEFAULT, - collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, + collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, docvalue_fields: Union[ - Sequence["i.FieldAndFormat"], Dict[str, Any], "DefaultType" + Sequence["types.FieldAndFormat"], Dict[str, Any], "DefaultType" ] = DEFAULT, explain: Union[bool, "DefaultType"] = DEFAULT, - highlight: Union["i.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT, + highlight: Union["types.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT, ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.ScriptField"], + Mapping[Union[str, "InstrumentedField"], "types.ScriptField"], Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -429,12 +440,14 @@ def __init__( "DefaultType", ] = DEFAULT, sort: Union[ - Union[Union[str, "InstrumentedField"], "i.SortOptions"], - Sequence[Union[Union[str, "InstrumentedField"], "i.SortOptions"]], + Union[Union[str, "InstrumentedField"], "types.SortOptions"], + Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]], Dict[str, Any], "DefaultType", ] = DEFAULT, - _source: Union[bool, "i.SourceFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + _source: Union[ + bool, "types.SourceFilter", Dict[str, Any], "DefaultType" + ] = DEFAULT, stored_fields: Union[ Union[str, "InstrumentedField"], Sequence[Union[str, "InstrumentedField"]], @@ -497,24 +510,26 @@ class IntervalsQuery(QueryBase): :arg _name: No documentation available. """ - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] - match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] + all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] + any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] + fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] + match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] + prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] + wildcard: Union["types.IntervalsWildcard", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, - match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, + all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, + any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, + fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, + prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, + wildcard: Union[ + "types.IntervalsWildcard", Dict[str, Any], "DefaultType" + ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -1001,13 +1016,13 @@ class QueryVectorBuilder(AttrDict[Any]): :arg text_embedding: No documentation available. """ - text_embedding: Union["i.TextEmbedding", Dict[str, Any], "DefaultType"] + text_embedding: Union["types.TextEmbedding", Dict[str, Any], "DefaultType"] def __init__( self, *, text_embedding: Union[ - "i.TextEmbedding", Dict[str, Any], "DefaultType" + "types.TextEmbedding", Dict[str, Any], "DefaultType" ] = DEFAULT, **kwargs: Any, ): @@ -1185,7 +1200,7 @@ class ShapeFieldQuery(AttrDict[Any]): Well Known Text (WKT) format. """ - indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] + indexed_shape: Union["types.FieldLookup", Dict[str, Any], "DefaultType"] relation: Union[ Literal["intersects", "disjoint", "within", "contains"], "DefaultType" ] @@ -1194,7 +1209,9 @@ class ShapeFieldQuery(AttrDict[Any]): def __init__( self, *, - indexed_shape: Union["i.FieldLookup", Dict[str, Any], "DefaultType"] = DEFAULT, + indexed_shape: Union[ + "types.FieldLookup", Dict[str, Any], "DefaultType" + ] = DEFAULT, relation: Union[ Literal["intersects", "disjoint", "within", "contains"], "DefaultType" ] = DEFAULT, @@ -1235,47 +1252,53 @@ class SpanQuery(AttrDict[Any]): other span queries. """ - span_containing: Union["i.SpanContainingQuery", Dict[str, Any], "DefaultType"] - span_field_masking: Union["i.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType"] - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "DefaultType"] + span_containing: Union["types.SpanContainingQuery", Dict[str, Any], "DefaultType"] + span_field_masking: Union[ + "types.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" + ] + span_first: Union["types.SpanFirstQuery", Dict[str, Any], "DefaultType"] span_gap: Union[Mapping[Union[str, "InstrumentedField"], int], "DefaultType"] - span_multi: Union["i.SpanMultiTermQuery", Dict[str, Any], "DefaultType"] - span_near: Union["i.SpanNearQuery", Dict[str, Any], "DefaultType"] - span_not: Union["i.SpanNotQuery", Dict[str, Any], "DefaultType"] - span_or: Union["i.SpanOrQuery", Dict[str, Any], "DefaultType"] + span_multi: Union["types.SpanMultiTermQuery", Dict[str, Any], "DefaultType"] + span_near: Union["types.SpanNearQuery", Dict[str, Any], "DefaultType"] + span_not: Union["types.SpanNotQuery", Dict[str, Any], "DefaultType"] + span_or: Union["types.SpanOrQuery", Dict[str, Any], "DefaultType"] span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], + Mapping[Union[str, "InstrumentedField"], "types.SpanTermQuery"], Dict[str, Any], "DefaultType", ] - span_within: Union["i.SpanWithinQuery", Dict[str, Any], "DefaultType"] + span_within: Union["types.SpanWithinQuery", Dict[str, Any], "DefaultType"] def __init__( self, *, span_containing: Union[ - "i.SpanContainingQuery", Dict[str, Any], "DefaultType" + "types.SpanContainingQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, span_field_masking: Union[ - "i.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" + "types.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, + span_first: Union[ + "types.SpanFirstQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, - span_first: Union["i.SpanFirstQuery", Dict[str, Any], "DefaultType"] = DEFAULT, span_gap: Union[ Mapping[Union[str, "InstrumentedField"], int], "DefaultType" ] = DEFAULT, span_multi: Union[ - "i.SpanMultiTermQuery", Dict[str, Any], "DefaultType" + "types.SpanMultiTermQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, - span_near: Union["i.SpanNearQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - span_not: Union["i.SpanNotQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - span_or: Union["i.SpanOrQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + span_near: Union[ + "types.SpanNearQuery", Dict[str, Any], "DefaultType" + ] = DEFAULT, + span_not: Union["types.SpanNotQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + span_or: Union["types.SpanOrQuery", Dict[str, Any], "DefaultType"] = DEFAULT, span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "i.SpanTermQuery"], + Mapping[Union[str, "InstrumentedField"], "types.SpanTermQuery"], Dict[str, Any], "DefaultType", ] = DEFAULT, span_within: Union[ - "i.SpanWithinQuery", Dict[str, Any], "DefaultType" + "types.SpanWithinQuery", Dict[str, Any], "DefaultType" ] = DEFAULT, **kwargs: Any, ): @@ -1424,7 +1447,7 @@ class TermsSetQuery(QueryBase): """ minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] - minimum_should_match_script: Union["i.Script", Dict[str, Any], "DefaultType"] + minimum_should_match_script: Union["types.Script", Dict[str, Any], "DefaultType"] terms: Union[Sequence[str], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -1436,7 +1459,7 @@ def __init__( str, "InstrumentedField", "DefaultType" ] = DEFAULT, minimum_should_match_script: Union[ - "i.Script", Dict[str, Any], "DefaultType" + "types.Script", Dict[str, Any], "DefaultType" ] = DEFAULT, terms: Union[Sequence[str], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, @@ -1471,7 +1494,7 @@ class TextExpansionQuery(QueryBase): model_id: Union[str, "DefaultType"] model_text: Union[str, "DefaultType"] - pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] + pruning_config: Union["types.TokenPruningConfig", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -1481,7 +1504,7 @@ def __init__( model_id: Union[str, "DefaultType"] = DEFAULT, model_text: Union[str, "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + "types.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -1539,16 +1562,16 @@ class TopLeftBottomRightGeoBounds(AttrDict[Any]): """ top_left: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], "DefaultType", ] bottom_right: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], @@ -1559,16 +1582,16 @@ def __init__( self, *, top_left: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], "DefaultType", ] = DEFAULT, bottom_right: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], @@ -1590,16 +1613,16 @@ class TopRightBottomLeftGeoBounds(AttrDict[Any]): """ top_right: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], "DefaultType", ] bottom_left: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], @@ -1610,16 +1633,16 @@ def __init__( self, *, top_right: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], "DefaultType", ] = DEFAULT, bottom_left: Union[ - "i.LatLonGeoLocation", - "i.GeoHashLocation", + "types.LatLonGeoLocation", + "types.GeoHashLocation", Sequence[float], str, Dict[str, Any], @@ -1647,7 +1670,7 @@ class WeightedTokensQuery(QueryBase): """ tokens: Union[Mapping[str, float], "DefaultType"] - pruning_config: Union["i.TokenPruningConfig", Dict[str, Any], "DefaultType"] + pruning_config: Union["types.TokenPruningConfig", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -1656,7 +1679,7 @@ def __init__( *, tokens: Union[Mapping[str, float], "DefaultType"] = DEFAULT, pruning_config: Union[ - "i.TokenPruningConfig", Dict[str, Any], "DefaultType" + "types.TokenPruningConfig", Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -1782,20 +1805,23 @@ class FieldCollapse(AttrDict[Any]): field: Union[str, "InstrumentedField", "DefaultType"] inner_hits: Union[ - "i.InnerHits", Sequence["i.InnerHits"], Dict[str, Any], "DefaultType" + "types.InnerHits", Sequence["types.InnerHits"], Dict[str, Any], "DefaultType" ] max_concurrent_group_searches: Union[int, "DefaultType"] - collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] + collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, inner_hits: Union[ - "i.InnerHits", Sequence["i.InnerHits"], Dict[str, Any], "DefaultType" + "types.InnerHits", + Sequence["types.InnerHits"], + Dict[str, Any], + "DefaultType", ] = DEFAULT, max_concurrent_group_searches: Union[int, "DefaultType"] = DEFAULT, - collapse: Union["i.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, + collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if field is not DEFAULT: @@ -2063,7 +2089,7 @@ class Highlight(HighlightBase): encoder: Union[Literal["default", "html"], "DefaultType"] fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], Dict[str, Any], "DefaultType", ] @@ -2094,7 +2120,7 @@ def __init__( *, encoder: Union[Literal["default", "html"], "DefaultType"] = DEFAULT, fields: Union[ - Mapping[Union[str, "InstrumentedField"], "i.HighlightField"], + Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], Dict[str, Any], "DefaultType", ] = DEFAULT, @@ -2178,13 +2204,13 @@ class ScriptField(AttrDict[Any]): :arg ignore_failure: No documentation available. """ - script: Union["i.Script", Dict[str, Any], "DefaultType"] + script: Union["types.Script", Dict[str, Any], "DefaultType"] ignore_failure: Union[bool, "DefaultType"] def __init__( self, *, - script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, ignore_failure: Union[bool, "DefaultType"] = DEFAULT, **kwargs: Any, ): @@ -2203,20 +2229,20 @@ class SortOptions(AttrDict[Any]): :arg _script: No documentation available. """ - _score: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] - _doc: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] - _geo_distance: Union["i.GeoDistanceSort", Dict[str, Any], "DefaultType"] - _script: Union["i.ScriptSort", Dict[str, Any], "DefaultType"] + _score: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] + _doc: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] + _geo_distance: Union["types.GeoDistanceSort", Dict[str, Any], "DefaultType"] + _script: Union["types.ScriptSort", Dict[str, Any], "DefaultType"] def __init__( self, *, - _score: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, - _doc: Union["i.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _score: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _doc: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, _geo_distance: Union[ - "i.GeoDistanceSort", Dict[str, Any], "DefaultType" + "types.GeoDistanceSort", Dict[str, Any], "DefaultType" ] = DEFAULT, - _script: Union["i.ScriptSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _script: Union["types.ScriptSort", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if _score is not DEFAULT: @@ -2282,20 +2308,22 @@ class IntervalsAllOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] + intervals: Union[ + Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" + ] max_gaps: Union[int, "DefaultType"] ordered: Union[bool, "DefaultType"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, intervals: Union[ - Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, max_gaps: Union[int, "DefaultType"] = DEFAULT, ordered: Union[bool, "DefaultType"] = DEFAULT, - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if intervals is not DEFAULT: @@ -2315,16 +2343,18 @@ class IntervalsAnyOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] + intervals: Union[ + Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" + ] + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, intervals: Union[ - Sequence["i.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" ] = DEFAULT, - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if intervals is not DEFAULT: @@ -2402,7 +2432,7 @@ class IntervalsMatch(AttrDict[Any]): ordered: Union[bool, "DefaultType"] query: Union[str, "DefaultType"] use_field: Union[str, "InstrumentedField", "DefaultType"] - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, @@ -2412,7 +2442,7 @@ def __init__( ordered: Union[bool, "DefaultType"] = DEFAULT, query: Union[str, "DefaultType"] = DEFAULT, use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - filter: Union["i.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if analyzer is not DEFAULT: @@ -2531,16 +2561,16 @@ class SpanContainingQuery(QueryBase): :arg _name: No documentation available. """ - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2569,7 +2599,7 @@ class SpanFieldMaskingQuery(QueryBase): """ field: Union[str, "InstrumentedField", "DefaultType"] - query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + query: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -2577,7 +2607,7 @@ def __init__( self, *, field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - query: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + query: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2607,7 +2637,7 @@ class SpanFirstQuery(QueryBase): """ end: Union[int, "DefaultType"] - match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + match: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -2615,7 +2645,7 @@ def __init__( self, *, end: Union[int, "DefaultType"] = DEFAULT, - match: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -2678,7 +2708,7 @@ class SpanNearQuery(QueryBase): :arg _name: No documentation available. """ - clauses: Union[Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType"] + clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] in_order: Union[bool, "DefaultType"] slop: Union[int, "DefaultType"] boost: Union[float, "DefaultType"] @@ -2688,7 +2718,7 @@ def __init__( self, *, clauses: Union[ - Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" ] = DEFAULT, in_order: Union[bool, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, @@ -2730,8 +2760,8 @@ class SpanNotQuery(QueryBase): """ dist: Union[int, "DefaultType"] - exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] - include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] + include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] post: Union[int, "DefaultType"] pre: Union[int, "DefaultType"] boost: Union[float, "DefaultType"] @@ -2741,8 +2771,8 @@ def __init__( self, *, dist: Union[int, "DefaultType"] = DEFAULT, - exclude: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - include: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, post: Union[int, "DefaultType"] = DEFAULT, pre: Union[int, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, @@ -2777,7 +2807,7 @@ class SpanOrQuery(QueryBase): :arg _name: No documentation available. """ - clauses: Union[Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType"] + clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -2785,7 +2815,7 @@ def __init__( self, *, clauses: Union[ - Sequence["i.SpanQuery"], Dict[str, Any], "DefaultType" + Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" ] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, @@ -2814,16 +2844,16 @@ class SpanWithinQuery(QueryBase): :arg _name: No documentation available. """ - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, - big: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["i.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, @@ -3055,7 +3085,7 @@ class GeoDistanceSort(AttrDict[Any]): unit: Union[ Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" ] - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] def __init__( self, @@ -3069,7 +3099,7 @@ def __init__( unit: Union[ Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" ] = DEFAULT, - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if mode is not DEFAULT: @@ -3097,21 +3127,21 @@ class ScriptSort(AttrDict[Any]): """ order: Union[Literal["asc", "desc"], "DefaultType"] - script: Union["i.Script", Dict[str, Any], "DefaultType"] + script: Union["types.Script", Dict[str, Any], "DefaultType"] type: Union[Literal["string", "number", "version"], "DefaultType"] mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] def __init__( self, *, order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, - script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, type: Union[Literal["string", "number", "version"], "DefaultType"] = DEFAULT, mode: Union[ Literal["min", "max", "sum", "avg", "median"], "DefaultType" ] = DEFAULT, - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if order is not DEFAULT: @@ -3138,22 +3168,24 @@ class IntervalsContainer(AttrDict[Any]): :arg wildcard: Matches terms using a wildcard pattern. """ - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] - match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] + all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] + any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] + fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] + match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] + prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] + wildcard: Union["types.IntervalsWildcard", Dict[str, Any], "DefaultType"] def __init__( self, *, - all_of: Union["i.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, - any_of: Union["i.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, - fuzzy: Union["i.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, - match: Union["i.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, - prefix: Union["i.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, - wildcard: Union["i.IntervalsWildcard", Dict[str, Any], "DefaultType"] = DEFAULT, + all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, + any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, + fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, + match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, + prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, + wildcard: Union[ + "types.IntervalsWildcard", Dict[str, Any], "DefaultType" + ] = DEFAULT, **kwargs: Any, ): if all_of is not DEFAULT: @@ -3193,40 +3225,44 @@ class IntervalsFilter(AttrDict[Any]): must return a boolean value: `true` or `false`. """ - after: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - before: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - contained_by: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - containing: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_contained_by: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_containing: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_overlapping: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - overlapping: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] - script: Union["i.Script", Dict[str, Any], "DefaultType"] + after: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + before: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + contained_by: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + containing: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_contained_by: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_containing: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + not_overlapping: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + overlapping: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] + script: Union["types.Script", Dict[str, Any], "DefaultType"] def __init__( self, *, - after: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] = DEFAULT, - before: Union["i.IntervalsContainer", Dict[str, Any], "DefaultType"] = DEFAULT, + after: Union[ + "types.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, + before: Union[ + "types.IntervalsContainer", Dict[str, Any], "DefaultType" + ] = DEFAULT, contained_by: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, containing: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, not_contained_by: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, not_containing: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, not_overlapping: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, overlapping: Union[ - "i.IntervalsContainer", Dict[str, Any], "DefaultType" + "types.IntervalsContainer", Dict[str, Any], "DefaultType" ] = DEFAULT, - script: Union["i.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): if after is not DEFAULT: @@ -3260,7 +3296,7 @@ class NestedSortValue(AttrDict[Any]): filter: Union[Query, "DefaultType"] max_children: Union[int, "DefaultType"] - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] path: Union[str, "InstrumentedField", "DefaultType"] def __init__( @@ -3268,7 +3304,7 @@ def __init__( *, filter: Union[Query, "DefaultType"] = DEFAULT, max_children: Union[int, "DefaultType"] = DEFAULT, - nested: Union["i.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): diff --git a/tests/_async/test_search.py b/tests/_async/test_search.py index cfb2d269..8a338da9 100644 --- a/tests/_async/test_search.py +++ b/tests/_async/test_search.py @@ -26,8 +26,8 @@ AsyncSearch, Document, Q, - interfaces, query, + types, wrappers, ) from elasticsearch_dsl.exceptions import IllegalOperation @@ -541,8 +541,8 @@ def test_reverse() -> None: def test_code_generated_classes() -> None: s = AsyncSearch() s = ( - s.query(query.Match("title", interfaces.MatchQuery(query="python"))) - .query(~query.Match("title", interfaces.MatchQuery(query="ruby"))) + s.query(query.Match("title", types.MatchQuery(query="python"))) + .query(~query.Match("title", types.MatchQuery(query="ruby"))) .query( query.Knn( field="title", @@ -553,8 +553,8 @@ def test_code_generated_classes() -> None: ) ) .filter( - query.Term("category", interfaces.TermQuery(value="meetup")) - | query.Term("category", interfaces.TermQuery(value="conference")) + query.Term("category", types.TermQuery(value="meetup")) + | query.Term("category", types.TermQuery(value="conference")) ) .collapse("user_id") .post_filter(query.Terms(tags=["prague", "czech"])) diff --git a/tests/_sync/test_search.py b/tests/_sync/test_search.py index 30a01188..ee87b788 100644 --- a/tests/_sync/test_search.py +++ b/tests/_sync/test_search.py @@ -21,15 +21,7 @@ import pytest from pytest import raises -from elasticsearch_dsl import ( - Document, - EmptySearch, - Q, - Search, - interfaces, - query, - wrappers, -) +from elasticsearch_dsl import Document, EmptySearch, Q, Search, query, types, wrappers from elasticsearch_dsl.exceptions import IllegalOperation @@ -541,8 +533,8 @@ def test_reverse() -> None: def test_code_generated_classes() -> None: s = Search() s = ( - s.query(query.Match("title", interfaces.MatchQuery(query="python"))) - .query(~query.Match("title", interfaces.MatchQuery(query="ruby"))) + s.query(query.Match("title", types.MatchQuery(query="python"))) + .query(~query.Match("title", types.MatchQuery(query="ruby"))) .query( query.Knn( field="title", @@ -553,8 +545,8 @@ def test_code_generated_classes() -> None: ) ) .filter( - query.Term("category", interfaces.TermQuery(value="meetup")) - | query.Term("category", interfaces.TermQuery(value="conference")) + query.Term("category", types.TermQuery(value="meetup")) + | query.Term("category", types.TermQuery(value="conference")) ) .collapse("user_id") .post_filter(query.Terms(tags=["prague", "czech"])) diff --git a/utils/generator.py b/utils/generator.py index 67fdf53c..585fa5db 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -31,7 +31,7 @@ lstrip_blocks=True, ) query_py = jinja_env.get_template("query.py.tpl") -interfaces_py = jinja_env.get_template("interfaces.py.tpl") +types_py = jinja_env.get_template("types.py.tpl") # map with name replacements for Elasticsearch attributes PROP_REPLACEMENTS = {"from": "from_"} @@ -90,7 +90,7 @@ def __init__(self): # Interfaces collects interfaces that are seen while traversing the schema. # Any interfaces collected here are then rendered as Python in the - # interfaces.py module. + # types.py module. self.interfaces = [] def find_type(self, name, namespace=None): @@ -182,7 +182,7 @@ def get_python_type(self, schema_type): # for now we treat PipeSeparatedFlags as a special case if "PipeSeparatedFlags" not in self.interfaces: self.interfaces.append("PipeSeparatedFlags") - return '"i.PipeSeparatedFlags"', None + return '"types.PipeSeparatedFlags"', None else: # generic union type types = list( @@ -211,11 +211,11 @@ def get_python_type(self, schema_type): return '"wrappers.Range[Any]"', None elif schema_type["name"]["name"].endswith("ScoreFunction"): name = schema_type["name"]["name"][:-8] - return f'"f.{name}"', None + return f'"function.{name}"', None elif schema_type["name"]["name"].endswith("DecayFunction"): - return '"f.DecayFunction"', None + return '"function.DecayFunction"', None elif schema_type["name"]["name"].endswith("Function"): - return f"\"f.{schema_type['name']['name']}\"", None + return f"\"function.{schema_type['name']['name']}\"", None elif schema_type["name"]["namespace"] == "_types.analysis" and schema_type[ "name" ]["name"].endswith("Analyzer"): @@ -226,7 +226,7 @@ def get_python_type(self, schema_type): # and add the interface to the interfaces.py module if schema_type["name"]["name"] not in self.interfaces: self.interfaces.append(schema_type["name"]["name"]) - return f"\"i.{schema_type['name']['name']}\"", None + return f"\"types.{schema_type['name']['name']}\"", None elif schema_type["kind"] == "user_defined_value": # user_defined_value maps to Python's Any type return "Any", None @@ -248,7 +248,7 @@ def get_attribute_data(self, arg): type_ = "Any" param = None if type_ != "Any": - if "i." in type_: + if "types." in type_: type_ = add_dict_type(type_) # interfaces can be given as dicts type_ = add_not_set(type_) required = "(required) " if arg["required"] else "" @@ -487,8 +487,8 @@ def generate_query_py(schema, filename): print(f"Generated {filename}.") -def generate_interfaces_py(schema, filename): - """Generate interfaces.py""" +def generate_types_py(schema, filename): + """Generate types.py""" classes = {} schema.interfaces = sorted(schema.interfaces) for interface in schema.interfaces: @@ -515,11 +515,11 @@ def generate_interfaces_py(schema, filename): parent = classes[parent].get("parent") with open(filename, "wt") as f: - f.write(interfaces_py.render(classes=classes_list)) + f.write(types_py.render(classes=classes_list)) print(f"Generated {filename}.") if __name__ == "__main__": schema = ElasticsearchSchema() generate_query_py(schema, "elasticsearch_dsl/query.py") - generate_interfaces_py(schema, "elasticsearch_dsl/interfaces.py") + generate_types_py(schema, "elasticsearch_dsl/types.py") diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index abff5f6a..7016b52c 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -48,7 +48,7 @@ from .utils import DslBase if TYPE_CHECKING: from elastic_transport.client_utils import DefaultType from .document_base import InstrumentedField - from elasticsearch_dsl import interfaces as i, wrappers + from elasticsearch_dsl import types, wrappers _T = TypeVar("_T") _M = TypeVar("_M", bound=Mapping[str, Any]) diff --git a/utils/templates/interfaces.py.tpl b/utils/templates/types.py.tpl similarity index 97% rename from utils/templates/interfaces.py.tpl rename to utils/templates/types.py.tpl index cb595930..85bedb87 100644 --- a/utils/templates/interfaces.py.tpl +++ b/utils/templates/types.py.tpl @@ -20,7 +20,7 @@ from typing import Any, Dict, Literal, Mapping, Sequence, Union from elastic_transport.client_utils import DEFAULT, DefaultType from elasticsearch_dsl.document_base import InstrumentedField -from elasticsearch_dsl import function as f, interfaces as i, Query +from elasticsearch_dsl import function, types, Query from elasticsearch_dsl.utils import AttrDict PipeSeparatedFlags = str From 819b79b4dcc0dd18514c9ed9412535753841d005 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 16:18:37 +0100 Subject: [PATCH 17/27] leave undocumented classes and attributes with an empty docstring --- elasticsearch_dsl/query.py | 124 +++++++++--------- elasticsearch_dsl/types.py | 238 +++++++++++++++++------------------ utils/generator.py | 6 +- utils/templates/query.py.tpl | 2 + 4 files changed, 182 insertions(+), 188 deletions(-) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 4f1dc393..6b05067a 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -168,7 +168,7 @@ class Bool(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "bool" @@ -328,7 +328,7 @@ class Boosting(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "boosting" @@ -359,8 +359,6 @@ def __init__( class Common(Query): """ - No documentation available. - :arg _field: The field to use in this query. :arg _value: The query value for the field. """ @@ -405,7 +403,7 @@ class CombinedFields(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "combined_fields" @@ -452,7 +450,7 @@ class ConstantScore(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "constant_score" @@ -490,7 +488,7 @@ class DisMax(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "dis_max" @@ -540,7 +538,7 @@ class DistanceFeature(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "distance_feature" @@ -570,7 +568,7 @@ class Exists(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "exists" @@ -607,7 +605,7 @@ class FunctionScore(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "function_score" @@ -682,7 +680,7 @@ class GeoBoundingBox(Query): :arg _field: The field to use in this query. :arg _value: The query value for the field. - :arg type: No documentation available. + :arg type: :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude. Set to `COERCE` to also try to infer correct latitude or longitude. @@ -694,7 +692,7 @@ class GeoBoundingBox(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "geo_bounding_box" @@ -756,7 +754,7 @@ class GeoDistance(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "geo_distance" @@ -798,18 +796,16 @@ def __init__( class GeoPolygon(Query): """ - No documentation available. - :arg _field: The field to use in this query. :arg _value: The query value for the field. - :arg validation_method: No documentation available. - :arg ignore_unmapped: No documentation available. + :arg validation_method: + :arg ignore_unmapped: :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "geo_polygon" @@ -855,7 +851,7 @@ class GeoShape(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "geo_shape" @@ -907,7 +903,7 @@ class HasChild(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "has_child" @@ -967,7 +963,7 @@ class HasParent(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "has_parent" @@ -1010,7 +1006,7 @@ class Ids(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "ids" @@ -1068,7 +1064,7 @@ class Knn(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "knn" @@ -1137,7 +1133,7 @@ class MatchAll(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "match_all" @@ -1202,7 +1198,7 @@ class MatchNone(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "match_none" @@ -1313,19 +1309,19 @@ class MoreLikeThis(Query): are ignored from the input document. :arg min_word_length: The minimum word length below which the terms are ignored. - :arg routing: No documentation available. + :arg routing: :arg stop_words: An array of stop words. Any word in this set is ignored. :arg unlike: Used in combination with `like` to exclude documents that match a set of terms. - :arg version: No documentation available. - :arg version_type: No documentation available. + :arg version: + :arg version_type: :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "more_like_this" @@ -1406,7 +1402,7 @@ class MultiMatch(Query): into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. - :arg cutoff_frequency: No documentation available. + :arg cutoff_frequency: :arg fields: The fields to be queried. Defaults to the `index.query.default_field` index settings, which in turn defaults to `*`. @@ -1439,7 +1435,7 @@ class MultiMatch(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "multi_match" @@ -1524,7 +1520,7 @@ class Nested(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "nested" @@ -1571,7 +1567,7 @@ class ParentId(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "parent_id" @@ -1616,7 +1612,7 @@ class Percolate(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "percolate" @@ -1669,7 +1665,7 @@ class Pinned(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "pinned" @@ -1738,7 +1734,7 @@ class QueryString(Query): the query string if no operators are specified. :arg enable_position_increments: If `true`, enable position increments in queries constructed from a `query_string` search. - :arg escape: No documentation available. + :arg escape: :arg fields: Array of fields to search. Supports wildcards (`*`). :arg fuzziness: Maximum edit distance allowed for fuzzy matching. :arg fuzzy_max_expansions: Maximum number of terms to which the query @@ -1774,7 +1770,7 @@ class QueryString(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "query_string" @@ -1896,7 +1892,7 @@ class RankFeature(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "rank_feature" @@ -1956,17 +1952,15 @@ def __init__( class Rule(Query): """ - No documentation available. - - :arg organic: (required) No documentation available. - :arg ruleset_ids: (required) No documentation available. - :arg match_criteria: (required) No documentation available. + :arg organic: (required) + :arg ruleset_ids: (required) + :arg match_criteria: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "rule" @@ -2006,7 +2000,7 @@ class Script(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "script" @@ -2037,7 +2031,7 @@ class ScriptScore(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "script_score" @@ -2077,7 +2071,7 @@ class Semantic(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "semantic" @@ -2107,7 +2101,7 @@ class Shape(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "shape" @@ -2169,7 +2163,7 @@ class SimpleQueryString(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "simple_query_string" @@ -2231,7 +2225,7 @@ class SpanContaining(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_containing" @@ -2253,14 +2247,14 @@ class SpanFieldMasking(Query): Wrapper to allow span queries to participate in composite single-field span queries by _lying_ about their search field. - :arg field: (required) No documentation available. - :arg query: (required) No documentation available. + :arg field: (required) + :arg query: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_field_masking" @@ -2289,7 +2283,7 @@ class SpanFirst(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_first" @@ -2319,7 +2313,7 @@ class SpanMulti(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_multi" @@ -2353,7 +2347,7 @@ class SpanNear(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_near" @@ -2401,7 +2395,7 @@ class SpanNot(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_not" @@ -2440,7 +2434,7 @@ class SpanOr(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_or" @@ -2492,7 +2486,7 @@ class SpanWithin(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "span_within" @@ -2543,7 +2537,7 @@ class SparseVector(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "sparse_vector" @@ -2612,7 +2606,7 @@ class Terms(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "terms" @@ -2747,7 +2741,7 @@ class Wrapper(Query): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "wrapper" @@ -2765,15 +2759,13 @@ def __init__( class Type(Query): """ - No documentation available. - - :arg value: (required) No documentation available. + :arg value: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ name = "type" diff --git a/elasticsearch_dsl/types.py b/elasticsearch_dsl/types.py index 7a051c4d..be31b9e1 100644 --- a/elasticsearch_dsl/types.py +++ b/elasticsearch_dsl/types.py @@ -33,7 +33,7 @@ class QueryBase(AttrDict[Any]): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ boost: Union[float, "DefaultType"] @@ -55,18 +55,18 @@ def __init__( class CommonTermsQuery(QueryBase): """ - :arg analyzer: No documentation available. - :arg cutoff_frequency: No documentation available. - :arg high_freq_operator: No documentation available. - :arg low_freq_operator: No documentation available. - :arg minimum_should_match: No documentation available. - :arg query: (required) No documentation available. + :arg analyzer: + :arg cutoff_frequency: + :arg high_freq_operator: + :arg low_freq_operator: + :arg minimum_should_match: + :arg query: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ analyzer: Union[str, "DefaultType"] @@ -112,10 +112,10 @@ def __init__( class CoordsGeoBounds(AttrDict[Any]): """ - :arg top: (required) No documentation available. - :arg bottom: (required) No documentation available. - :arg left: (required) No documentation available. - :arg right: (required) No documentation available. + :arg top: (required) + :arg bottom: (required) + :arg left: (required) + :arg right: (required) """ top: Union[float, "DefaultType"] @@ -164,8 +164,8 @@ class FunctionScoreContainer(AttrDict[Any]): :arg script_score: Enables you to wrap another query and customize the scoring of it optionally with a computation derived from other numeric field values in the doc using a script expression. - :arg filter: No documentation available. - :arg weight: No documentation available. + :arg filter: + :arg weight: """ exp: Union["function.DecayFunction", "DefaultType"] @@ -227,7 +227,7 @@ class FuzzyQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ max_expansions: Union[int, "DefaultType"] @@ -273,7 +273,7 @@ def __init__( class GeoHashLocation(AttrDict[Any]): """ - :arg geohash: (required) No documentation available. + :arg geohash: (required) """ geohash: Union[str, "DefaultType"] @@ -286,7 +286,7 @@ def __init__(self, *, geohash: Union[str, "DefaultType"] = DEFAULT, **kwargs: An class GeoPolygonPoints(AttrDict[Any]): """ - :arg points: (required) No documentation available. + :arg points: (required) """ points: Union[ @@ -323,7 +323,7 @@ def __init__( class GeoShapeFieldQuery(AttrDict[Any]): """ - :arg shape: No documentation available. + :arg shape: :arg indexed_shape: Query using an indexed shape retrieved from the the specified document and path. :arg relation: Spatial relation operator used to search a geo field. @@ -363,20 +363,20 @@ class InnerHits(AttrDict[Any]): hits. :arg size: The maximum number of hits to return per `inner_hits`. :arg from: Inner hit starting document offset. - :arg collapse: No documentation available. - :arg docvalue_fields: No documentation available. - :arg explain: No documentation available. - :arg highlight: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg script_fields: No documentation available. - :arg seq_no_primary_term: No documentation available. - :arg fields: No documentation available. + :arg collapse: + :arg docvalue_fields: + :arg explain: + :arg highlight: + :arg ignore_unmapped: + :arg script_fields: + :arg seq_no_primary_term: + :arg fields: :arg sort: How the inner hits should be sorted per `inner_hits`. By default, inner hits are sorted by score. - :arg _source: No documentation available. - :arg stored_fields: No documentation available. - :arg track_scores: No documentation available. - :arg version: No documentation available. + :arg _source: + :arg stored_fields: + :arg track_scores: + :arg version: """ name: Union[str, "DefaultType"] @@ -507,7 +507,7 @@ class IntervalsQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] @@ -579,13 +579,13 @@ def __init__( class LikeDocument(AttrDict[Any]): """ :arg doc: A document not present in the index. - :arg fields: No documentation available. + :arg fields: :arg _id: ID of a document. :arg _index: Index of a document. :arg per_field_analyzer: Overrides the default analyzer. - :arg routing: No documentation available. - :arg version: No documentation available. - :arg version_type: No documentation available. + :arg routing: + :arg version: + :arg version_type: """ doc: Any @@ -671,7 +671,7 @@ class MatchBoolPrefixQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ analyzer: Union[str, "DefaultType"] @@ -744,7 +744,7 @@ class MatchPhrasePrefixQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ analyzer: Union[str, "DefaultType"] @@ -800,7 +800,7 @@ class MatchPhraseQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ analyzer: Union[str, "DefaultType"] @@ -842,7 +842,7 @@ class MatchQuery(QueryBase): into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. - :arg cutoff_frequency: No documentation available. + :arg cutoff_frequency: :arg fuzziness: Maximum edit distance allowed for matching. :arg fuzzy_rewrite: Method used to rewrite the query. :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include @@ -868,7 +868,7 @@ class MatchQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ analyzer: Union[str, "DefaultType"] @@ -979,7 +979,7 @@ class PrefixQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ rewrite: Union[str, "DefaultType"] @@ -1013,7 +1013,7 @@ def __init__( class QueryVectorBuilder(AttrDict[Any]): """ - :arg text_embedding: No documentation available. + :arg text_embedding: """ text_embedding: Union["types.TextEmbedding", Dict[str, Any], "DefaultType"] @@ -1109,7 +1109,7 @@ class RegexpQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ case_insensitive: Union[bool, "DefaultType"] @@ -1157,7 +1157,7 @@ class Script(AttrDict[Any]): script as variables. Use parameters instead of hard-coded values to decrease compile time. :arg lang: Specifies the language the script is written in. - :arg options: No documentation available. + :arg options: """ source: Union[str, "DefaultType"] @@ -1235,7 +1235,7 @@ class SpanQuery(AttrDict[Any]): across different fields. :arg span_first: Accepts another span query whose matches must appear within the first N positions of the field. - :arg span_gap: No documentation available. + :arg span_gap: :arg span_multi: Wraps a `term`, `range`, `prefix`, `wildcard`, `regexp`, or `fuzzy` query. :arg span_near: Accepts multiple span queries whose matches must be @@ -1327,13 +1327,13 @@ def __init__( class SpanTermQuery(QueryBase): """ - :arg value: (required) No documentation available. + :arg value: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ value: Union[str, "DefaultType"] @@ -1369,7 +1369,7 @@ class TermQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ value: Union[int, float, str, bool, None, Any, "DefaultType"] @@ -1399,10 +1399,10 @@ def __init__( class TermsLookup(AttrDict[Any]): """ - :arg index: (required) No documentation available. - :arg id: (required) No documentation available. - :arg path: (required) No documentation available. - :arg routing: No documentation available. + :arg index: (required) + :arg id: (required) + :arg path: (required) + :arg routing: """ index: Union[str, "DefaultType"] @@ -1443,7 +1443,7 @@ class TermsSetQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] @@ -1489,7 +1489,7 @@ class TextExpansionQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ model_id: Union[str, "DefaultType"] @@ -1557,8 +1557,8 @@ def __init__( class TopLeftBottomRightGeoBounds(AttrDict[Any]): """ - :arg top_left: (required) No documentation available. - :arg bottom_right: (required) No documentation available. + :arg top_left: (required) + :arg bottom_right: (required) """ top_left: Union[ @@ -1608,8 +1608,8 @@ def __init__( class TopRightBottomLeftGeoBounds(AttrDict[Any]): """ - :arg top_right: (required) No documentation available. - :arg bottom_left: (required) No documentation available. + :arg top_right: (required) + :arg bottom_left: (required) """ top_right: Union[ @@ -1666,7 +1666,7 @@ class WeightedTokensQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ tokens: Union[Mapping[str, float], "DefaultType"] @@ -1712,7 +1712,7 @@ class WildcardQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ case_insensitive: Union[bool, "DefaultType"] @@ -1750,7 +1750,7 @@ def __init__( class WktGeoBounds(AttrDict[Any]): """ - :arg wkt: (required) No documentation available. + :arg wkt: (required) """ wkt: Union[str, "DefaultType"] @@ -1800,7 +1800,7 @@ class FieldCollapse(AttrDict[Any]): :arg inner_hits: The number of inner hits and their sort order :arg max_concurrent_group_searches: The number of concurrent requests allowed to retrieve the inner_hits per group - :arg collapse: No documentation available. + :arg collapse: """ field: Union[str, "InstrumentedField", "DefaultType"] @@ -1840,7 +1840,7 @@ class FieldAndFormat(AttrDict[Any]): :arg field: (required) Wildcard pattern. The request returns values for field names matching this pattern. :arg format: Format in which the values are returned. - :arg include_unmapped: No documentation available. + :arg include_unmapped: """ field: Union[str, "InstrumentedField", "DefaultType"] @@ -1866,7 +1866,7 @@ def __init__( class HighlightBase(AttrDict[Any]): """ - :arg type: No documentation available. + :arg type: :arg boundary_chars: A string that contains each boundary character. :arg boundary_max_scan: How far to scan for boundary characters. :arg boundary_scanner: Specifies how to break the highlighted @@ -1876,18 +1876,18 @@ class HighlightBase(AttrDict[Any]): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. - :arg force_source: No documentation available. + :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` highlighter. :arg fragment_size: The size of the highlighted fragment in characters. - :arg highlight_filter: No documentation available. + :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. - :arg max_fragment_length: No documentation available. + :arg max_fragment_length: :arg max_analyzed_offset: If set to a non-negative value, highlighting stops at this defined maximum limit. The rest of the text is not processed, thus not highlighted and no error is returned The @@ -1903,7 +1903,7 @@ class HighlightBase(AttrDict[Any]): returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If `number_of_fragments` is `0`, `fragment_size` is ignored. - :arg options: No documentation available. + :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will @@ -2024,9 +2024,9 @@ def __init__( class Highlight(HighlightBase): """ - :arg encoder: No documentation available. - :arg fields: (required) No documentation available. - :arg type: No documentation available. + :arg encoder: + :arg fields: (required) + :arg type: :arg boundary_chars: A string that contains each boundary character. :arg boundary_max_scan: How far to scan for boundary characters. :arg boundary_scanner: Specifies how to break the highlighted @@ -2036,18 +2036,18 @@ class Highlight(HighlightBase): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. - :arg force_source: No documentation available. + :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` highlighter. :arg fragment_size: The size of the highlighted fragment in characters. - :arg highlight_filter: No documentation available. + :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. - :arg max_fragment_length: No documentation available. + :arg max_fragment_length: :arg max_analyzed_offset: If set to a non-negative value, highlighting stops at this defined maximum limit. The rest of the text is not processed, thus not highlighted and no error is returned The @@ -2063,7 +2063,7 @@ class Highlight(HighlightBase): returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If `number_of_fragments` is `0`, `fragment_size` is ignored. - :arg options: No documentation available. + :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will @@ -2200,8 +2200,8 @@ def __init__( class ScriptField(AttrDict[Any]): """ - :arg script: (required) No documentation available. - :arg ignore_failure: No documentation available. + :arg script: (required) + :arg ignore_failure: """ script: Union["types.Script", Dict[str, Any], "DefaultType"] @@ -2223,10 +2223,10 @@ def __init__( class SortOptions(AttrDict[Any]): """ - :arg _score: No documentation available. - :arg _doc: No documentation available. - :arg _geo_distance: No documentation available. - :arg _script: No documentation available. + :arg _score: + :arg _doc: + :arg _geo_distance: + :arg _script: """ _score: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] @@ -2258,8 +2258,8 @@ def __init__( class SourceFilter(AttrDict[Any]): """ - :arg excludes: No documentation available. - :arg includes: No documentation available. + :arg excludes: + :arg includes: """ excludes: Union[ @@ -2526,8 +2526,8 @@ def __init__( class TextEmbedding(AttrDict[Any]): """ - :arg model_id: (required) No documentation available. - :arg model_text: (required) No documentation available. + :arg model_id: (required) + :arg model_text: (required) """ model_id: Union[str, "DefaultType"] @@ -2558,7 +2558,7 @@ class SpanContainingQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] @@ -2588,14 +2588,14 @@ def __init__( class SpanFieldMaskingQuery(QueryBase): """ - :arg field: (required) No documentation available. - :arg query: (required) No documentation available. + :arg field: (required) + :arg query: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ field: Union[str, "InstrumentedField", "DefaultType"] @@ -2633,7 +2633,7 @@ class SpanFirstQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ end: Union[int, "DefaultType"] @@ -2670,7 +2670,7 @@ class SpanMultiTermQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ match: Union[Query, "DefaultType"] @@ -2705,7 +2705,7 @@ class SpanNearQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] @@ -2756,7 +2756,7 @@ class SpanNotQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ dist: Union[int, "DefaultType"] @@ -2804,7 +2804,7 @@ class SpanOrQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] @@ -2841,7 +2841,7 @@ class SpanWithinQuery(QueryBase): default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score. - :arg _name: No documentation available. + :arg _name: """ big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] @@ -2871,10 +2871,10 @@ def __init__( class HighlightField(HighlightBase): """ - :arg fragment_offset: No documentation available. - :arg matched_fields: No documentation available. - :arg analyzer: No documentation available. - :arg type: No documentation available. + :arg fragment_offset: + :arg matched_fields: + :arg analyzer: + :arg type: :arg boundary_chars: A string that contains each boundary character. :arg boundary_max_scan: How far to scan for boundary characters. :arg boundary_scanner: Specifies how to break the highlighted @@ -2884,18 +2884,18 @@ class HighlightField(HighlightBase): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. - :arg force_source: No documentation available. + :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` highlighter. :arg fragment_size: The size of the highlighted fragment in characters. - :arg highlight_filter: No documentation available. + :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. - :arg max_fragment_length: No documentation available. + :arg max_fragment_length: :arg max_analyzed_offset: If set to a non-negative value, highlighting stops at this defined maximum limit. The rest of the text is not processed, thus not highlighted and no error is returned The @@ -2911,7 +2911,7 @@ class HighlightField(HighlightBase): returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If `number_of_fragments` is `0`, `fragment_size` is ignored. - :arg options: No documentation available. + :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will @@ -3052,7 +3052,7 @@ def __init__( class ScoreSort(AttrDict[Any]): """ - :arg order: No documentation available. + :arg order: """ order: Union[Literal["asc", "desc"], "DefaultType"] @@ -3070,12 +3070,12 @@ def __init__( class GeoDistanceSort(AttrDict[Any]): """ - :arg mode: No documentation available. - :arg distance_type: No documentation available. - :arg ignore_unmapped: No documentation available. - :arg order: No documentation available. - :arg unit: No documentation available. - :arg nested: No documentation available. + :arg mode: + :arg distance_type: + :arg ignore_unmapped: + :arg order: + :arg unit: + :arg nested: """ mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] @@ -3119,11 +3119,11 @@ def __init__( class ScriptSort(AttrDict[Any]): """ - :arg order: No documentation available. - :arg script: (required) No documentation available. - :arg type: No documentation available. - :arg mode: No documentation available. - :arg nested: No documentation available. + :arg order: + :arg script: (required) + :arg type: + :arg mode: + :arg nested: """ order: Union[Literal["asc", "desc"], "DefaultType"] @@ -3288,10 +3288,10 @@ def __init__( class NestedSortValue(AttrDict[Any]): """ - :arg filter: No documentation available. - :arg max_children: No documentation available. - :arg nested: No documentation available. - :arg path: (required) No documentation available. + :arg filter: + :arg max_children: + :arg nested: + :arg path: (required) """ filter: Union[Query, "DefaultType"] diff --git a/utils/generator.py b/utils/generator.py index 585fa5db..82d1ed0d 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -46,7 +46,7 @@ def wrapped_doc(text, width=70, initial_indent="", subsequent_indent=""): """Formats a docstring as a list of lines of up to the request width.""" return textwrap.wrap( - (text or "No documentation available.").replace("\n", " "), + text.replace("\n", " "), width=width, initial_indent=initial_indent, subsequent_indent=subsequent_indent, @@ -253,7 +253,7 @@ def get_attribute_data(self, arg): type_ = add_not_set(type_) required = "(required) " if arg["required"] else "" doc = wrapped_doc( - f":arg {arg['name']}: {required}{arg.get('description', 'No documentation available.')}", + f":arg {arg['name']}: {required}{arg.get('description', '')}", subsequent_indent=" ", ) arg = { @@ -300,7 +300,7 @@ def property_to_python_class(self, p): "property_name": p["name"], "name": "".join([w.title() for w in p["name"].split("_")]), } - k["docstring"] = wrapped_doc(p.get("description")) + k["docstring"] = wrapped_doc(p.get("description") or "") kind = p["type"]["kind"] if kind == "instance_of": namespace = p["type"]["type"]["namespace"] diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index 7016b52c..a31e4b75 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -153,7 +153,9 @@ class {{ k.name }}({{ parent }}): {{ line }} {% endfor %} {% if k.args %} + {% if k.docstring %} + {% endif %} {% for kwarg in k.args %} {% for line in kwarg.doc %} {{ line }} From d6fc3f09ab8d406ec64ce2e09b167ca4bb1b06f1 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 17:13:34 +0100 Subject: [PATCH 18/27] add unit test for AttrDict with from reserved keyword --- tests/test_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index fe417d2f..7081e9be 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -125,3 +125,12 @@ def test_attrlist_to_list() -> None: l = utils.AttrList[Any]([{}, {}]).to_list() assert isinstance(l, list) assert l == [{}, {}] + + +def test_attrdict_with_reserved_keyword() -> None: + d = utils.AttrDict({"from": 10, "size": 20}) + assert d.from_ == 10 + assert d.size == 20 + d = utils.AttrDict({}) + d.from_ = 10 + assert {"from": 10} == d.to_dict() From 67abf79265eb9f682350102c3c98f3b2f9cfdd37 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 17:36:55 +0100 Subject: [PATCH 19/27] add a dependency on the transport library --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index c473e720..2ac81588 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ "python-dateutil", "typing-extensions", "elasticsearch>=8.0.0,<9.0.0", + "elastic-transport>=8.0.0,<9.0.0", ] async_requires = [ From ef3cc7d552f734efb0328c2c978bdd2f0ec52d6c Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Sep 2024 17:39:23 +0100 Subject: [PATCH 20/27] Update utils/generator.py Co-authored-by: Quentin Pradet --- utils/generator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/generator.py b/utils/generator.py index 82d1ed0d..4080f9a8 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -210,6 +210,7 @@ def get_python_type(self, schema_type): if schema_type["name"]["name"].endswith("RangeQuery"): return '"wrappers.Range[Any]"', None elif schema_type["name"]["name"].endswith("ScoreFunction"): + # When dropping Python 3.8, use `removesuffix("Function")` instead name = schema_type["name"]["name"][:-8] return f'"function.{name}"', None elif schema_type["name"]["name"].endswith("DecayFunction"): From 1c43dd227ad1a8263f8a7cf7e54810b5861691bc Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 10 Sep 2024 14:39:20 +0100 Subject: [PATCH 21/27] list required arguments first in types.py --- elasticsearch_dsl/types.py | 184 ++++++++++++++++++------------------- utils/generator.py | 55 ++++++----- 2 files changed, 119 insertions(+), 120 deletions(-) diff --git a/elasticsearch_dsl/types.py b/elasticsearch_dsl/types.py index be31b9e1..391bf0e3 100644 --- a/elasticsearch_dsl/types.py +++ b/elasticsearch_dsl/types.py @@ -55,12 +55,12 @@ def __init__( class CommonTermsQuery(QueryBase): """ + :arg query: (required) :arg analyzer: :arg cutoff_frequency: :arg high_freq_operator: :arg low_freq_operator: :arg minimum_should_match: - :arg query: (required) :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases @@ -69,28 +69,30 @@ class CommonTermsQuery(QueryBase): :arg _name: """ + query: Union[str, "DefaultType"] analyzer: Union[str, "DefaultType"] cutoff_frequency: Union[float, "DefaultType"] high_freq_operator: Union[Literal["and", "or"], "DefaultType"] low_freq_operator: Union[Literal["and", "or"], "DefaultType"] minimum_should_match: Union[int, str, "DefaultType"] - query: Union[str, "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, + query: Union[str, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, high_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, low_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, - query: Union[str, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if query is not DEFAULT: + kwargs["query"] = query if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if cutoff_frequency is not DEFAULT: @@ -101,8 +103,6 @@ def __init__( kwargs["low_freq_operator"] = low_freq_operator if minimum_should_match is not DEFAULT: kwargs["minimum_should_match"] = minimum_should_match - if query is not DEFAULT: - kwargs["query"] = query if boost is not DEFAULT: kwargs["boost"] = boost if _name is not DEFAULT: @@ -213,6 +213,7 @@ def __init__( class FuzzyQuery(QueryBase): """ + :arg value: (required) Term you wish to find in the provided field. :arg max_expansions: Maximum number of variations created. :arg prefix_length: Number of beginning characters left unchanged when creating expansions. @@ -221,7 +222,6 @@ class FuzzyQuery(QueryBase): :arg transpositions: Indicates whether edits include transpositions of two adjacent characters (for example `ab` to `ba`). :arg fuzziness: Maximum edit distance allowed for matching. - :arg value: (required) Term you wish to find in the provided field. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases @@ -230,28 +230,30 @@ class FuzzyQuery(QueryBase): :arg _name: """ + value: Union[str, float, bool, "DefaultType"] max_expansions: Union[int, "DefaultType"] prefix_length: Union[int, "DefaultType"] rewrite: Union[str, "DefaultType"] transpositions: Union[bool, "DefaultType"] fuzziness: Union[str, int, "DefaultType"] - value: Union[str, float, bool, "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, + value: Union[str, float, bool, "DefaultType"] = DEFAULT, max_expansions: Union[int, "DefaultType"] = DEFAULT, prefix_length: Union[int, "DefaultType"] = DEFAULT, rewrite: Union[str, "DefaultType"] = DEFAULT, transpositions: Union[bool, "DefaultType"] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, - value: Union[str, float, bool, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if value is not DEFAULT: + kwargs["value"] = value if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions if prefix_length is not DEFAULT: @@ -262,8 +264,6 @@ def __init__( kwargs["transpositions"] = transpositions if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness - if value is not DEFAULT: - kwargs["value"] = value if boost is not DEFAULT: kwargs["boost"] = boost if _name is not DEFAULT: @@ -641,6 +641,8 @@ def __init__( class MatchBoolPrefixQuery(QueryBase): """ + :arg query: (required) Terms you wish to find in the provided field. + The last term is used in a prefix query. :arg analyzer: Analyzer used to convert the text in the query value into tokens. :arg fuzziness: Maximum edit distance allowed for matching. Can be @@ -664,8 +666,6 @@ class MatchBoolPrefixQuery(QueryBase): :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. Can be applied to the term subqueries constructed for all terms but the final term. - :arg query: (required) Terms you wish to find in the provided field. - The last term is used in a prefix query. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases @@ -674,6 +674,7 @@ class MatchBoolPrefixQuery(QueryBase): :arg _name: """ + query: Union[str, "DefaultType"] analyzer: Union[str, "DefaultType"] fuzziness: Union[str, int, "DefaultType"] fuzzy_rewrite: Union[str, "DefaultType"] @@ -682,13 +683,13 @@ class MatchBoolPrefixQuery(QueryBase): minimum_should_match: Union[int, str, "DefaultType"] operator: Union[Literal["and", "or"], "DefaultType"] prefix_length: Union[int, "DefaultType"] - query: Union[str, "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, + query: Union[str, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, @@ -697,11 +698,12 @@ def __init__( minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, prefix_length: Union[int, "DefaultType"] = DEFAULT, - query: Union[str, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if query is not DEFAULT: + kwargs["query"] = query if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if fuzziness is not DEFAULT: @@ -718,8 +720,6 @@ def __init__( kwargs["operator"] = operator if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if query is not DEFAULT: - kwargs["query"] = query if boost is not DEFAULT: kwargs["boost"] = boost if _name is not DEFAULT: @@ -729,11 +729,11 @@ def __init__( class MatchPhrasePrefixQuery(QueryBase): """ + :arg query: (required) Text you wish to find in the provided field. :arg analyzer: Analyzer used to convert text in the query value into tokens. :arg max_expansions: Maximum number of terms to which the last provided term of the query value will expand. - :arg query: (required) Text you wish to find in the provided field. :arg slop: Maximum number of positions allowed between matching tokens. :arg zero_terms_query: Indicates whether no documents are returned if @@ -747,9 +747,9 @@ class MatchPhrasePrefixQuery(QueryBase): :arg _name: """ + query: Union[str, "DefaultType"] analyzer: Union[str, "DefaultType"] max_expansions: Union[int, "DefaultType"] - query: Union[str, "DefaultType"] slop: Union[int, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] boost: Union[float, "DefaultType"] @@ -758,21 +758,21 @@ class MatchPhrasePrefixQuery(QueryBase): def __init__( self, *, + query: Union[str, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, max_expansions: Union[int, "DefaultType"] = DEFAULT, - query: Union[str, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if query is not DEFAULT: + kwargs["query"] = query if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if max_expansions is not DEFAULT: kwargs["max_expansions"] = max_expansions - if query is not DEFAULT: - kwargs["query"] = query if slop is not DEFAULT: kwargs["slop"] = slop if zero_terms_query is not DEFAULT: @@ -786,10 +786,10 @@ def __init__( class MatchPhraseQuery(QueryBase): """ - :arg analyzer: Analyzer used to convert the text in the query value - into tokens. :arg query: (required) Query terms that are analyzed and turned into a phrase query. + :arg analyzer: Analyzer used to convert the text in the query value + into tokens. :arg slop: Maximum number of positions allowed between matching tokens. :arg zero_terms_query: Indicates whether no documents are returned if @@ -803,8 +803,8 @@ class MatchPhraseQuery(QueryBase): :arg _name: """ - analyzer: Union[str, "DefaultType"] query: Union[str, "DefaultType"] + analyzer: Union[str, "DefaultType"] slop: Union[int, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] boost: Union[float, "DefaultType"] @@ -813,18 +813,18 @@ class MatchPhraseQuery(QueryBase): def __init__( self, *, - analyzer: Union[str, "DefaultType"] = DEFAULT, query: Union[str, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, slop: Union[int, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer is not DEFAULT: - kwargs["analyzer"] = analyzer if query is not DEFAULT: kwargs["query"] = query + if analyzer is not DEFAULT: + kwargs["analyzer"] = analyzer if slop is not DEFAULT: kwargs["slop"] = slop if zero_terms_query is not DEFAULT: @@ -838,6 +838,8 @@ def __init__( class MatchQuery(QueryBase): """ + :arg query: (required) Text, number, boolean value or date you wish to + find in the provided field. :arg analyzer: Analyzer used to convert the text in the query value into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase @@ -858,8 +860,6 @@ class MatchQuery(QueryBase): value. :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. - :arg query: (required) Text, number, boolean value or date you wish to - find in the provided field. :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter. @@ -871,6 +871,7 @@ class MatchQuery(QueryBase): :arg _name: """ + query: Union[str, float, bool, "DefaultType"] analyzer: Union[str, "DefaultType"] auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] cutoff_frequency: Union[float, "DefaultType"] @@ -882,7 +883,6 @@ class MatchQuery(QueryBase): minimum_should_match: Union[int, str, "DefaultType"] operator: Union[Literal["and", "or"], "DefaultType"] prefix_length: Union[int, "DefaultType"] - query: Union[str, float, bool, "DefaultType"] zero_terms_query: Union[Literal["all", "none"], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -890,6 +890,7 @@ class MatchQuery(QueryBase): def __init__( self, *, + query: Union[str, float, bool, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, @@ -901,12 +902,13 @@ def __init__( minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, prefix_length: Union[int, "DefaultType"] = DEFAULT, - query: Union[str, float, bool, "DefaultType"] = DEFAULT, zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if query is not DEFAULT: + kwargs["query"] = query if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if auto_generate_synonyms_phrase_query is not DEFAULT: @@ -931,8 +933,6 @@ def __init__( kwargs["operator"] = operator if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if query is not DEFAULT: - kwargs["query"] = query if zero_terms_query is not DEFAULT: kwargs["zero_terms_query"] = zero_terms_query if boost is not DEFAULT: @@ -967,9 +967,9 @@ def __init__( class PrefixQuery(QueryBase): """ - :arg rewrite: Method used to rewrite the query. :arg value: (required) Beginning characters of terms you wish to find in the provided field. + :arg rewrite: Method used to rewrite the query. :arg case_insensitive: Allows ASCII case insensitive matching of the value with the indexed field values when set to `true`. Default is `false` which means the case sensitivity of matching depends on @@ -982,8 +982,8 @@ class PrefixQuery(QueryBase): :arg _name: """ - rewrite: Union[str, "DefaultType"] value: Union[str, "DefaultType"] + rewrite: Union[str, "DefaultType"] case_insensitive: Union[bool, "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] @@ -991,17 +991,17 @@ class PrefixQuery(QueryBase): def __init__( self, *, - rewrite: Union[str, "DefaultType"] = DEFAULT, value: Union[str, "DefaultType"] = DEFAULT, + rewrite: Union[str, "DefaultType"] = DEFAULT, case_insensitive: Union[bool, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if rewrite is not DEFAULT: - kwargs["rewrite"] = rewrite if value is not DEFAULT: kwargs["value"] = value + if rewrite is not DEFAULT: + kwargs["rewrite"] = rewrite if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive if boost is not DEFAULT: @@ -1094,6 +1094,8 @@ def __init__( class RegexpQuery(QueryBase): """ + :arg value: (required) Regular expression for terms you wish to find + in the provided field. :arg case_insensitive: Allows case insensitive matching of the regular expression value with the indexed field values when set to `true`. When `false`, case sensitivity of matching depends on the @@ -1102,8 +1104,6 @@ class RegexpQuery(QueryBase): :arg max_determinized_states: Maximum number of automaton states required for the query. :arg rewrite: Method used to rewrite the query. - :arg value: (required) Regular expression for terms you wish to find - in the provided field. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases @@ -1112,26 +1112,28 @@ class RegexpQuery(QueryBase): :arg _name: """ + value: Union[str, "DefaultType"] case_insensitive: Union[bool, "DefaultType"] flags: Union[str, "DefaultType"] max_determinized_states: Union[int, "DefaultType"] rewrite: Union[str, "DefaultType"] - value: Union[str, "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, + value: Union[str, "DefaultType"] = DEFAULT, case_insensitive: Union[bool, "DefaultType"] = DEFAULT, flags: Union[str, "DefaultType"] = DEFAULT, max_determinized_states: Union[int, "DefaultType"] = DEFAULT, rewrite: Union[str, "DefaultType"] = DEFAULT, - value: Union[str, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if value is not DEFAULT: + kwargs["value"] = value if case_insensitive is not DEFAULT: kwargs["case_insensitive"] = case_insensitive if flags is not DEFAULT: @@ -1140,8 +1142,6 @@ def __init__( kwargs["max_determinized_states"] = max_determinized_states if rewrite is not DEFAULT: kwargs["rewrite"] = rewrite - if value is not DEFAULT: - kwargs["value"] = value if boost is not DEFAULT: kwargs["boost"] = boost if _name is not DEFAULT: @@ -1432,12 +1432,12 @@ def __init__( class TermsSetQuery(QueryBase): """ + :arg terms: (required) Array of terms you wish to find in the provided + field. :arg minimum_should_match_field: Numeric field containing the number of matching terms required to return a document. :arg minimum_should_match_script: Custom script containing the number of matching terms required to return a document. - :arg terms: (required) Array of terms you wish to find in the provided - field. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases @@ -1446,32 +1446,32 @@ class TermsSetQuery(QueryBase): :arg _name: """ + terms: Union[Sequence[str], "DefaultType"] minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] minimum_should_match_script: Union["types.Script", Dict[str, Any], "DefaultType"] - terms: Union[Sequence[str], "DefaultType"] boost: Union[float, "DefaultType"] _name: Union[str, "DefaultType"] def __init__( self, *, + terms: Union[Sequence[str], "DefaultType"] = DEFAULT, minimum_should_match_field: Union[ str, "InstrumentedField", "DefaultType" ] = DEFAULT, minimum_should_match_script: Union[ "types.Script", Dict[str, Any], "DefaultType" ] = DEFAULT, - terms: Union[Sequence[str], "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): + if terms is not DEFAULT: + kwargs["terms"] = terms if minimum_should_match_field is not DEFAULT: kwargs["minimum_should_match_field"] = str(minimum_should_match_field) if minimum_should_match_script is not DEFAULT: kwargs["minimum_should_match_script"] = minimum_should_match_script - if terms is not DEFAULT: - kwargs["terms"] = terms if boost is not DEFAULT: kwargs["boost"] = boost if _name is not DEFAULT: @@ -2024,8 +2024,8 @@ def __init__( class Highlight(HighlightBase): """ - :arg encoder: :arg fields: (required) + :arg encoder: :arg type: :arg boundary_chars: A string that contains each boundary character. :arg boundary_max_scan: How far to scan for boundary characters. @@ -2087,12 +2087,12 @@ class Highlight(HighlightBase): :arg tags_schema: Set to `styled` to use the built-in tag schema. """ - encoder: Union[Literal["default", "html"], "DefaultType"] fields: Union[ Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], Dict[str, Any], "DefaultType", ] + encoder: Union[Literal["default", "html"], "DefaultType"] type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] boundary_chars: Union[str, "DefaultType"] boundary_max_scan: Union[int, "DefaultType"] @@ -2118,12 +2118,12 @@ class Highlight(HighlightBase): def __init__( self, *, - encoder: Union[Literal["default", "html"], "DefaultType"] = DEFAULT, fields: Union[ Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], Dict[str, Any], "DefaultType", ] = DEFAULT, + encoder: Union[Literal["default", "html"], "DefaultType"] = DEFAULT, type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, boundary_chars: Union[str, "DefaultType"] = DEFAULT, boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, @@ -2149,10 +2149,10 @@ def __init__( tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if encoder is not DEFAULT: - kwargs["encoder"] = encoder if fields is not DEFAULT: kwargs["fields"] = str(fields) + if encoder is not DEFAULT: + kwargs["encoder"] = encoder if type is not DEFAULT: kwargs["type"] = type if boundary_chars is not DEFAULT: @@ -2366,11 +2366,11 @@ def __init__( class IntervalsFuzzy(AttrDict[Any]): """ + :arg term: (required) The term to match. :arg analyzer: Analyzer used to normalize the term. :arg fuzziness: Maximum edit distance allowed for matching. :arg prefix_length: Number of beginning characters left unchanged when creating expansions. - :arg term: (required) The term to match. :arg transpositions: Indicates whether edits include transpositions of two adjacent characters (for example, `ab` to `ba`). :arg use_field: If specified, match intervals from this field rather @@ -2379,32 +2379,32 @@ class IntervalsFuzzy(AttrDict[Any]): separately. """ + term: Union[str, "DefaultType"] analyzer: Union[str, "DefaultType"] fuzziness: Union[str, int, "DefaultType"] prefix_length: Union[int, "DefaultType"] - term: Union[str, "DefaultType"] transpositions: Union[bool, "DefaultType"] use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, + term: Union[str, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, fuzziness: Union[str, int, "DefaultType"] = DEFAULT, prefix_length: Union[int, "DefaultType"] = DEFAULT, - term: Union[str, "DefaultType"] = DEFAULT, transpositions: Union[bool, "DefaultType"] = DEFAULT, use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): + if term is not DEFAULT: + kwargs["term"] = term if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if fuzziness is not DEFAULT: kwargs["fuzziness"] = fuzziness if prefix_length is not DEFAULT: kwargs["prefix_length"] = prefix_length - if term is not DEFAULT: - kwargs["term"] = term if transpositions is not DEFAULT: kwargs["transpositions"] = transpositions if use_field is not DEFAULT: @@ -2414,12 +2414,12 @@ def __init__( class IntervalsMatch(AttrDict[Any]): """ + :arg query: (required) Text you wish to find in the provided field. :arg analyzer: Analyzer used to analyze terms in the query. :arg max_gaps: Maximum number of positions between the matching terms. Terms further apart than this are not considered matches. :arg ordered: If `true`, matching terms must appear in their specified order. - :arg query: (required) Text you wish to find in the provided field. :arg use_field: If specified, match intervals from this field rather than the top-level field. The `term` is normalized using the search analyzer from this field, unless `analyzer` is specified @@ -2427,32 +2427,32 @@ class IntervalsMatch(AttrDict[Any]): :arg filter: An optional interval filter. """ + query: Union[str, "DefaultType"] analyzer: Union[str, "DefaultType"] max_gaps: Union[int, "DefaultType"] ordered: Union[bool, "DefaultType"] - query: Union[str, "DefaultType"] use_field: Union[str, "InstrumentedField", "DefaultType"] filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] def __init__( self, *, + query: Union[str, "DefaultType"] = DEFAULT, analyzer: Union[str, "DefaultType"] = DEFAULT, max_gaps: Union[int, "DefaultType"] = DEFAULT, ordered: Union[bool, "DefaultType"] = DEFAULT, - query: Union[str, "DefaultType"] = DEFAULT, use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): + if query is not DEFAULT: + kwargs["query"] = query if analyzer is not DEFAULT: kwargs["analyzer"] = analyzer if max_gaps is not DEFAULT: kwargs["max_gaps"] = max_gaps if ordered is not DEFAULT: kwargs["ordered"] = ordered - if query is not DEFAULT: - kwargs["query"] = query if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) if filter is not DEFAULT: @@ -2462,31 +2462,31 @@ def __init__( class IntervalsPrefix(AttrDict[Any]): """ - :arg analyzer: Analyzer used to analyze the `prefix`. :arg prefix: (required) Beginning characters of terms you wish to find in the top-level field. + :arg analyzer: Analyzer used to analyze the `prefix`. :arg use_field: If specified, match intervals from this field rather than the top-level field. The `prefix` is normalized using the search analyzer from this field, unless `analyzer` is specified separately. """ - analyzer: Union[str, "DefaultType"] prefix: Union[str, "DefaultType"] + analyzer: Union[str, "DefaultType"] use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - analyzer: Union[str, "DefaultType"] = DEFAULT, prefix: Union[str, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer is not DEFAULT: - kwargs["analyzer"] = analyzer if prefix is not DEFAULT: kwargs["prefix"] = prefix + if analyzer is not DEFAULT: + kwargs["analyzer"] = analyzer if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -2494,31 +2494,31 @@ def __init__( class IntervalsWildcard(AttrDict[Any]): """ + :arg pattern: (required) Wildcard pattern used to find matching terms. :arg analyzer: Analyzer used to analyze the `pattern`. Defaults to the top-level field's analyzer. - :arg pattern: (required) Wildcard pattern used to find matching terms. :arg use_field: If specified, match intervals from this field rather than the top-level field. The `pattern` is normalized using the search analyzer from this field, unless `analyzer` is specified separately. """ - analyzer: Union[str, "DefaultType"] pattern: Union[str, "DefaultType"] + analyzer: Union[str, "DefaultType"] use_field: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, - analyzer: Union[str, "DefaultType"] = DEFAULT, pattern: Union[str, "DefaultType"] = DEFAULT, + analyzer: Union[str, "DefaultType"] = DEFAULT, use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): - if analyzer is not DEFAULT: - kwargs["analyzer"] = analyzer if pattern is not DEFAULT: kwargs["pattern"] = pattern + if analyzer is not DEFAULT: + kwargs["analyzer"] = analyzer if use_field is not DEFAULT: kwargs["use_field"] = str(use_field) super().__init__(kwargs) @@ -2741,12 +2741,12 @@ def __init__( class SpanNotQuery(QueryBase): """ - :arg dist: The number of tokens from within the include span that - can’t have overlap with the exclude span. Equivalent to setting - both `pre` and `post`. :arg exclude: (required) Span query whose matches must not overlap those returned. :arg include: (required) Span query whose matches are filtered. + :arg dist: The number of tokens from within the include span that + can’t have overlap with the exclude span. Equivalent to setting + both `pre` and `post`. :arg post: The number of tokens after the include span that can’t have overlap with the exclude span. :arg pre: The number of tokens before the include span that can’t have @@ -2759,9 +2759,9 @@ class SpanNotQuery(QueryBase): :arg _name: """ - dist: Union[int, "DefaultType"] exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] + dist: Union[int, "DefaultType"] post: Union[int, "DefaultType"] pre: Union[int, "DefaultType"] boost: Union[float, "DefaultType"] @@ -2770,21 +2770,21 @@ class SpanNotQuery(QueryBase): def __init__( self, *, - dist: Union[int, "DefaultType"] = DEFAULT, exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + dist: Union[int, "DefaultType"] = DEFAULT, post: Union[int, "DefaultType"] = DEFAULT, pre: Union[int, "DefaultType"] = DEFAULT, boost: Union[float, "DefaultType"] = DEFAULT, _name: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any, ): - if dist is not DEFAULT: - kwargs["dist"] = dist if exclude is not DEFAULT: kwargs["exclude"] = exclude if include is not DEFAULT: kwargs["include"] = include + if dist is not DEFAULT: + kwargs["dist"] = dist if post is not DEFAULT: kwargs["post"] = post if pre is not DEFAULT: @@ -3119,15 +3119,15 @@ def __init__( class ScriptSort(AttrDict[Any]): """ - :arg order: :arg script: (required) + :arg order: :arg type: :arg mode: :arg nested: """ - order: Union[Literal["asc", "desc"], "DefaultType"] script: Union["types.Script", Dict[str, Any], "DefaultType"] + order: Union[Literal["asc", "desc"], "DefaultType"] type: Union[Literal["string", "number", "version"], "DefaultType"] mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] @@ -3135,8 +3135,8 @@ class ScriptSort(AttrDict[Any]): def __init__( self, *, - order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, type: Union[Literal["string", "number", "version"], "DefaultType"] = DEFAULT, mode: Union[ Literal["min", "max", "sum", "avg", "median"], "DefaultType" @@ -3144,10 +3144,10 @@ def __init__( nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, **kwargs: Any, ): - if order is not DEFAULT: - kwargs["order"] = order if script is not DEFAULT: kwargs["script"] = script + if order is not DEFAULT: + kwargs["order"] = order if type is not DEFAULT: kwargs["type"] = type if mode is not DEFAULT: @@ -3288,32 +3288,32 @@ def __init__( class NestedSortValue(AttrDict[Any]): """ + :arg path: (required) :arg filter: :arg max_children: :arg nested: - :arg path: (required) """ + path: Union[str, "InstrumentedField", "DefaultType"] filter: Union[Query, "DefaultType"] max_children: Union[int, "DefaultType"] nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] - path: Union[str, "InstrumentedField", "DefaultType"] def __init__( self, *, + path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, filter: Union[Query, "DefaultType"] = DEFAULT, max_children: Union[int, "DefaultType"] = DEFAULT, nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, - path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, **kwargs: Any, ): + if path is not DEFAULT: + kwargs["path"] = str(path) if filter is not DEFAULT: kwargs["filter"] = filter if max_children is not DEFAULT: kwargs["max_children"] = max_children if nested is not DEFAULT: kwargs["nested"] = nested - if path is not DEFAULT: - kwargs["path"] = str(path) super().__init__(kwargs) diff --git a/utils/generator.py b/utils/generator.py index 4080f9a8..de2de5ac 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -234,14 +234,15 @@ def get_python_type(self, schema_type): raise RuntimeError(f"Cannot find Python type for {schema_type}") - def get_attribute_data(self, arg): - """Return the template definitions for a class attribute. - - This method returns a tuple. The first element is a dict with the - information to render the attribute. The second element is a dictionary - with Python DSL specific typing details to be stored in the - DslBase._param_defs attribute (or None if the type does not need to be - in _param_defs). + def add_attribute(self, k, arg): + """Add an attribute to the internal representation of a class. + + This method adds the argument `arg` to the data structure for a class + stored in `k`. In particular, the argument is added to the `k["args"]` + list, making sure required arguments are first in the list. If the + argument is of a type that needs Python DSL specific typing details to + be stored in the DslBase._param_defs attribute, then this is added to + `k["params"]`. """ try: type_, param = schema.get_python_type(arg["type"]) @@ -265,7 +266,22 @@ def get_attribute_data(self, arg): } if param is not None: param = {"name": arg["name"], "param": param} - return arg, param + if arg["required"]: + # insert in the right place so that all required arguments + # appear at the top of the argument list + i = 0 + for i in range(len(k["args"]) + 1): + if i == len(k["args"]): + break + if k["args"][i].get("positional"): + continue + if k["args"][i]["required"] is False: + break + k["args"].insert(i, arg) + else: + k["args"].append(arg) + if param and "params" in k: + k["params"].append(param) def property_to_python_class(self, p): """Return a dictionary with template data necessary to render a schema @@ -354,23 +370,7 @@ def property_to_python_class(self, p): ) while True: for arg in type_["properties"]: - python_arg, param = self.get_attribute_data(arg) - if python_arg["required"]: - # insert in the right place so that all required arguments - # appear at the top of the argument list - i = 0 - for i in range(len(k["args"]) + 1): - if i == len(k["args"]): - break - if k["args"][i].get("positional"): - continue - if k["args"][i]["required"] is False: - break - k["args"].insert(i, python_arg) - else: - k["args"].append(python_arg) - if param: - k["params"].append(param) + self.add_attribute(k, arg) if "inherits" in type_ and "type" in type_["inherits"]: type_ = schema.find_type( type_["inherits"]["type"]["name"], @@ -458,8 +458,7 @@ def interface_to_python_class(self, interface, interfaces): k = {"name": interface, "args": []} while True: for arg in type_["properties"]: - arg_type, _ = schema.get_attribute_data(arg) - k["args"].append(arg_type) + schema.add_attribute(k, arg) if "inherits" in type_ and "type" in type_["inherits"]: if "parent" not in k: k["parent"] = type_["inherits"]["type"]["name"] From 4977f9fda9b6d22e8d458f34f10ebf227b5d2d3b Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 10 Sep 2024 15:01:25 +0100 Subject: [PATCH 22/27] add server defaults to argument docstrings --- elasticsearch_dsl/query.py | 156 ++++++++++++++++++++----------------- elasticsearch_dsl/types.py | 153 +++++++++++++++++++++--------------- utils/generator.py | 7 +- 3 files changed, 184 insertions(+), 132 deletions(-) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 6b05067a..607df3ff 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -167,7 +167,7 @@ class Bool(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -327,7 +327,7 @@ class Boosting(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -391,18 +391,19 @@ class CombinedFields(Query): performing a search. :arg auto_generate_synonyms_phrase_query: If true, match phrase queries are automatically created for multi-term synonyms. + Defaults to `True` if omitted. :arg operator: Boolean logic used to interpret text in the query - value. + value. Defaults to `or` if omitted. :arg minimum_should_match: Minimum number of clauses that must match for a document to be returned. :arg zero_terms_query: Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a `stop` - filter. + filter. Defaults to `none` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -449,7 +450,7 @@ class ConstantScore(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -487,7 +488,7 @@ class DisMax(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -537,7 +538,7 @@ class DistanceFeature(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -567,7 +568,7 @@ class Exists(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -590,7 +591,7 @@ class FunctionScore(Query): are retrieved by a query. :arg boost_mode: Defines how he newly computed score is combined with - the score of the query + the score of the query Defaults to `multiply` if omitted. :arg functions: One or more functions that compute a new score for each document returned by the query. :arg max_boost: Restricts the new score to not exceed the provided @@ -600,11 +601,12 @@ class FunctionScore(Query): :arg query: A query that determines the documents for which a new score is computed. :arg score_mode: Specifies how the computed scores are combined + Defaults to `multiply` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -683,7 +685,8 @@ class GeoBoundingBox(Query): :arg type: :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude. Set to `COERCE` to also try to - infer correct latitude or longitude. + infer correct latitude or longitude. Defaults to `'strict'` if + omitted. :arg ignore_unmapped: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. @@ -691,7 +694,7 @@ class GeoBoundingBox(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -742,10 +745,11 @@ class GeoDistance(Query): considered to be matches. :arg distance_type: How to compute the distance. Set to `plane` for a faster calculation that's inaccurate on long distances and close - to the poles. + to the poles. Defaults to `'arc'` if omitted. :arg validation_method: Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude. Set to `COERCE` to also try to - infer correct latitude or longitude. + infer correct latitude or longitude. Defaults to `'strict'` if + omitted. :arg ignore_unmapped: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. @@ -753,7 +757,7 @@ class GeoDistance(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -798,13 +802,13 @@ class GeoPolygon(Query): """ :arg _field: The field to use in this query. :arg _value: The query value for the field. - :arg validation_method: + :arg validation_method: Defaults to `'strict'` if omitted. :arg ignore_unmapped: :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -850,7 +854,7 @@ class GeoShape(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -897,12 +901,13 @@ class HasChild(Query): If the parent document does not meet this limit, it is excluded from the search results. :arg score_mode: Indicates how scores for matching child documents - affect the root parent document’s relevance score. + affect the root parent document’s relevance score. Defaults to + `'none'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -962,7 +967,7 @@ class HasParent(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1005,7 +1010,7 @@ class Ids(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1063,7 +1068,7 @@ class Knn(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1132,7 +1137,7 @@ class MatchAll(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1197,7 +1202,7 @@ class MatchNone(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1288,7 +1293,8 @@ class MoreLikeThis(Query): when using this feature. Defaults to deactivated (0). :arg fail_on_unsupported_field: Controls whether the query should fail (throw an exception) if any of the specified fields are not of the - supported types (`text` or `keyword`). + supported types (`text` or `keyword`). Defaults to `True` if + omitted. :arg fields: A list of fields to fetch and analyze the text from. Defaults to the `index.query.default_field` index setting, which has a default value of `*`. @@ -1297,16 +1303,17 @@ class MoreLikeThis(Query): :arg max_doc_freq: The maximum document frequency above which the terms are ignored from the input document. :arg max_query_terms: The maximum number of query terms that can be - selected. + selected. Defaults to `25` if omitted. :arg max_word_length: The maximum word length above which the terms are ignored. Defaults to unbounded (`0`). :arg min_doc_freq: The minimum document frequency below which the - terms are ignored from the input document. + terms are ignored from the input document. Defaults to `5` if + omitted. :arg minimum_should_match: After the disjunctive query has been formed, this parameter controls the number of terms that must match. :arg min_term_freq: The minimum term frequency below which the terms - are ignored from the input document. + are ignored from the input document. Defaults to `2` if omitted. :arg min_word_length: The minimum word length below which the terms are ignored. :arg routing: @@ -1315,12 +1322,12 @@ class MoreLikeThis(Query): :arg unlike: Used in combination with `like` to exclude documents that match a set of terms. :arg version: - :arg version_type: + :arg version_type: Defaults to `'internal'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1402,6 +1409,7 @@ class MultiMatch(Query): into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. + Defaults to `True` if omitted. :arg cutoff_frequency: :arg fields: The fields to be queried. Defaults to the `index.query.default_field` index settings, which in turn defaults @@ -1411,15 +1419,15 @@ class MultiMatch(Query): :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to `ba`). Can be applied to the term subqueries constructed for all - terms but the final term. + terms but the final term. Defaults to `True` if omitted. :arg lenient: If `true`, format-based errors, such as providing a text query value for a numeric field, are ignored. :arg max_expansions: Maximum number of terms to which the query will - expand. + expand. Defaults to `50` if omitted. :arg minimum_should_match: Minimum number of clauses that must match for a document to be returned. :arg operator: Boolean logic used to interpret text in the query - value. + value. Defaults to `'or'` if omitted. :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. :arg slop: Maximum number of positions allowed between matching @@ -1427,14 +1435,15 @@ class MultiMatch(Query): :arg tie_breaker: Determines how scores for each per-term blended query and scores across groups are combined. :arg type: How `the` multi_match query is executed internally. + Defaults to `'best_fields'` if omitted. :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` - filter. + filter. Defaults to `'none'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1514,12 +1523,12 @@ class Nested(Query): not return any documents instead of an error. :arg inner_hits: If defined, each search hit will contain inner hits. :arg score_mode: How scores for matching child objects affect the root - parent document’s relevance score. + parent document’s relevance score. Defaults to `'avg'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1566,7 +1575,7 @@ class ParentId(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1611,7 +1620,7 @@ class Percolate(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1664,7 +1673,7 @@ class Pinned(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1720,35 +1729,39 @@ class QueryString(Query): search. :arg allow_leading_wildcard: If `true`, the wildcard characters `*` and `?` are allowed as the first character of the query string. + Defaults to `True` if omitted. :arg analyzer: Analyzer used to convert text in the query string into tokens. :arg analyze_wildcard: If `true`, the query attempts to analyze wildcard terms in the query string. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. + Defaults to `True` if omitted. :arg default_field: Default field to search if no field is provided in the query string. Supports wildcards (`*`). Defaults to the `index.query.default_field` index setting, which has a default value of `*`. :arg default_operator: Default boolean logic used to interpret text in - the query string if no operators are specified. + the query string if no operators are specified. Defaults to `'or'` + if omitted. :arg enable_position_increments: If `true`, enable position increments - in queries constructed from a `query_string` search. + in queries constructed from a `query_string` search. Defaults to + `True` if omitted. :arg escape: :arg fields: Array of fields to search. Supports wildcards (`*`). :arg fuzziness: Maximum edit distance allowed for fuzzy matching. :arg fuzzy_max_expansions: Maximum number of terms to which the query - expands for fuzzy matching. + expands for fuzzy matching. Defaults to `50` if omitted. :arg fuzzy_prefix_length: Number of beginning characters left unchanged for fuzzy matching. :arg fuzzy_rewrite: Method used to rewrite the query. :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to - `ba`). + `ba`). Defaults to `True` if omitted. :arg lenient: If `true`, format-based errors, such as providing a text value for a numeric field, are ignored. :arg max_determinized_states: Maximum number of automaton states - required for the query. + required for the query. Defaults to `10000` if omitted. :arg minimum_should_match: Minimum number of clauses that must match for a document to be returned. :arg phrase_slop: Maximum number of positions allowed between matching @@ -1765,11 +1778,12 @@ class QueryString(Query): :arg time_zone: Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query string to UTC. :arg type: Determines how the query matches and scores documents. + Defaults to `'best_fields'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1891,7 +1905,7 @@ class RankFeature(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1959,7 +1973,7 @@ class Rule(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1999,7 +2013,7 @@ class Script(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2030,7 +2044,7 @@ class ScriptScore(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2070,7 +2084,7 @@ class Semantic(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2100,7 +2114,7 @@ class Shape(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2136,17 +2150,19 @@ class SimpleQueryString(Query): wildcard terms in the query string. :arg auto_generate_synonyms_phrase_query: If `true`, the parser creates a match_phrase query for each multi-position token. + Defaults to `True` if omitted. :arg default_operator: Default boolean logic used to interpret text in - the query string if no operators are specified. + the query string if no operators are specified. Defaults to `'or'` + if omitted. :arg fields: Array of fields you wish to search. Accepts wildcard expressions. You also can boost relevance scores for matches to particular fields using a caret (`^`) notation. Defaults to the `index.query.default_field index` setting, which has a default value of `*`. :arg flags: List of enabled operators for the simple query string - syntax. + syntax. Defaults to `ALL` if omitted. :arg fuzzy_max_expansions: Maximum number of terms to which the query - expands for fuzzy matching. + expands for fuzzy matching. Defaults to `50` if omitted. :arg fuzzy_prefix_length: Number of beginning characters left unchanged for fuzzy matching. :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include @@ -2162,7 +2178,7 @@ class SimpleQueryString(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2224,7 +2240,7 @@ class SpanContaining(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2253,7 +2269,7 @@ class SpanFieldMasking(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2282,7 +2298,7 @@ class SpanFirst(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2312,7 +2328,7 @@ class SpanMulti(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2346,7 +2362,7 @@ class SpanNear(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2394,7 +2410,7 @@ class SpanNot(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2433,7 +2449,7 @@ class SpanOr(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2485,7 +2501,7 @@ class SpanWithin(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2536,7 +2552,7 @@ class SparseVector(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2605,7 +2621,7 @@ class Terms(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2740,7 +2756,7 @@ class Wrapper(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2764,7 +2780,7 @@ class Type(Query): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ diff --git a/elasticsearch_dsl/types.py b/elasticsearch_dsl/types.py index 391bf0e3..cb3da8f9 100644 --- a/elasticsearch_dsl/types.py +++ b/elasticsearch_dsl/types.py @@ -32,7 +32,7 @@ class QueryBase(AttrDict[Any]): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -65,7 +65,7 @@ class CommonTermsQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -214,19 +214,21 @@ def __init__( class FuzzyQuery(QueryBase): """ :arg value: (required) Term you wish to find in the provided field. - :arg max_expansions: Maximum number of variations created. + :arg max_expansions: Maximum number of variations created. Defaults to + `50` if omitted. :arg prefix_length: Number of beginning characters left unchanged when creating expansions. :arg rewrite: Number of beginning characters left unchanged when - creating expansions. + creating expansions. Defaults to `constant_score` if omitted. :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example `ab` to `ba`). + two adjacent characters (for example `ab` to `ba`). Defaults to + `True` if omitted. :arg fuzziness: Maximum edit distance allowed for matching. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -327,6 +329,7 @@ class GeoShapeFieldQuery(AttrDict[Any]): :arg indexed_shape: Query using an indexed shape retrieved from the the specified document and path. :arg relation: Spatial relation operator used to search a geo field. + Defaults to `intersects` if omitted. """ shape: Any @@ -362,6 +365,7 @@ class InnerHits(AttrDict[Any]): response. Useful when a search request contains multiple inner hits. :arg size: The maximum number of hits to return per `inner_hits`. + Defaults to `3` if omitted. :arg from: Inner hit starting document offset. :arg collapse: :arg docvalue_fields: @@ -506,7 +510,7 @@ class IntervalsQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -585,7 +589,7 @@ class LikeDocument(AttrDict[Any]): :arg per_field_analyzer: Overrides the default analyzer. :arg routing: :arg version: - :arg version_type: + :arg version_type: Defaults to `'internal'` if omitted. """ doc: Any @@ -654,15 +658,16 @@ class MatchBoolPrefixQuery(QueryBase): :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to `ba`). Can be applied to the term subqueries constructed for all - terms but the final term. + terms but the final term. Defaults to `True` if omitted. :arg max_expansions: Maximum number of terms to which the query will expand. Can be applied to the term subqueries constructed for all - terms but the final term. + terms but the final term. Defaults to `50` if omitted. :arg minimum_should_match: Minimum number of clauses that must match for a document to be returned. Applied to the constructed bool query. :arg operator: Boolean logic used to interpret text in the query - value. Applied to the constructed bool query. + value. Applied to the constructed bool query. Defaults to `'or'` + if omitted. :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. Can be applied to the term subqueries constructed for all terms but the final term. @@ -670,7 +675,7 @@ class MatchBoolPrefixQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -733,17 +738,18 @@ class MatchPhrasePrefixQuery(QueryBase): :arg analyzer: Analyzer used to convert text in the query value into tokens. :arg max_expansions: Maximum number of terms to which the last - provided term of the query value will expand. + provided term of the query value will expand. Defaults to `50` if + omitted. :arg slop: Maximum number of positions allowed between matching tokens. :arg zero_terms_query: Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a `stop` - filter. + filter. Defaults to `none` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -794,12 +800,12 @@ class MatchPhraseQuery(QueryBase): tokens. :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` - filter. + filter. Defaults to `'none'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -844,30 +850,31 @@ class MatchQuery(QueryBase): into tokens. :arg auto_generate_synonyms_phrase_query: If `true`, match phrase queries are automatically created for multi-term synonyms. + Defaults to `True` if omitted. :arg cutoff_frequency: :arg fuzziness: Maximum edit distance allowed for matching. :arg fuzzy_rewrite: Method used to rewrite the query. :arg fuzzy_transpositions: If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to - `ba`). + `ba`). Defaults to `True` if omitted. :arg lenient: If `true`, format-based errors, such as providing a text query value for a numeric field, are ignored. :arg max_expansions: Maximum number of terms to which the query will - expand. + expand. Defaults to `50` if omitted. :arg minimum_should_match: Minimum number of clauses that must match for a document to be returned. :arg operator: Boolean logic used to interpret text in the query - value. + value. Defaults to `'or'` if omitted. :arg prefix_length: Number of beginning characters left unchanged for fuzzy matching. :arg zero_terms_query: Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` - filter. + filter. Defaults to `'none'` if omitted. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -978,7 +985,7 @@ class PrefixQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1102,13 +1109,13 @@ class RegexpQuery(QueryBase): underlying field’s mapping. :arg flags: Enables optional operators for the regular expression. :arg max_determinized_states: Maximum number of automaton states - required for the query. + required for the query. Defaults to `10000` if omitted. :arg rewrite: Method used to rewrite the query. :arg boost: Floating point number used to decrease or increase the relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1156,7 +1163,8 @@ class Script(AttrDict[Any]): :arg params: Specifies any named parameters that are passed into the script as variables. Use parameters instead of hard-coded values to decrease compile time. - :arg lang: Specifies the language the script is written in. + :arg lang: Specifies the language the script is written in. Defaults + to `painless` if omitted. :arg options: """ @@ -1332,7 +1340,7 @@ class SpanTermQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1368,7 +1376,7 @@ class TermQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1442,7 +1450,7 @@ class TermsSetQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1488,7 +1496,7 @@ class TextExpansionQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1527,9 +1535,11 @@ class TokenPruningConfig(AttrDict[Any]): """ :arg tokens_freq_ratio_threshold: Tokens whose frequency is more than this threshold times the average frequency of all tokens in the - specified field are considered outliers and pruned. + specified field are considered outliers and pruned. Defaults to + `5` if omitted. :arg tokens_weight_threshold: Tokens whose weight is less than this - threshold are considered nonsignificant and pruned. + threshold are considered nonsignificant and pruned. Defaults to + `0.4` if omitted. :arg only_score_pruned_tokens: Whether to only score pruned tokens, vs only scoring kept tokens. """ @@ -1665,7 +1675,7 @@ class WeightedTokensQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1711,7 +1721,7 @@ class WildcardQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -1868,7 +1878,9 @@ class HighlightBase(AttrDict[Any]): """ :arg type: :arg boundary_chars: A string that contains each boundary character. + Defaults to `.,!? \t\n` if omitted. :arg boundary_max_scan: How far to scan for boundary characters. + Defaults to `20` if omitted. :arg boundary_scanner: Specifies how to break the highlighted fragments: chars, sentence, or word. Only valid for the unified and fvh highlighters. Defaults to `sentence` for the `unified` @@ -1876,12 +1888,13 @@ class HighlightBase(AttrDict[Any]): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + Defaults to `Locale.ROOT` if omitted. :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` - highlighter. + highlighter. Defaults to `span` if omitted. :arg fragment_size: The size of the highlighted fragment in - characters. + characters. Defaults to `100` if omitted. :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query @@ -1902,19 +1915,22 @@ class HighlightBase(AttrDict[Any]): returned. Instead, the entire field contents are highlighted and returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If - `number_of_fragments` is `0`, `fragment_size` is ignored. + `number_of_fragments` is `0`, `fragment_size` is ignored. Defaults + to `5` if omitted. :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will output the most relevant fragments first. Each highlighter applies - its own logic to compute relevancy scores. + its own logic to compute relevancy scores. Defaults to `none` if + omitted. :arg phrase_limit: Controls the number of matching phrases in a document that are considered. Prevents the `fvh` highlighter from analyzing too many phrases and consuming too much memory. When using `matched_fields`, `phrase_limit` phrases per matched field are considered. Raising the limit increases query time and consumes more memory. Only supported by the `fvh` highlighter. + Defaults to `256` if omitted. :arg post_tags: Use in conjunction with `pre_tags` to define the HTML tags to use for the highlighted text. By default, highlighted text is wrapped in `` and `` tags. @@ -1923,7 +1939,7 @@ class HighlightBase(AttrDict[Any]): is wrapped in `` and `` tags. :arg require_field_match: By default, only fields that contains a query match are highlighted. Set to `false` to highlight all - fields. + fields. Defaults to `True` if omitted. :arg tags_schema: Set to `styled` to use the built-in tag schema. """ @@ -2028,7 +2044,9 @@ class Highlight(HighlightBase): :arg encoder: :arg type: :arg boundary_chars: A string that contains each boundary character. + Defaults to `.,!? \t\n` if omitted. :arg boundary_max_scan: How far to scan for boundary characters. + Defaults to `20` if omitted. :arg boundary_scanner: Specifies how to break the highlighted fragments: chars, sentence, or word. Only valid for the unified and fvh highlighters. Defaults to `sentence` for the `unified` @@ -2036,12 +2054,13 @@ class Highlight(HighlightBase): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + Defaults to `Locale.ROOT` if omitted. :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` - highlighter. + highlighter. Defaults to `span` if omitted. :arg fragment_size: The size of the highlighted fragment in - characters. + characters. Defaults to `100` if omitted. :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query @@ -2062,19 +2081,22 @@ class Highlight(HighlightBase): returned. Instead, the entire field contents are highlighted and returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If - `number_of_fragments` is `0`, `fragment_size` is ignored. + `number_of_fragments` is `0`, `fragment_size` is ignored. Defaults + to `5` if omitted. :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will output the most relevant fragments first. Each highlighter applies - its own logic to compute relevancy scores. + its own logic to compute relevancy scores. Defaults to `none` if + omitted. :arg phrase_limit: Controls the number of matching phrases in a document that are considered. Prevents the `fvh` highlighter from analyzing too many phrases and consuming too much memory. When using `matched_fields`, `phrase_limit` phrases per matched field are considered. Raising the limit increases query time and consumes more memory. Only supported by the `fvh` highlighter. + Defaults to `256` if omitted. :arg post_tags: Use in conjunction with `pre_tags` to define the HTML tags to use for the highlighted text. By default, highlighted text is wrapped in `` and `` tags. @@ -2083,7 +2105,7 @@ class Highlight(HighlightBase): is wrapped in `` and `` tags. :arg require_field_match: By default, only fields that contains a query match are highlighted. Set to `false` to highlight all - fields. + fields. Defaults to `True` if omitted. :arg tags_schema: Set to `styled` to use the built-in tag schema. """ @@ -2302,7 +2324,7 @@ class IntervalsAllOf(AttrDict[Any]): match. :arg max_gaps: Maximum number of positions between the matching terms. Intervals produced by the rules further apart than this are not - considered matches. + considered matches. Defaults to `-1` if omitted. :arg ordered: If `true`, intervals produced by the rules should appear in the order in which they are specified. :arg filter: Rule used to filter returned intervals. @@ -2368,11 +2390,13 @@ class IntervalsFuzzy(AttrDict[Any]): """ :arg term: (required) The term to match. :arg analyzer: Analyzer used to normalize the term. - :arg fuzziness: Maximum edit distance allowed for matching. + :arg fuzziness: Maximum edit distance allowed for matching. Defaults + to `auto` if omitted. :arg prefix_length: Number of beginning characters left unchanged when creating expansions. :arg transpositions: Indicates whether edits include transpositions of - two adjacent characters (for example, `ab` to `ba`). + two adjacent characters (for example, `ab` to `ba`). Defaults to + `True` if omitted. :arg use_field: If specified, match intervals from this field rather than the top-level field. The `term` is normalized using the search analyzer from this field, unless `analyzer` is specified @@ -2417,7 +2441,8 @@ class IntervalsMatch(AttrDict[Any]): :arg query: (required) Text you wish to find in the provided field. :arg analyzer: Analyzer used to analyze terms in the query. :arg max_gaps: Maximum number of positions between the matching terms. - Terms further apart than this are not considered matches. + Terms further apart than this are not considered matches. Defaults + to `-1` if omitted. :arg ordered: If `true`, matching terms must appear in their specified order. :arg use_field: If specified, match intervals from this field rather @@ -2557,7 +2582,7 @@ class SpanContainingQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2594,7 +2619,7 @@ class SpanFieldMaskingQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2632,7 +2657,7 @@ class SpanFirstQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2669,7 +2694,7 @@ class SpanMultiTermQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2704,7 +2729,7 @@ class SpanNearQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2755,7 +2780,7 @@ class SpanNotQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2803,7 +2828,7 @@ class SpanOrQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2840,7 +2865,7 @@ class SpanWithinQuery(QueryBase): relevance scores of the query. Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the - relevance score. + relevance score. Defaults to `1` if omitted. :arg _name: """ @@ -2876,7 +2901,9 @@ class HighlightField(HighlightBase): :arg analyzer: :arg type: :arg boundary_chars: A string that contains each boundary character. + Defaults to `.,!? \t\n` if omitted. :arg boundary_max_scan: How far to scan for boundary characters. + Defaults to `20` if omitted. :arg boundary_scanner: Specifies how to break the highlighted fragments: chars, sentence, or word. Only valid for the unified and fvh highlighters. Defaults to `sentence` for the `unified` @@ -2884,12 +2911,13 @@ class HighlightField(HighlightBase): :arg boundary_scanner_locale: Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. + Defaults to `Locale.ROOT` if omitted. :arg force_source: :arg fragmenter: Specifies how text should be broken up in highlight snippets: `simple` or `span`. Only valid for the `plain` - highlighter. + highlighter. Defaults to `span` if omitted. :arg fragment_size: The size of the highlighted fragment in - characters. + characters. Defaults to `100` if omitted. :arg highlight_filter: :arg highlight_query: Highlight matches for a query other than the search query. This is especially useful if you use a rescore query @@ -2910,19 +2938,22 @@ class HighlightField(HighlightBase): returned. Instead, the entire field contents are highlighted and returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. If - `number_of_fragments` is `0`, `fragment_size` is ignored. + `number_of_fragments` is `0`, `fragment_size` is ignored. Defaults + to `5` if omitted. :arg options: :arg order: Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: `none`). Setting this option to `score` will output the most relevant fragments first. Each highlighter applies - its own logic to compute relevancy scores. + its own logic to compute relevancy scores. Defaults to `none` if + omitted. :arg phrase_limit: Controls the number of matching phrases in a document that are considered. Prevents the `fvh` highlighter from analyzing too many phrases and consuming too much memory. When using `matched_fields`, `phrase_limit` phrases per matched field are considered. Raising the limit increases query time and consumes more memory. Only supported by the `fvh` highlighter. + Defaults to `256` if omitted. :arg post_tags: Use in conjunction with `pre_tags` to define the HTML tags to use for the highlighted text. By default, highlighted text is wrapped in `` and `` tags. @@ -2931,7 +2962,7 @@ class HighlightField(HighlightBase): is wrapped in `` and `` tags. :arg require_field_match: By default, only fields that contains a query match are highlighted. Set to `false` to highlight all - fields. + fields. Defaults to `True` if omitted. :arg tags_schema: Set to `styled` to use the built-in tag schema. """ diff --git a/utils/generator.py b/utils/generator.py index de2de5ac..bb4bcfc0 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -254,8 +254,13 @@ def add_attribute(self, k, arg): type_ = add_dict_type(type_) # interfaces can be given as dicts type_ = add_not_set(type_) required = "(required) " if arg["required"] else "" + server_default = ( + f" Defaults to `{arg['serverDefault']}` if omitted." + if arg.get("serverDefault") + else "" + ) doc = wrapped_doc( - f":arg {arg['name']}: {required}{arg.get('description', '')}", + f":arg {arg['name']}: {required}{arg.get('description', '')}{server_default}", subsequent_indent=" ", ) arg = { From 97643e118d1a54dabbf41afee298200cb2e03268 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 10 Sep 2024 15:35:48 +0100 Subject: [PATCH 23/27] remove unnecessary quotes from type hints in types.py --- elasticsearch_dsl/types.py | 1594 ++++++++++++++++------------------ utils/generator.py | 18 +- utils/templates/types.py.tpl | 2 +- 3 files changed, 784 insertions(+), 830 deletions(-) diff --git a/elasticsearch_dsl/types.py b/elasticsearch_dsl/types.py index cb3da8f9..e75770fb 100644 --- a/elasticsearch_dsl/types.py +++ b/elasticsearch_dsl/types.py @@ -19,7 +19,7 @@ from elastic_transport.client_utils import DEFAULT, DefaultType -from elasticsearch_dsl import Query, function, types +from elasticsearch_dsl import Query, function from elasticsearch_dsl.document_base import InstrumentedField from elasticsearch_dsl.utils import AttrDict @@ -36,14 +36,14 @@ class QueryBase(AttrDict[Any]): :arg _name: """ - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if boost is not DEFAULT: @@ -69,26 +69,26 @@ class CommonTermsQuery(QueryBase): :arg _name: """ - query: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - cutoff_frequency: Union[float, "DefaultType"] - high_freq_operator: Union[Literal["and", "or"], "DefaultType"] - low_freq_operator: Union[Literal["and", "or"], "DefaultType"] - minimum_should_match: Union[int, str, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + query: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + cutoff_frequency: Union[float, DefaultType] + high_freq_operator: Union[Literal["and", "or"], DefaultType] + low_freq_operator: Union[Literal["and", "or"], DefaultType] + minimum_should_match: Union[int, str, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, - high_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, - low_freq_operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, - minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + cutoff_frequency: Union[float, DefaultType] = DEFAULT, + high_freq_operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, + low_freq_operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, + minimum_should_match: Union[int, str, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -118,18 +118,18 @@ class CoordsGeoBounds(AttrDict[Any]): :arg right: (required) """ - top: Union[float, "DefaultType"] - bottom: Union[float, "DefaultType"] - left: Union[float, "DefaultType"] - right: Union[float, "DefaultType"] + top: Union[float, DefaultType] + bottom: Union[float, DefaultType] + left: Union[float, DefaultType] + right: Union[float, DefaultType] def __init__( self, *, - top: Union[float, "DefaultType"] = DEFAULT, - bottom: Union[float, "DefaultType"] = DEFAULT, - left: Union[float, "DefaultType"] = DEFAULT, - right: Union[float, "DefaultType"] = DEFAULT, + top: Union[float, DefaultType] = DEFAULT, + bottom: Union[float, DefaultType] = DEFAULT, + left: Union[float, DefaultType] = DEFAULT, + right: Union[float, DefaultType] = DEFAULT, **kwargs: Any, ): if top is not DEFAULT: @@ -168,28 +168,28 @@ class FunctionScoreContainer(AttrDict[Any]): :arg weight: """ - exp: Union["function.DecayFunction", "DefaultType"] - gauss: Union["function.DecayFunction", "DefaultType"] - linear: Union["function.DecayFunction", "DefaultType"] - field_value_factor: Union["function.FieldValueFactorScore", "DefaultType"] - random_score: Union["function.RandomScore", "DefaultType"] - script_score: Union["function.ScriptScore", "DefaultType"] - filter: Union[Query, "DefaultType"] - weight: Union[float, "DefaultType"] + exp: Union[function.DecayFunction, DefaultType] + gauss: Union[function.DecayFunction, DefaultType] + linear: Union[function.DecayFunction, DefaultType] + field_value_factor: Union[function.FieldValueFactorScore, DefaultType] + random_score: Union[function.RandomScore, DefaultType] + script_score: Union[function.ScriptScore, DefaultType] + filter: Union[Query, DefaultType] + weight: Union[float, DefaultType] def __init__( self, *, - exp: Union["function.DecayFunction", "DefaultType"] = DEFAULT, - gauss: Union["function.DecayFunction", "DefaultType"] = DEFAULT, - linear: Union["function.DecayFunction", "DefaultType"] = DEFAULT, + exp: Union[function.DecayFunction, DefaultType] = DEFAULT, + gauss: Union[function.DecayFunction, DefaultType] = DEFAULT, + linear: Union[function.DecayFunction, DefaultType] = DEFAULT, field_value_factor: Union[ - "function.FieldValueFactorScore", "DefaultType" + function.FieldValueFactorScore, DefaultType ] = DEFAULT, - random_score: Union["function.RandomScore", "DefaultType"] = DEFAULT, - script_score: Union["function.ScriptScore", "DefaultType"] = DEFAULT, - filter: Union[Query, "DefaultType"] = DEFAULT, - weight: Union[float, "DefaultType"] = DEFAULT, + random_score: Union[function.RandomScore, DefaultType] = DEFAULT, + script_score: Union[function.ScriptScore, DefaultType] = DEFAULT, + filter: Union[Query, DefaultType] = DEFAULT, + weight: Union[float, DefaultType] = DEFAULT, **kwargs: Any, ): if exp is not DEFAULT: @@ -232,26 +232,26 @@ class FuzzyQuery(QueryBase): :arg _name: """ - value: Union[str, float, bool, "DefaultType"] - max_expansions: Union[int, "DefaultType"] - prefix_length: Union[int, "DefaultType"] - rewrite: Union[str, "DefaultType"] - transpositions: Union[bool, "DefaultType"] - fuzziness: Union[str, int, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + value: Union[str, float, bool, DefaultType] + max_expansions: Union[int, DefaultType] + prefix_length: Union[int, DefaultType] + rewrite: Union[str, DefaultType] + transpositions: Union[bool, DefaultType] + fuzziness: Union[str, int, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - value: Union[str, float, bool, "DefaultType"] = DEFAULT, - max_expansions: Union[int, "DefaultType"] = DEFAULT, - prefix_length: Union[int, "DefaultType"] = DEFAULT, - rewrite: Union[str, "DefaultType"] = DEFAULT, - transpositions: Union[bool, "DefaultType"] = DEFAULT, - fuzziness: Union[str, int, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, float, bool, DefaultType] = DEFAULT, + max_expansions: Union[int, DefaultType] = DEFAULT, + prefix_length: Union[int, DefaultType] = DEFAULT, + rewrite: Union[str, DefaultType] = DEFAULT, + transpositions: Union[bool, DefaultType] = DEFAULT, + fuzziness: Union[str, int, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if value is not DEFAULT: @@ -278,9 +278,9 @@ class GeoHashLocation(AttrDict[Any]): :arg geohash: (required) """ - geohash: Union[str, "DefaultType"] + geohash: Union[str, DefaultType] - def __init__(self, *, geohash: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + def __init__(self, *, geohash: Union[str, DefaultType] = DEFAULT, **kwargs: Any): if geohash is not DEFAULT: kwargs["geohash"] = geohash super().__init__(kwargs) @@ -292,13 +292,9 @@ class GeoPolygonPoints(AttrDict[Any]): """ points: Union[ - Sequence[ - Union[ - "types.LatLonGeoLocation", "types.GeoHashLocation", Sequence[float], str - ] - ], + Sequence[Union["LatLonGeoLocation", "GeoHashLocation", Sequence[float], str]], Dict[str, Any], - "DefaultType", + DefaultType, ] def __init__( @@ -306,15 +302,10 @@ def __init__( *, points: Union[ Sequence[ - Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", - Sequence[float], - str, - ] + Union["LatLonGeoLocation", "GeoHashLocation", Sequence[float], str] ], Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, **kwargs: Any, ): @@ -333,20 +324,18 @@ class GeoShapeFieldQuery(AttrDict[Any]): """ shape: Any - indexed_shape: Union["types.FieldLookup", Dict[str, Any], "DefaultType"] + indexed_shape: Union["FieldLookup", Dict[str, Any], DefaultType] relation: Union[ - Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + Literal["intersects", "disjoint", "within", "contains"], DefaultType ] def __init__( self, *, shape: Any = DEFAULT, - indexed_shape: Union[ - "types.FieldLookup", Dict[str, Any], "DefaultType" - ] = DEFAULT, + indexed_shape: Union["FieldLookup", Dict[str, Any], DefaultType] = DEFAULT, relation: Union[ - Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + Literal["intersects", "disjoint", "within", "contains"], DefaultType ] = DEFAULT, **kwargs: Any, ): @@ -383,82 +372,78 @@ class InnerHits(AttrDict[Any]): :arg version: """ - name: Union[str, "DefaultType"] - size: Union[int, "DefaultType"] - from_: Union[int, "DefaultType"] - collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] - docvalue_fields: Union[ - Sequence["types.FieldAndFormat"], Dict[str, Any], "DefaultType" - ] - explain: Union[bool, "DefaultType"] - highlight: Union["types.Highlight", Dict[str, Any], "DefaultType"] - ignore_unmapped: Union[bool, "DefaultType"] + name: Union[str, DefaultType] + size: Union[int, DefaultType] + from_: Union[int, DefaultType] + collapse: Union["FieldCollapse", Dict[str, Any], DefaultType] + docvalue_fields: Union[Sequence["FieldAndFormat"], Dict[str, Any], DefaultType] + explain: Union[bool, DefaultType] + highlight: Union["Highlight", Dict[str, Any], DefaultType] + ignore_unmapped: Union[bool, DefaultType] script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "types.ScriptField"], + Mapping[Union[str, InstrumentedField], "ScriptField"], Dict[str, Any], - "DefaultType", + DefaultType, ] - seq_no_primary_term: Union[bool, "DefaultType"] + seq_no_primary_term: Union[bool, DefaultType] fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] sort: Union[ - Union[Union[str, "InstrumentedField"], "types.SortOptions"], - Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]], + Union[Union[str, InstrumentedField], "SortOptions"], + Sequence[Union[Union[str, InstrumentedField], "SortOptions"]], Dict[str, Any], - "DefaultType", + DefaultType, ] - _source: Union[bool, "types.SourceFilter", Dict[str, Any], "DefaultType"] + _source: Union[bool, "SourceFilter", Dict[str, Any], DefaultType] stored_fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] - track_scores: Union[bool, "DefaultType"] - version: Union[bool, "DefaultType"] + track_scores: Union[bool, DefaultType] + version: Union[bool, DefaultType] def __init__( self, *, - name: Union[str, "DefaultType"] = DEFAULT, - size: Union[int, "DefaultType"] = DEFAULT, - from_: Union[int, "DefaultType"] = DEFAULT, - collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, + name: Union[str, DefaultType] = DEFAULT, + size: Union[int, DefaultType] = DEFAULT, + from_: Union[int, DefaultType] = DEFAULT, + collapse: Union["FieldCollapse", Dict[str, Any], DefaultType] = DEFAULT, docvalue_fields: Union[ - Sequence["types.FieldAndFormat"], Dict[str, Any], "DefaultType" + Sequence["FieldAndFormat"], Dict[str, Any], DefaultType ] = DEFAULT, - explain: Union[bool, "DefaultType"] = DEFAULT, - highlight: Union["types.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT, - ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, + explain: Union[bool, DefaultType] = DEFAULT, + highlight: Union["Highlight", Dict[str, Any], DefaultType] = DEFAULT, + ignore_unmapped: Union[bool, DefaultType] = DEFAULT, script_fields: Union[ - Mapping[Union[str, "InstrumentedField"], "types.ScriptField"], + Mapping[Union[str, InstrumentedField], "ScriptField"], Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, - seq_no_primary_term: Union[bool, "DefaultType"] = DEFAULT, + seq_no_primary_term: Union[bool, DefaultType] = DEFAULT, fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] = DEFAULT, sort: Union[ - Union[Union[str, "InstrumentedField"], "types.SortOptions"], - Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]], + Union[Union[str, InstrumentedField], "SortOptions"], + Sequence[Union[Union[str, InstrumentedField], "SortOptions"]], Dict[str, Any], - "DefaultType", - ] = DEFAULT, - _source: Union[ - bool, "types.SourceFilter", Dict[str, Any], "DefaultType" + DefaultType, ] = DEFAULT, + _source: Union[bool, "SourceFilter", Dict[str, Any], DefaultType] = DEFAULT, stored_fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] = DEFAULT, - track_scores: Union[bool, "DefaultType"] = DEFAULT, - version: Union[bool, "DefaultType"] = DEFAULT, + track_scores: Union[bool, DefaultType] = DEFAULT, + version: Union[bool, DefaultType] = DEFAULT, **kwargs: Any, ): if name is not DEFAULT: @@ -514,28 +499,26 @@ class IntervalsQuery(QueryBase): :arg _name: """ - all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] - any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] - fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] - match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] - prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] - wildcard: Union["types.IntervalsWildcard", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + all_of: Union["IntervalsAllOf", Dict[str, Any], DefaultType] + any_of: Union["IntervalsAnyOf", Dict[str, Any], DefaultType] + fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] + match: Union["IntervalsMatch", Dict[str, Any], DefaultType] + prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] + wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, - any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, - fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, - match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, - prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, - wildcard: Union[ - "types.IntervalsWildcard", Dict[str, Any], "DefaultType" - ] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + all_of: Union["IntervalsAllOf", Dict[str, Any], DefaultType] = DEFAULT, + any_of: Union["IntervalsAnyOf", Dict[str, Any], DefaultType] = DEFAULT, + fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] = DEFAULT, + match: Union["IntervalsMatch", Dict[str, Any], DefaultType] = DEFAULT, + prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] = DEFAULT, + wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if all_of is not DEFAULT: @@ -563,14 +546,14 @@ class LatLonGeoLocation(AttrDict[Any]): :arg lon: (required) Longitude """ - lat: Union[float, "DefaultType"] - lon: Union[float, "DefaultType"] + lat: Union[float, DefaultType] + lon: Union[float, DefaultType] def __init__( self, *, - lat: Union[float, "DefaultType"] = DEFAULT, - lon: Union[float, "DefaultType"] = DEFAULT, + lat: Union[float, DefaultType] = DEFAULT, + lon: Union[float, DefaultType] = DEFAULT, **kwargs: Any, ): if lat is not DEFAULT: @@ -593,34 +576,30 @@ class LikeDocument(AttrDict[Any]): """ doc: Any - fields: Union[Sequence[Union[str, "InstrumentedField"]], "DefaultType"] - _id: Union[str, "DefaultType"] - _index: Union[str, "DefaultType"] - per_field_analyzer: Union[ - Mapping[Union[str, "InstrumentedField"], str], "DefaultType" - ] - routing: Union[str, "DefaultType"] - version: Union[int, "DefaultType"] + fields: Union[Sequence[Union[str, InstrumentedField]], DefaultType] + _id: Union[str, DefaultType] + _index: Union[str, DefaultType] + per_field_analyzer: Union[Mapping[Union[str, InstrumentedField], str], DefaultType] + routing: Union[str, DefaultType] + version: Union[int, DefaultType] version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "DefaultType" + Literal["internal", "external", "external_gte", "force"], DefaultType ] def __init__( self, *, doc: Any = DEFAULT, - fields: Union[ - Sequence[Union[str, "InstrumentedField"]], "DefaultType" - ] = DEFAULT, - _id: Union[str, "DefaultType"] = DEFAULT, - _index: Union[str, "DefaultType"] = DEFAULT, + fields: Union[Sequence[Union[str, InstrumentedField]], DefaultType] = DEFAULT, + _id: Union[str, DefaultType] = DEFAULT, + _index: Union[str, DefaultType] = DEFAULT, per_field_analyzer: Union[ - Mapping[Union[str, "InstrumentedField"], str], "DefaultType" + Mapping[Union[str, InstrumentedField], str], DefaultType ] = DEFAULT, - routing: Union[str, "DefaultType"] = DEFAULT, - version: Union[int, "DefaultType"] = DEFAULT, + routing: Union[str, DefaultType] = DEFAULT, + version: Union[int, DefaultType] = DEFAULT, version_type: Union[ - Literal["internal", "external", "external_gte", "force"], "DefaultType" + Literal["internal", "external", "external_gte", "force"], DefaultType ] = DEFAULT, **kwargs: Any, ): @@ -679,32 +658,32 @@ class MatchBoolPrefixQuery(QueryBase): :arg _name: """ - query: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - fuzziness: Union[str, int, "DefaultType"] - fuzzy_rewrite: Union[str, "DefaultType"] - fuzzy_transpositions: Union[bool, "DefaultType"] - max_expansions: Union[int, "DefaultType"] - minimum_should_match: Union[int, str, "DefaultType"] - operator: Union[Literal["and", "or"], "DefaultType"] - prefix_length: Union[int, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + query: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + fuzziness: Union[str, int, DefaultType] + fuzzy_rewrite: Union[str, DefaultType] + fuzzy_transpositions: Union[bool, DefaultType] + max_expansions: Union[int, DefaultType] + minimum_should_match: Union[int, str, DefaultType] + operator: Union[Literal["and", "or"], DefaultType] + prefix_length: Union[int, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - fuzziness: Union[str, int, "DefaultType"] = DEFAULT, - fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, - fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, - max_expansions: Union[int, "DefaultType"] = DEFAULT, - minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, - operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, - prefix_length: Union[int, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + fuzziness: Union[str, int, DefaultType] = DEFAULT, + fuzzy_rewrite: Union[str, DefaultType] = DEFAULT, + fuzzy_transpositions: Union[bool, DefaultType] = DEFAULT, + max_expansions: Union[int, DefaultType] = DEFAULT, + minimum_should_match: Union[int, str, DefaultType] = DEFAULT, + operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, + prefix_length: Union[int, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -753,24 +732,24 @@ class MatchPhrasePrefixQuery(QueryBase): :arg _name: """ - query: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - max_expansions: Union[int, "DefaultType"] - slop: Union[int, "DefaultType"] - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + query: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + max_expansions: Union[int, DefaultType] + slop: Union[int, DefaultType] + zero_terms_query: Union[Literal["all", "none"], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - max_expansions: Union[int, "DefaultType"] = DEFAULT, - slop: Union[int, "DefaultType"] = DEFAULT, - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + max_expansions: Union[int, DefaultType] = DEFAULT, + slop: Union[int, DefaultType] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -809,22 +788,22 @@ class MatchPhraseQuery(QueryBase): :arg _name: """ - query: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - slop: Union[int, "DefaultType"] - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + query: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + slop: Union[int, DefaultType] + zero_terms_query: Union[Literal["all", "none"], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - slop: Union[int, "DefaultType"] = DEFAULT, - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + slop: Union[int, DefaultType] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -878,40 +857,40 @@ class MatchQuery(QueryBase): :arg _name: """ - query: Union[str, float, bool, "DefaultType"] - analyzer: Union[str, "DefaultType"] - auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] - cutoff_frequency: Union[float, "DefaultType"] - fuzziness: Union[str, int, "DefaultType"] - fuzzy_rewrite: Union[str, "DefaultType"] - fuzzy_transpositions: Union[bool, "DefaultType"] - lenient: Union[bool, "DefaultType"] - max_expansions: Union[int, "DefaultType"] - minimum_should_match: Union[int, str, "DefaultType"] - operator: Union[Literal["and", "or"], "DefaultType"] - prefix_length: Union[int, "DefaultType"] - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + query: Union[str, float, bool, DefaultType] + analyzer: Union[str, DefaultType] + auto_generate_synonyms_phrase_query: Union[bool, DefaultType] + cutoff_frequency: Union[float, DefaultType] + fuzziness: Union[str, int, DefaultType] + fuzzy_rewrite: Union[str, DefaultType] + fuzzy_transpositions: Union[bool, DefaultType] + lenient: Union[bool, DefaultType] + max_expansions: Union[int, DefaultType] + minimum_should_match: Union[int, str, DefaultType] + operator: Union[Literal["and", "or"], DefaultType] + prefix_length: Union[int, DefaultType] + zero_terms_query: Union[Literal["all", "none"], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - query: Union[str, float, bool, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - auto_generate_synonyms_phrase_query: Union[bool, "DefaultType"] = DEFAULT, - cutoff_frequency: Union[float, "DefaultType"] = DEFAULT, - fuzziness: Union[str, int, "DefaultType"] = DEFAULT, - fuzzy_rewrite: Union[str, "DefaultType"] = DEFAULT, - fuzzy_transpositions: Union[bool, "DefaultType"] = DEFAULT, - lenient: Union[bool, "DefaultType"] = DEFAULT, - max_expansions: Union[int, "DefaultType"] = DEFAULT, - minimum_should_match: Union[int, str, "DefaultType"] = DEFAULT, - operator: Union[Literal["and", "or"], "DefaultType"] = DEFAULT, - prefix_length: Union[int, "DefaultType"] = DEFAULT, - zero_terms_query: Union[Literal["all", "none"], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + query: Union[str, float, bool, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + auto_generate_synonyms_phrase_query: Union[bool, DefaultType] = DEFAULT, + cutoff_frequency: Union[float, DefaultType] = DEFAULT, + fuzziness: Union[str, int, DefaultType] = DEFAULT, + fuzzy_rewrite: Union[str, DefaultType] = DEFAULT, + fuzzy_transpositions: Union[bool, DefaultType] = DEFAULT, + lenient: Union[bool, DefaultType] = DEFAULT, + max_expansions: Union[int, DefaultType] = DEFAULT, + minimum_should_match: Union[int, str, DefaultType] = DEFAULT, + operator: Union[Literal["and", "or"], DefaultType] = DEFAULT, + prefix_length: Union[int, DefaultType] = DEFAULT, + zero_terms_query: Union[Literal["all", "none"], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -955,14 +934,14 @@ class PinnedDoc(AttrDict[Any]): :arg _index: (required) The index that contains the document. """ - _id: Union[str, "DefaultType"] - _index: Union[str, "DefaultType"] + _id: Union[str, DefaultType] + _index: Union[str, DefaultType] def __init__( self, *, - _id: Union[str, "DefaultType"] = DEFAULT, - _index: Union[str, "DefaultType"] = DEFAULT, + _id: Union[str, DefaultType] = DEFAULT, + _index: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if _id is not DEFAULT: @@ -989,20 +968,20 @@ class PrefixQuery(QueryBase): :arg _name: """ - value: Union[str, "DefaultType"] - rewrite: Union[str, "DefaultType"] - case_insensitive: Union[bool, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + value: Union[str, DefaultType] + rewrite: Union[str, DefaultType] + case_insensitive: Union[bool, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - value: Union[str, "DefaultType"] = DEFAULT, - rewrite: Union[str, "DefaultType"] = DEFAULT, - case_insensitive: Union[bool, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, DefaultType] = DEFAULT, + rewrite: Union[str, DefaultType] = DEFAULT, + case_insensitive: Union[bool, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if value is not DEFAULT: @@ -1023,14 +1002,12 @@ class QueryVectorBuilder(AttrDict[Any]): :arg text_embedding: """ - text_embedding: Union["types.TextEmbedding", Dict[str, Any], "DefaultType"] + text_embedding: Union["TextEmbedding", Dict[str, Any], DefaultType] def __init__( self, *, - text_embedding: Union[ - "types.TextEmbedding", Dict[str, Any], "DefaultType" - ] = DEFAULT, + text_embedding: Union["TextEmbedding", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if text_embedding is not DEFAULT: @@ -1051,10 +1028,10 @@ class RankFeatureFunctionLogarithm(RankFeatureFunction): :arg scaling_factor: (required) Configurable scaling factor. """ - scaling_factor: Union[float, "DefaultType"] + scaling_factor: Union[float, DefaultType] def __init__( - self, *, scaling_factor: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any + self, *, scaling_factor: Union[float, DefaultType] = DEFAULT, **kwargs: Any ): if scaling_factor is not DEFAULT: kwargs["scaling_factor"] = scaling_factor @@ -1067,9 +1044,9 @@ class RankFeatureFunctionSaturation(RankFeatureFunction): than 0.5. """ - pivot: Union[float, "DefaultType"] + pivot: Union[float, DefaultType] - def __init__(self, *, pivot: Union[float, "DefaultType"] = DEFAULT, **kwargs: Any): + def __init__(self, *, pivot: Union[float, DefaultType] = DEFAULT, **kwargs: Any): if pivot is not DEFAULT: kwargs["pivot"] = pivot super().__init__(**kwargs) @@ -1082,14 +1059,14 @@ class RankFeatureFunctionSigmoid(RankFeatureFunction): :arg exponent: (required) Configurable Exponent. """ - pivot: Union[float, "DefaultType"] - exponent: Union[float, "DefaultType"] + pivot: Union[float, DefaultType] + exponent: Union[float, DefaultType] def __init__( self, *, - pivot: Union[float, "DefaultType"] = DEFAULT, - exponent: Union[float, "DefaultType"] = DEFAULT, + pivot: Union[float, DefaultType] = DEFAULT, + exponent: Union[float, DefaultType] = DEFAULT, **kwargs: Any, ): if pivot is not DEFAULT: @@ -1119,24 +1096,24 @@ class RegexpQuery(QueryBase): :arg _name: """ - value: Union[str, "DefaultType"] - case_insensitive: Union[bool, "DefaultType"] - flags: Union[str, "DefaultType"] - max_determinized_states: Union[int, "DefaultType"] - rewrite: Union[str, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + value: Union[str, DefaultType] + case_insensitive: Union[bool, DefaultType] + flags: Union[str, DefaultType] + max_determinized_states: Union[int, DefaultType] + rewrite: Union[str, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - value: Union[str, "DefaultType"] = DEFAULT, - case_insensitive: Union[bool, "DefaultType"] = DEFAULT, - flags: Union[str, "DefaultType"] = DEFAULT, - max_determinized_states: Union[int, "DefaultType"] = DEFAULT, - rewrite: Union[str, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, DefaultType] = DEFAULT, + case_insensitive: Union[bool, DefaultType] = DEFAULT, + flags: Union[str, DefaultType] = DEFAULT, + max_determinized_states: Union[int, DefaultType] = DEFAULT, + rewrite: Union[str, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if value is not DEFAULT: @@ -1168,22 +1145,22 @@ class Script(AttrDict[Any]): :arg options: """ - source: Union[str, "DefaultType"] - id: Union[str, "DefaultType"] - params: Union[Mapping[str, Any], "DefaultType"] - lang: Union[Literal["painless", "expression", "mustache", "java"], "DefaultType"] - options: Union[Mapping[str, str], "DefaultType"] + source: Union[str, DefaultType] + id: Union[str, DefaultType] + params: Union[Mapping[str, Any], DefaultType] + lang: Union[Literal["painless", "expression", "mustache", "java"], DefaultType] + options: Union[Mapping[str, str], DefaultType] def __init__( self, *, - source: Union[str, "DefaultType"] = DEFAULT, - id: Union[str, "DefaultType"] = DEFAULT, - params: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, + source: Union[str, DefaultType] = DEFAULT, + id: Union[str, DefaultType] = DEFAULT, + params: Union[Mapping[str, Any], DefaultType] = DEFAULT, lang: Union[ - Literal["painless", "expression", "mustache", "java"], "DefaultType" + Literal["painless", "expression", "mustache", "java"], DefaultType ] = DEFAULT, - options: Union[Mapping[str, str], "DefaultType"] = DEFAULT, + options: Union[Mapping[str, str], DefaultType] = DEFAULT, **kwargs: Any, ): if source is not DEFAULT: @@ -1208,20 +1185,18 @@ class ShapeFieldQuery(AttrDict[Any]): Well Known Text (WKT) format. """ - indexed_shape: Union["types.FieldLookup", Dict[str, Any], "DefaultType"] + indexed_shape: Union["FieldLookup", Dict[str, Any], DefaultType] relation: Union[ - Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + Literal["intersects", "disjoint", "within", "contains"], DefaultType ] shape: Any def __init__( self, *, - indexed_shape: Union[ - "types.FieldLookup", Dict[str, Any], "DefaultType" - ] = DEFAULT, + indexed_shape: Union["FieldLookup", Dict[str, Any], DefaultType] = DEFAULT, relation: Union[ - Literal["intersects", "disjoint", "within", "contains"], "DefaultType" + Literal["intersects", "disjoint", "within", "contains"], DefaultType ] = DEFAULT, shape: Any = DEFAULT, **kwargs: Any, @@ -1260,54 +1235,44 @@ class SpanQuery(AttrDict[Any]): other span queries. """ - span_containing: Union["types.SpanContainingQuery", Dict[str, Any], "DefaultType"] - span_field_masking: Union[ - "types.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" - ] - span_first: Union["types.SpanFirstQuery", Dict[str, Any], "DefaultType"] - span_gap: Union[Mapping[Union[str, "InstrumentedField"], int], "DefaultType"] - span_multi: Union["types.SpanMultiTermQuery", Dict[str, Any], "DefaultType"] - span_near: Union["types.SpanNearQuery", Dict[str, Any], "DefaultType"] - span_not: Union["types.SpanNotQuery", Dict[str, Any], "DefaultType"] - span_or: Union["types.SpanOrQuery", Dict[str, Any], "DefaultType"] + span_containing: Union["SpanContainingQuery", Dict[str, Any], DefaultType] + span_field_masking: Union["SpanFieldMaskingQuery", Dict[str, Any], DefaultType] + span_first: Union["SpanFirstQuery", Dict[str, Any], DefaultType] + span_gap: Union[Mapping[Union[str, InstrumentedField], int], DefaultType] + span_multi: Union["SpanMultiTermQuery", Dict[str, Any], DefaultType] + span_near: Union["SpanNearQuery", Dict[str, Any], DefaultType] + span_not: Union["SpanNotQuery", Dict[str, Any], DefaultType] + span_or: Union["SpanOrQuery", Dict[str, Any], DefaultType] span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "types.SpanTermQuery"], + Mapping[Union[str, InstrumentedField], "SpanTermQuery"], Dict[str, Any], - "DefaultType", + DefaultType, ] - span_within: Union["types.SpanWithinQuery", Dict[str, Any], "DefaultType"] + span_within: Union["SpanWithinQuery", Dict[str, Any], DefaultType] def __init__( self, *, span_containing: Union[ - "types.SpanContainingQuery", Dict[str, Any], "DefaultType" + "SpanContainingQuery", Dict[str, Any], DefaultType ] = DEFAULT, span_field_masking: Union[ - "types.SpanFieldMaskingQuery", Dict[str, Any], "DefaultType" - ] = DEFAULT, - span_first: Union[ - "types.SpanFirstQuery", Dict[str, Any], "DefaultType" + "SpanFieldMaskingQuery", Dict[str, Any], DefaultType ] = DEFAULT, + span_first: Union["SpanFirstQuery", Dict[str, Any], DefaultType] = DEFAULT, span_gap: Union[ - Mapping[Union[str, "InstrumentedField"], int], "DefaultType" - ] = DEFAULT, - span_multi: Union[ - "types.SpanMultiTermQuery", Dict[str, Any], "DefaultType" - ] = DEFAULT, - span_near: Union[ - "types.SpanNearQuery", Dict[str, Any], "DefaultType" + Mapping[Union[str, InstrumentedField], int], DefaultType ] = DEFAULT, - span_not: Union["types.SpanNotQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - span_or: Union["types.SpanOrQuery", Dict[str, Any], "DefaultType"] = DEFAULT, + span_multi: Union["SpanMultiTermQuery", Dict[str, Any], DefaultType] = DEFAULT, + span_near: Union["SpanNearQuery", Dict[str, Any], DefaultType] = DEFAULT, + span_not: Union["SpanNotQuery", Dict[str, Any], DefaultType] = DEFAULT, + span_or: Union["SpanOrQuery", Dict[str, Any], DefaultType] = DEFAULT, span_term: Union[ - Mapping[Union[str, "InstrumentedField"], "types.SpanTermQuery"], + Mapping[Union[str, InstrumentedField], "SpanTermQuery"], Dict[str, Any], - "DefaultType", - ] = DEFAULT, - span_within: Union[ - "types.SpanWithinQuery", Dict[str, Any], "DefaultType" + DefaultType, ] = DEFAULT, + span_within: Union["SpanWithinQuery", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if span_containing is not DEFAULT: @@ -1344,16 +1309,16 @@ class SpanTermQuery(QueryBase): :arg _name: """ - value: Union[str, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + value: Union[str, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - value: Union[str, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + value: Union[str, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if value is not DEFAULT: @@ -1380,18 +1345,18 @@ class TermQuery(QueryBase): :arg _name: """ - value: Union[int, float, str, bool, None, Any, "DefaultType"] - case_insensitive: Union[bool, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + value: Union[int, float, str, bool, None, Any, DefaultType] + case_insensitive: Union[bool, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - value: Union[int, float, str, bool, None, Any, "DefaultType"] = DEFAULT, - case_insensitive: Union[bool, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + value: Union[int, float, str, bool, None, Any, DefaultType] = DEFAULT, + case_insensitive: Union[bool, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if value is not DEFAULT: @@ -1413,18 +1378,18 @@ class TermsLookup(AttrDict[Any]): :arg routing: """ - index: Union[str, "DefaultType"] - id: Union[str, "DefaultType"] - path: Union[str, "InstrumentedField", "DefaultType"] - routing: Union[str, "DefaultType"] + index: Union[str, DefaultType] + id: Union[str, DefaultType] + path: Union[str, InstrumentedField, DefaultType] + routing: Union[str, DefaultType] def __init__( self, *, - index: Union[str, "DefaultType"] = DEFAULT, - id: Union[str, "DefaultType"] = DEFAULT, - path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - routing: Union[str, "DefaultType"] = DEFAULT, + index: Union[str, DefaultType] = DEFAULT, + id: Union[str, DefaultType] = DEFAULT, + path: Union[str, InstrumentedField, DefaultType] = DEFAULT, + routing: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if index is not DEFAULT: @@ -1454,24 +1419,24 @@ class TermsSetQuery(QueryBase): :arg _name: """ - terms: Union[Sequence[str], "DefaultType"] - minimum_should_match_field: Union[str, "InstrumentedField", "DefaultType"] - minimum_should_match_script: Union["types.Script", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + terms: Union[Sequence[str], DefaultType] + minimum_should_match_field: Union[str, InstrumentedField, DefaultType] + minimum_should_match_script: Union["Script", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - terms: Union[Sequence[str], "DefaultType"] = DEFAULT, + terms: Union[Sequence[str], DefaultType] = DEFAULT, minimum_should_match_field: Union[ - str, "InstrumentedField", "DefaultType" + str, InstrumentedField, DefaultType ] = DEFAULT, minimum_should_match_script: Union[ - "types.Script", Dict[str, Any], "DefaultType" + "Script", Dict[str, Any], DefaultType ] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if terms is not DEFAULT: @@ -1500,22 +1465,22 @@ class TextExpansionQuery(QueryBase): :arg _name: """ - model_id: Union[str, "DefaultType"] - model_text: Union[str, "DefaultType"] - pruning_config: Union["types.TokenPruningConfig", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + model_id: Union[str, DefaultType] + model_text: Union[str, DefaultType] + pruning_config: Union["TokenPruningConfig", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - model_id: Union[str, "DefaultType"] = DEFAULT, - model_text: Union[str, "DefaultType"] = DEFAULT, + model_id: Union[str, DefaultType] = DEFAULT, + model_text: Union[str, DefaultType] = DEFAULT, pruning_config: Union[ - "types.TokenPruningConfig", Dict[str, Any], "DefaultType" + "TokenPruningConfig", Dict[str, Any], DefaultType ] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if model_id is not DEFAULT: @@ -1544,16 +1509,16 @@ class TokenPruningConfig(AttrDict[Any]): only scoring kept tokens. """ - tokens_freq_ratio_threshold: Union[int, "DefaultType"] - tokens_weight_threshold: Union[float, "DefaultType"] - only_score_pruned_tokens: Union[bool, "DefaultType"] + tokens_freq_ratio_threshold: Union[int, DefaultType] + tokens_weight_threshold: Union[float, DefaultType] + only_score_pruned_tokens: Union[bool, DefaultType] def __init__( self, *, - tokens_freq_ratio_threshold: Union[int, "DefaultType"] = DEFAULT, - tokens_weight_threshold: Union[float, "DefaultType"] = DEFAULT, - only_score_pruned_tokens: Union[bool, "DefaultType"] = DEFAULT, + tokens_freq_ratio_threshold: Union[int, DefaultType] = DEFAULT, + tokens_weight_threshold: Union[float, DefaultType] = DEFAULT, + only_score_pruned_tokens: Union[bool, DefaultType] = DEFAULT, **kwargs: Any, ): if tokens_freq_ratio_threshold is not DEFAULT: @@ -1572,40 +1537,40 @@ class TopLeftBottomRightGeoBounds(AttrDict[Any]): """ top_left: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] bottom_right: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] def __init__( self, *, top_left: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, bottom_right: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, **kwargs: Any, ): @@ -1623,40 +1588,40 @@ class TopRightBottomLeftGeoBounds(AttrDict[Any]): """ top_right: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] bottom_left: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] def __init__( self, *, top_right: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, bottom_left: Union[ - "types.LatLonGeoLocation", - "types.GeoHashLocation", + "LatLonGeoLocation", + "GeoHashLocation", Sequence[float], str, Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, **kwargs: Any, ): @@ -1679,20 +1644,20 @@ class WeightedTokensQuery(QueryBase): :arg _name: """ - tokens: Union[Mapping[str, float], "DefaultType"] - pruning_config: Union["types.TokenPruningConfig", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + tokens: Union[Mapping[str, float], DefaultType] + pruning_config: Union["TokenPruningConfig", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - tokens: Union[Mapping[str, float], "DefaultType"] = DEFAULT, + tokens: Union[Mapping[str, float], DefaultType] = DEFAULT, pruning_config: Union[ - "types.TokenPruningConfig", Dict[str, Any], "DefaultType" + "TokenPruningConfig", Dict[str, Any], DefaultType ] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if tokens is not DEFAULT: @@ -1725,22 +1690,22 @@ class WildcardQuery(QueryBase): :arg _name: """ - case_insensitive: Union[bool, "DefaultType"] - rewrite: Union[str, "DefaultType"] - value: Union[str, "DefaultType"] - wildcard: Union[str, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + case_insensitive: Union[bool, DefaultType] + rewrite: Union[str, DefaultType] + value: Union[str, DefaultType] + wildcard: Union[str, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - case_insensitive: Union[bool, "DefaultType"] = DEFAULT, - rewrite: Union[str, "DefaultType"] = DEFAULT, - value: Union[str, "DefaultType"] = DEFAULT, - wildcard: Union[str, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + case_insensitive: Union[bool, DefaultType] = DEFAULT, + rewrite: Union[str, DefaultType] = DEFAULT, + value: Union[str, DefaultType] = DEFAULT, + wildcard: Union[str, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if case_insensitive is not DEFAULT: @@ -1763,9 +1728,9 @@ class WktGeoBounds(AttrDict[Any]): :arg wkt: (required) """ - wkt: Union[str, "DefaultType"] + wkt: Union[str, DefaultType] - def __init__(self, *, wkt: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any): + def __init__(self, *, wkt: Union[str, DefaultType] = DEFAULT, **kwargs: Any): if wkt is not DEFAULT: kwargs["wkt"] = wkt super().__init__(kwargs) @@ -1779,18 +1744,18 @@ class FieldLookup(AttrDict[Any]): :arg routing: Custom routing value. """ - id: Union[str, "DefaultType"] - index: Union[str, "DefaultType"] - path: Union[str, "InstrumentedField", "DefaultType"] - routing: Union[str, "DefaultType"] + id: Union[str, DefaultType] + index: Union[str, DefaultType] + path: Union[str, InstrumentedField, DefaultType] + routing: Union[str, DefaultType] def __init__( self, *, - id: Union[str, "DefaultType"] = DEFAULT, - index: Union[str, "DefaultType"] = DEFAULT, - path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - routing: Union[str, "DefaultType"] = DEFAULT, + id: Union[str, DefaultType] = DEFAULT, + index: Union[str, DefaultType] = DEFAULT, + path: Union[str, InstrumentedField, DefaultType] = DEFAULT, + routing: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if id is not DEFAULT: @@ -1813,25 +1778,20 @@ class FieldCollapse(AttrDict[Any]): :arg collapse: """ - field: Union[str, "InstrumentedField", "DefaultType"] - inner_hits: Union[ - "types.InnerHits", Sequence["types.InnerHits"], Dict[str, Any], "DefaultType" - ] - max_concurrent_group_searches: Union[int, "DefaultType"] - collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] + field: Union[str, InstrumentedField, DefaultType] + inner_hits: Union["InnerHits", Sequence["InnerHits"], Dict[str, Any], DefaultType] + max_concurrent_group_searches: Union[int, DefaultType] + collapse: Union["FieldCollapse", Dict[str, Any], DefaultType] def __init__( self, *, - field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + field: Union[str, InstrumentedField, DefaultType] = DEFAULT, inner_hits: Union[ - "types.InnerHits", - Sequence["types.InnerHits"], - Dict[str, Any], - "DefaultType", + "InnerHits", Sequence["InnerHits"], Dict[str, Any], DefaultType ] = DEFAULT, - max_concurrent_group_searches: Union[int, "DefaultType"] = DEFAULT, - collapse: Union["types.FieldCollapse", Dict[str, Any], "DefaultType"] = DEFAULT, + max_concurrent_group_searches: Union[int, DefaultType] = DEFAULT, + collapse: Union["FieldCollapse", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if field is not DEFAULT: @@ -1853,16 +1813,16 @@ class FieldAndFormat(AttrDict[Any]): :arg include_unmapped: """ - field: Union[str, "InstrumentedField", "DefaultType"] - format: Union[str, "DefaultType"] - include_unmapped: Union[bool, "DefaultType"] + field: Union[str, InstrumentedField, DefaultType] + format: Union[str, DefaultType] + include_unmapped: Union[bool, DefaultType] def __init__( self, *, - field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - format: Union[str, "DefaultType"] = DEFAULT, - include_unmapped: Union[bool, "DefaultType"] = DEFAULT, + field: Union[str, InstrumentedField, DefaultType] = DEFAULT, + format: Union[str, DefaultType] = DEFAULT, + include_unmapped: Union[bool, DefaultType] = DEFAULT, **kwargs: Any, ): if field is not DEFAULT: @@ -1943,54 +1903,54 @@ class HighlightBase(AttrDict[Any]): :arg tags_schema: Set to `styled` to use the built-in tag schema. """ - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] - boundary_chars: Union[str, "DefaultType"] - boundary_max_scan: Union[int, "DefaultType"] - boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] - boundary_scanner_locale: Union[str, "DefaultType"] - force_source: Union[bool, "DefaultType"] - fragmenter: Union[Literal["simple", "span"], "DefaultType"] - fragment_size: Union[int, "DefaultType"] - highlight_filter: Union[bool, "DefaultType"] - highlight_query: Union[Query, "DefaultType"] - max_fragment_length: Union[int, "DefaultType"] - max_analyzed_offset: Union[int, "DefaultType"] - no_match_size: Union[int, "DefaultType"] - number_of_fragments: Union[int, "DefaultType"] - options: Union[Mapping[str, Any], "DefaultType"] - order: Union[Literal["score"], "DefaultType"] - phrase_limit: Union[int, "DefaultType"] - post_tags: Union[Sequence[str], "DefaultType"] - pre_tags: Union[Sequence[str], "DefaultType"] - require_field_match: Union[bool, "DefaultType"] - tags_schema: Union[Literal["styled"], "DefaultType"] + type: Union[Literal["plain", "fvh", "unified"], DefaultType] + boundary_chars: Union[str, DefaultType] + boundary_max_scan: Union[int, DefaultType] + boundary_scanner: Union[Literal["chars", "sentence", "word"], DefaultType] + boundary_scanner_locale: Union[str, DefaultType] + force_source: Union[bool, DefaultType] + fragmenter: Union[Literal["simple", "span"], DefaultType] + fragment_size: Union[int, DefaultType] + highlight_filter: Union[bool, DefaultType] + highlight_query: Union[Query, DefaultType] + max_fragment_length: Union[int, DefaultType] + max_analyzed_offset: Union[int, DefaultType] + no_match_size: Union[int, DefaultType] + number_of_fragments: Union[int, DefaultType] + options: Union[Mapping[str, Any], DefaultType] + order: Union[Literal["score"], DefaultType] + phrase_limit: Union[int, DefaultType] + post_tags: Union[Sequence[str], DefaultType] + pre_tags: Union[Sequence[str], DefaultType] + require_field_match: Union[bool, DefaultType] + tags_schema: Union[Literal["styled"], DefaultType] def __init__( self, *, - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, - boundary_chars: Union[str, "DefaultType"] = DEFAULT, - boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, + type: Union[Literal["plain", "fvh", "unified"], DefaultType] = DEFAULT, + boundary_chars: Union[str, DefaultType] = DEFAULT, + boundary_max_scan: Union[int, DefaultType] = DEFAULT, boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "DefaultType" + Literal["chars", "sentence", "word"], DefaultType ] = DEFAULT, - boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, - force_source: Union[bool, "DefaultType"] = DEFAULT, - fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, - fragment_size: Union[int, "DefaultType"] = DEFAULT, - highlight_filter: Union[bool, "DefaultType"] = DEFAULT, - highlight_query: Union[Query, "DefaultType"] = DEFAULT, - max_fragment_length: Union[int, "DefaultType"] = DEFAULT, - max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, - no_match_size: Union[int, "DefaultType"] = DEFAULT, - number_of_fragments: Union[int, "DefaultType"] = DEFAULT, - options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, - order: Union[Literal["score"], "DefaultType"] = DEFAULT, - phrase_limit: Union[int, "DefaultType"] = DEFAULT, - post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - require_field_match: Union[bool, "DefaultType"] = DEFAULT, - tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, + boundary_scanner_locale: Union[str, DefaultType] = DEFAULT, + force_source: Union[bool, DefaultType] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], DefaultType] = DEFAULT, + fragment_size: Union[int, DefaultType] = DEFAULT, + highlight_filter: Union[bool, DefaultType] = DEFAULT, + highlight_query: Union[Query, DefaultType] = DEFAULT, + max_fragment_length: Union[int, DefaultType] = DEFAULT, + max_analyzed_offset: Union[int, DefaultType] = DEFAULT, + no_match_size: Union[int, DefaultType] = DEFAULT, + number_of_fragments: Union[int, DefaultType] = DEFAULT, + options: Union[Mapping[str, Any], DefaultType] = DEFAULT, + order: Union[Literal["score"], DefaultType] = DEFAULT, + phrase_limit: Union[int, DefaultType] = DEFAULT, + post_tags: Union[Sequence[str], DefaultType] = DEFAULT, + pre_tags: Union[Sequence[str], DefaultType] = DEFAULT, + require_field_match: Union[bool, DefaultType] = DEFAULT, + tags_schema: Union[Literal["styled"], DefaultType] = DEFAULT, **kwargs: Any, ): if type is not DEFAULT: @@ -2110,65 +2070,65 @@ class Highlight(HighlightBase): """ fields: Union[ - Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], + Mapping[Union[str, InstrumentedField], "HighlightField"], Dict[str, Any], - "DefaultType", + DefaultType, ] - encoder: Union[Literal["default", "html"], "DefaultType"] - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] - boundary_chars: Union[str, "DefaultType"] - boundary_max_scan: Union[int, "DefaultType"] - boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] - boundary_scanner_locale: Union[str, "DefaultType"] - force_source: Union[bool, "DefaultType"] - fragmenter: Union[Literal["simple", "span"], "DefaultType"] - fragment_size: Union[int, "DefaultType"] - highlight_filter: Union[bool, "DefaultType"] - highlight_query: Union[Query, "DefaultType"] - max_fragment_length: Union[int, "DefaultType"] - max_analyzed_offset: Union[int, "DefaultType"] - no_match_size: Union[int, "DefaultType"] - number_of_fragments: Union[int, "DefaultType"] - options: Union[Mapping[str, Any], "DefaultType"] - order: Union[Literal["score"], "DefaultType"] - phrase_limit: Union[int, "DefaultType"] - post_tags: Union[Sequence[str], "DefaultType"] - pre_tags: Union[Sequence[str], "DefaultType"] - require_field_match: Union[bool, "DefaultType"] - tags_schema: Union[Literal["styled"], "DefaultType"] + encoder: Union[Literal["default", "html"], DefaultType] + type: Union[Literal["plain", "fvh", "unified"], DefaultType] + boundary_chars: Union[str, DefaultType] + boundary_max_scan: Union[int, DefaultType] + boundary_scanner: Union[Literal["chars", "sentence", "word"], DefaultType] + boundary_scanner_locale: Union[str, DefaultType] + force_source: Union[bool, DefaultType] + fragmenter: Union[Literal["simple", "span"], DefaultType] + fragment_size: Union[int, DefaultType] + highlight_filter: Union[bool, DefaultType] + highlight_query: Union[Query, DefaultType] + max_fragment_length: Union[int, DefaultType] + max_analyzed_offset: Union[int, DefaultType] + no_match_size: Union[int, DefaultType] + number_of_fragments: Union[int, DefaultType] + options: Union[Mapping[str, Any], DefaultType] + order: Union[Literal["score"], DefaultType] + phrase_limit: Union[int, DefaultType] + post_tags: Union[Sequence[str], DefaultType] + pre_tags: Union[Sequence[str], DefaultType] + require_field_match: Union[bool, DefaultType] + tags_schema: Union[Literal["styled"], DefaultType] def __init__( self, *, fields: Union[ - Mapping[Union[str, "InstrumentedField"], "types.HighlightField"], + Mapping[Union[str, InstrumentedField], "HighlightField"], Dict[str, Any], - "DefaultType", + DefaultType, ] = DEFAULT, - encoder: Union[Literal["default", "html"], "DefaultType"] = DEFAULT, - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, - boundary_chars: Union[str, "DefaultType"] = DEFAULT, - boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, + encoder: Union[Literal["default", "html"], DefaultType] = DEFAULT, + type: Union[Literal["plain", "fvh", "unified"], DefaultType] = DEFAULT, + boundary_chars: Union[str, DefaultType] = DEFAULT, + boundary_max_scan: Union[int, DefaultType] = DEFAULT, boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "DefaultType" + Literal["chars", "sentence", "word"], DefaultType ] = DEFAULT, - boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, - force_source: Union[bool, "DefaultType"] = DEFAULT, - fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, - fragment_size: Union[int, "DefaultType"] = DEFAULT, - highlight_filter: Union[bool, "DefaultType"] = DEFAULT, - highlight_query: Union[Query, "DefaultType"] = DEFAULT, - max_fragment_length: Union[int, "DefaultType"] = DEFAULT, - max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, - no_match_size: Union[int, "DefaultType"] = DEFAULT, - number_of_fragments: Union[int, "DefaultType"] = DEFAULT, - options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, - order: Union[Literal["score"], "DefaultType"] = DEFAULT, - phrase_limit: Union[int, "DefaultType"] = DEFAULT, - post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - require_field_match: Union[bool, "DefaultType"] = DEFAULT, - tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, + boundary_scanner_locale: Union[str, DefaultType] = DEFAULT, + force_source: Union[bool, DefaultType] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], DefaultType] = DEFAULT, + fragment_size: Union[int, DefaultType] = DEFAULT, + highlight_filter: Union[bool, DefaultType] = DEFAULT, + highlight_query: Union[Query, DefaultType] = DEFAULT, + max_fragment_length: Union[int, DefaultType] = DEFAULT, + max_analyzed_offset: Union[int, DefaultType] = DEFAULT, + no_match_size: Union[int, DefaultType] = DEFAULT, + number_of_fragments: Union[int, DefaultType] = DEFAULT, + options: Union[Mapping[str, Any], DefaultType] = DEFAULT, + order: Union[Literal["score"], DefaultType] = DEFAULT, + phrase_limit: Union[int, DefaultType] = DEFAULT, + post_tags: Union[Sequence[str], DefaultType] = DEFAULT, + pre_tags: Union[Sequence[str], DefaultType] = DEFAULT, + require_field_match: Union[bool, DefaultType] = DEFAULT, + tags_schema: Union[Literal["styled"], DefaultType] = DEFAULT, **kwargs: Any, ): if fields is not DEFAULT: @@ -2226,14 +2186,14 @@ class ScriptField(AttrDict[Any]): :arg ignore_failure: """ - script: Union["types.Script", Dict[str, Any], "DefaultType"] - ignore_failure: Union[bool, "DefaultType"] + script: Union["Script", Dict[str, Any], DefaultType] + ignore_failure: Union[bool, DefaultType] def __init__( self, *, - script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, - ignore_failure: Union[bool, "DefaultType"] = DEFAULT, + script: Union["Script", Dict[str, Any], DefaultType] = DEFAULT, + ignore_failure: Union[bool, DefaultType] = DEFAULT, **kwargs: Any, ): if script is not DEFAULT: @@ -2251,20 +2211,18 @@ class SortOptions(AttrDict[Any]): :arg _script: """ - _score: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] - _doc: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] - _geo_distance: Union["types.GeoDistanceSort", Dict[str, Any], "DefaultType"] - _script: Union["types.ScriptSort", Dict[str, Any], "DefaultType"] + _score: Union["ScoreSort", Dict[str, Any], DefaultType] + _doc: Union["ScoreSort", Dict[str, Any], DefaultType] + _geo_distance: Union["GeoDistanceSort", Dict[str, Any], DefaultType] + _script: Union["ScriptSort", Dict[str, Any], DefaultType] def __init__( self, *, - _score: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, - _doc: Union["types.ScoreSort", Dict[str, Any], "DefaultType"] = DEFAULT, - _geo_distance: Union[ - "types.GeoDistanceSort", Dict[str, Any], "DefaultType" - ] = DEFAULT, - _script: Union["types.ScriptSort", Dict[str, Any], "DefaultType"] = DEFAULT, + _score: Union["ScoreSort", Dict[str, Any], DefaultType] = DEFAULT, + _doc: Union["ScoreSort", Dict[str, Any], DefaultType] = DEFAULT, + _geo_distance: Union["GeoDistanceSort", Dict[str, Any], DefaultType] = DEFAULT, + _script: Union["ScriptSort", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if _score is not DEFAULT: @@ -2285,28 +2243,28 @@ class SourceFilter(AttrDict[Any]): """ excludes: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] includes: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] def __init__( self, *, excludes: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] = DEFAULT, includes: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] = DEFAULT, **kwargs: Any, ): @@ -2330,22 +2288,20 @@ class IntervalsAllOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[ - Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" - ] - max_gaps: Union[int, "DefaultType"] - ordered: Union[bool, "DefaultType"] - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] + intervals: Union[Sequence["IntervalsContainer"], Dict[str, Any], DefaultType] + max_gaps: Union[int, DefaultType] + ordered: Union[bool, DefaultType] + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] def __init__( self, *, intervals: Union[ - Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["IntervalsContainer"], Dict[str, Any], DefaultType ] = DEFAULT, - max_gaps: Union[int, "DefaultType"] = DEFAULT, - ordered: Union[bool, "DefaultType"] = DEFAULT, - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + max_gaps: Union[int, DefaultType] = DEFAULT, + ordered: Union[bool, DefaultType] = DEFAULT, + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if intervals is not DEFAULT: @@ -2365,18 +2321,16 @@ class IntervalsAnyOf(AttrDict[Any]): :arg filter: Rule used to filter returned intervals. """ - intervals: Union[ - Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" - ] - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] + intervals: Union[Sequence["IntervalsContainer"], Dict[str, Any], DefaultType] + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] def __init__( self, *, intervals: Union[ - Sequence["types.IntervalsContainer"], Dict[str, Any], "DefaultType" + Sequence["IntervalsContainer"], Dict[str, Any], DefaultType ] = DEFAULT, - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if intervals is not DEFAULT: @@ -2403,22 +2357,22 @@ class IntervalsFuzzy(AttrDict[Any]): separately. """ - term: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - fuzziness: Union[str, int, "DefaultType"] - prefix_length: Union[int, "DefaultType"] - transpositions: Union[bool, "DefaultType"] - use_field: Union[str, "InstrumentedField", "DefaultType"] + term: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + fuzziness: Union[str, int, DefaultType] + prefix_length: Union[int, DefaultType] + transpositions: Union[bool, DefaultType] + use_field: Union[str, InstrumentedField, DefaultType] def __init__( self, *, - term: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - fuzziness: Union[str, int, "DefaultType"] = DEFAULT, - prefix_length: Union[int, "DefaultType"] = DEFAULT, - transpositions: Union[bool, "DefaultType"] = DEFAULT, - use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + term: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + fuzziness: Union[str, int, DefaultType] = DEFAULT, + prefix_length: Union[int, DefaultType] = DEFAULT, + transpositions: Union[bool, DefaultType] = DEFAULT, + use_field: Union[str, InstrumentedField, DefaultType] = DEFAULT, **kwargs: Any, ): if term is not DEFAULT: @@ -2452,22 +2406,22 @@ class IntervalsMatch(AttrDict[Any]): :arg filter: An optional interval filter. """ - query: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - max_gaps: Union[int, "DefaultType"] - ordered: Union[bool, "DefaultType"] - use_field: Union[str, "InstrumentedField", "DefaultType"] - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] + query: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + max_gaps: Union[int, DefaultType] + ordered: Union[bool, DefaultType] + use_field: Union[str, InstrumentedField, DefaultType] + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] def __init__( self, *, - query: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - max_gaps: Union[int, "DefaultType"] = DEFAULT, - ordered: Union[bool, "DefaultType"] = DEFAULT, - use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - filter: Union["types.IntervalsFilter", Dict[str, Any], "DefaultType"] = DEFAULT, + query: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + max_gaps: Union[int, DefaultType] = DEFAULT, + ordered: Union[bool, DefaultType] = DEFAULT, + use_field: Union[str, InstrumentedField, DefaultType] = DEFAULT, + filter: Union["IntervalsFilter", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if query is not DEFAULT: @@ -2496,16 +2450,16 @@ class IntervalsPrefix(AttrDict[Any]): separately. """ - prefix: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - use_field: Union[str, "InstrumentedField", "DefaultType"] + prefix: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + use_field: Union[str, InstrumentedField, DefaultType] def __init__( self, *, - prefix: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + prefix: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + use_field: Union[str, InstrumentedField, DefaultType] = DEFAULT, **kwargs: Any, ): if prefix is not DEFAULT: @@ -2528,16 +2482,16 @@ class IntervalsWildcard(AttrDict[Any]): separately. """ - pattern: Union[str, "DefaultType"] - analyzer: Union[str, "DefaultType"] - use_field: Union[str, "InstrumentedField", "DefaultType"] + pattern: Union[str, DefaultType] + analyzer: Union[str, DefaultType] + use_field: Union[str, InstrumentedField, DefaultType] def __init__( self, *, - pattern: Union[str, "DefaultType"] = DEFAULT, - analyzer: Union[str, "DefaultType"] = DEFAULT, - use_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, + pattern: Union[str, DefaultType] = DEFAULT, + analyzer: Union[str, DefaultType] = DEFAULT, + use_field: Union[str, InstrumentedField, DefaultType] = DEFAULT, **kwargs: Any, ): if pattern is not DEFAULT: @@ -2555,14 +2509,14 @@ class TextEmbedding(AttrDict[Any]): :arg model_text: (required) """ - model_id: Union[str, "DefaultType"] - model_text: Union[str, "DefaultType"] + model_id: Union[str, DefaultType] + model_text: Union[str, DefaultType] def __init__( self, *, - model_id: Union[str, "DefaultType"] = DEFAULT, - model_text: Union[str, "DefaultType"] = DEFAULT, + model_id: Union[str, DefaultType] = DEFAULT, + model_text: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if model_id is not DEFAULT: @@ -2586,18 +2540,18 @@ class SpanContainingQuery(QueryBase): :arg _name: """ - big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + big: Union["SpanQuery", Dict[str, Any], DefaultType] + little: Union["SpanQuery", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + big: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + little: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if big is not DEFAULT: @@ -2623,18 +2577,18 @@ class SpanFieldMaskingQuery(QueryBase): :arg _name: """ - field: Union[str, "InstrumentedField", "DefaultType"] - query: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + field: Union[str, InstrumentedField, DefaultType] + query: Union["SpanQuery", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - query: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + field: Union[str, InstrumentedField, DefaultType] = DEFAULT, + query: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if field is not DEFAULT: @@ -2661,18 +2615,18 @@ class SpanFirstQuery(QueryBase): :arg _name: """ - end: Union[int, "DefaultType"] - match: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + end: Union[int, DefaultType] + match: Union["SpanQuery", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - end: Union[int, "DefaultType"] = DEFAULT, - match: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + end: Union[int, DefaultType] = DEFAULT, + match: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if end is not DEFAULT: @@ -2698,16 +2652,16 @@ class SpanMultiTermQuery(QueryBase): :arg _name: """ - match: Union[Query, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + match: Union[Query, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - match: Union[Query, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + match: Union[Query, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if match is not DEFAULT: @@ -2733,22 +2687,20 @@ class SpanNearQuery(QueryBase): :arg _name: """ - clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] - in_order: Union[bool, "DefaultType"] - slop: Union[int, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + clauses: Union[Sequence["SpanQuery"], Dict[str, Any], DefaultType] + in_order: Union[bool, DefaultType] + slop: Union[int, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - clauses: Union[ - Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" - ] = DEFAULT, - in_order: Union[bool, "DefaultType"] = DEFAULT, - slop: Union[int, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + clauses: Union[Sequence["SpanQuery"], Dict[str, Any], DefaultType] = DEFAULT, + in_order: Union[bool, DefaultType] = DEFAULT, + slop: Union[int, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if clauses is not DEFAULT: @@ -2784,24 +2736,24 @@ class SpanNotQuery(QueryBase): :arg _name: """ - exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - dist: Union[int, "DefaultType"] - post: Union[int, "DefaultType"] - pre: Union[int, "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + exclude: Union["SpanQuery", Dict[str, Any], DefaultType] + include: Union["SpanQuery", Dict[str, Any], DefaultType] + dist: Union[int, DefaultType] + post: Union[int, DefaultType] + pre: Union[int, DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - exclude: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - include: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - dist: Union[int, "DefaultType"] = DEFAULT, - post: Union[int, "DefaultType"] = DEFAULT, - pre: Union[int, "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + exclude: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + include: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + dist: Union[int, DefaultType] = DEFAULT, + post: Union[int, DefaultType] = DEFAULT, + pre: Union[int, DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if exclude is not DEFAULT: @@ -2832,18 +2784,16 @@ class SpanOrQuery(QueryBase): :arg _name: """ - clauses: Union[Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + clauses: Union[Sequence["SpanQuery"], Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - clauses: Union[ - Sequence["types.SpanQuery"], Dict[str, Any], "DefaultType" - ] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + clauses: Union[Sequence["SpanQuery"], Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if clauses is not DEFAULT: @@ -2869,18 +2819,18 @@ class SpanWithinQuery(QueryBase): :arg _name: """ - big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] - boost: Union[float, "DefaultType"] - _name: Union[str, "DefaultType"] + big: Union["SpanQuery", Dict[str, Any], DefaultType] + little: Union["SpanQuery", Dict[str, Any], DefaultType] + boost: Union[float, DefaultType] + _name: Union[str, DefaultType] def __init__( self, *, - big: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - little: Union["types.SpanQuery", Dict[str, Any], "DefaultType"] = DEFAULT, - boost: Union[float, "DefaultType"] = DEFAULT, - _name: Union[str, "DefaultType"] = DEFAULT, + big: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + little: Union["SpanQuery", Dict[str, Any], DefaultType] = DEFAULT, + boost: Union[float, DefaultType] = DEFAULT, + _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): if big is not DEFAULT: @@ -2966,68 +2916,68 @@ class HighlightField(HighlightBase): :arg tags_schema: Set to `styled` to use the built-in tag schema. """ - fragment_offset: Union[int, "DefaultType"] + fragment_offset: Union[int, DefaultType] matched_fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] - analyzer: Union[str, Dict[str, Any], "DefaultType"] - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] - boundary_chars: Union[str, "DefaultType"] - boundary_max_scan: Union[int, "DefaultType"] - boundary_scanner: Union[Literal["chars", "sentence", "word"], "DefaultType"] - boundary_scanner_locale: Union[str, "DefaultType"] - force_source: Union[bool, "DefaultType"] - fragmenter: Union[Literal["simple", "span"], "DefaultType"] - fragment_size: Union[int, "DefaultType"] - highlight_filter: Union[bool, "DefaultType"] - highlight_query: Union[Query, "DefaultType"] - max_fragment_length: Union[int, "DefaultType"] - max_analyzed_offset: Union[int, "DefaultType"] - no_match_size: Union[int, "DefaultType"] - number_of_fragments: Union[int, "DefaultType"] - options: Union[Mapping[str, Any], "DefaultType"] - order: Union[Literal["score"], "DefaultType"] - phrase_limit: Union[int, "DefaultType"] - post_tags: Union[Sequence[str], "DefaultType"] - pre_tags: Union[Sequence[str], "DefaultType"] - require_field_match: Union[bool, "DefaultType"] - tags_schema: Union[Literal["styled"], "DefaultType"] + analyzer: Union[str, Dict[str, Any], DefaultType] + type: Union[Literal["plain", "fvh", "unified"], DefaultType] + boundary_chars: Union[str, DefaultType] + boundary_max_scan: Union[int, DefaultType] + boundary_scanner: Union[Literal["chars", "sentence", "word"], DefaultType] + boundary_scanner_locale: Union[str, DefaultType] + force_source: Union[bool, DefaultType] + fragmenter: Union[Literal["simple", "span"], DefaultType] + fragment_size: Union[int, DefaultType] + highlight_filter: Union[bool, DefaultType] + highlight_query: Union[Query, DefaultType] + max_fragment_length: Union[int, DefaultType] + max_analyzed_offset: Union[int, DefaultType] + no_match_size: Union[int, DefaultType] + number_of_fragments: Union[int, DefaultType] + options: Union[Mapping[str, Any], DefaultType] + order: Union[Literal["score"], DefaultType] + phrase_limit: Union[int, DefaultType] + post_tags: Union[Sequence[str], DefaultType] + pre_tags: Union[Sequence[str], DefaultType] + require_field_match: Union[bool, DefaultType] + tags_schema: Union[Literal["styled"], DefaultType] def __init__( self, *, - fragment_offset: Union[int, "DefaultType"] = DEFAULT, + fragment_offset: Union[int, DefaultType] = DEFAULT, matched_fields: Union[ - Union[str, "InstrumentedField"], - Sequence[Union[str, "InstrumentedField"]], - "DefaultType", + Union[str, InstrumentedField], + Sequence[Union[str, InstrumentedField]], + DefaultType, ] = DEFAULT, - analyzer: Union[str, Dict[str, Any], "DefaultType"] = DEFAULT, - type: Union[Literal["plain", "fvh", "unified"], "DefaultType"] = DEFAULT, - boundary_chars: Union[str, "DefaultType"] = DEFAULT, - boundary_max_scan: Union[int, "DefaultType"] = DEFAULT, + analyzer: Union[str, Dict[str, Any], DefaultType] = DEFAULT, + type: Union[Literal["plain", "fvh", "unified"], DefaultType] = DEFAULT, + boundary_chars: Union[str, DefaultType] = DEFAULT, + boundary_max_scan: Union[int, DefaultType] = DEFAULT, boundary_scanner: Union[ - Literal["chars", "sentence", "word"], "DefaultType" + Literal["chars", "sentence", "word"], DefaultType ] = DEFAULT, - boundary_scanner_locale: Union[str, "DefaultType"] = DEFAULT, - force_source: Union[bool, "DefaultType"] = DEFAULT, - fragmenter: Union[Literal["simple", "span"], "DefaultType"] = DEFAULT, - fragment_size: Union[int, "DefaultType"] = DEFAULT, - highlight_filter: Union[bool, "DefaultType"] = DEFAULT, - highlight_query: Union[Query, "DefaultType"] = DEFAULT, - max_fragment_length: Union[int, "DefaultType"] = DEFAULT, - max_analyzed_offset: Union[int, "DefaultType"] = DEFAULT, - no_match_size: Union[int, "DefaultType"] = DEFAULT, - number_of_fragments: Union[int, "DefaultType"] = DEFAULT, - options: Union[Mapping[str, Any], "DefaultType"] = DEFAULT, - order: Union[Literal["score"], "DefaultType"] = DEFAULT, - phrase_limit: Union[int, "DefaultType"] = DEFAULT, - post_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - pre_tags: Union[Sequence[str], "DefaultType"] = DEFAULT, - require_field_match: Union[bool, "DefaultType"] = DEFAULT, - tags_schema: Union[Literal["styled"], "DefaultType"] = DEFAULT, + boundary_scanner_locale: Union[str, DefaultType] = DEFAULT, + force_source: Union[bool, DefaultType] = DEFAULT, + fragmenter: Union[Literal["simple", "span"], DefaultType] = DEFAULT, + fragment_size: Union[int, DefaultType] = DEFAULT, + highlight_filter: Union[bool, DefaultType] = DEFAULT, + highlight_query: Union[Query, DefaultType] = DEFAULT, + max_fragment_length: Union[int, DefaultType] = DEFAULT, + max_analyzed_offset: Union[int, DefaultType] = DEFAULT, + no_match_size: Union[int, DefaultType] = DEFAULT, + number_of_fragments: Union[int, DefaultType] = DEFAULT, + options: Union[Mapping[str, Any], DefaultType] = DEFAULT, + order: Union[Literal["score"], DefaultType] = DEFAULT, + phrase_limit: Union[int, DefaultType] = DEFAULT, + post_tags: Union[Sequence[str], DefaultType] = DEFAULT, + pre_tags: Union[Sequence[str], DefaultType] = DEFAULT, + require_field_match: Union[bool, DefaultType] = DEFAULT, + tags_schema: Union[Literal["styled"], DefaultType] = DEFAULT, **kwargs: Any, ): if fragment_offset is not DEFAULT: @@ -3086,12 +3036,12 @@ class ScoreSort(AttrDict[Any]): :arg order: """ - order: Union[Literal["asc", "desc"], "DefaultType"] + order: Union[Literal["asc", "desc"], DefaultType] def __init__( self, *, - order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, + order: Union[Literal["asc", "desc"], DefaultType] = DEFAULT, **kwargs: Any, ): if order is not DEFAULT: @@ -3109,28 +3059,28 @@ class GeoDistanceSort(AttrDict[Any]): :arg nested: """ - mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] - distance_type: Union[Literal["arc", "plane"], "DefaultType"] - ignore_unmapped: Union[bool, "DefaultType"] - order: Union[Literal["asc", "desc"], "DefaultType"] + mode: Union[Literal["min", "max", "sum", "avg", "median"], DefaultType] + distance_type: Union[Literal["arc", "plane"], DefaultType] + ignore_unmapped: Union[bool, DefaultType] + order: Union[Literal["asc", "desc"], DefaultType] unit: Union[ - Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], DefaultType ] - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] def __init__( self, *, mode: Union[ - Literal["min", "max", "sum", "avg", "median"], "DefaultType" + Literal["min", "max", "sum", "avg", "median"], DefaultType ] = DEFAULT, - distance_type: Union[Literal["arc", "plane"], "DefaultType"] = DEFAULT, - ignore_unmapped: Union[bool, "DefaultType"] = DEFAULT, - order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, + distance_type: Union[Literal["arc", "plane"], DefaultType] = DEFAULT, + ignore_unmapped: Union[bool, DefaultType] = DEFAULT, + order: Union[Literal["asc", "desc"], DefaultType] = DEFAULT, unit: Union[ - Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType" + Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], DefaultType ] = DEFAULT, - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if mode is not DEFAULT: @@ -3157,22 +3107,22 @@ class ScriptSort(AttrDict[Any]): :arg nested: """ - script: Union["types.Script", Dict[str, Any], "DefaultType"] - order: Union[Literal["asc", "desc"], "DefaultType"] - type: Union[Literal["string", "number", "version"], "DefaultType"] - mode: Union[Literal["min", "max", "sum", "avg", "median"], "DefaultType"] - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] + script: Union["Script", Dict[str, Any], DefaultType] + order: Union[Literal["asc", "desc"], DefaultType] + type: Union[Literal["string", "number", "version"], DefaultType] + mode: Union[Literal["min", "max", "sum", "avg", "median"], DefaultType] + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] def __init__( self, *, - script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, - order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT, - type: Union[Literal["string", "number", "version"], "DefaultType"] = DEFAULT, + script: Union["Script", Dict[str, Any], DefaultType] = DEFAULT, + order: Union[Literal["asc", "desc"], DefaultType] = DEFAULT, + type: Union[Literal["string", "number", "version"], DefaultType] = DEFAULT, mode: Union[ - Literal["min", "max", "sum", "avg", "median"], "DefaultType" + Literal["min", "max", "sum", "avg", "median"], DefaultType ] = DEFAULT, - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if script is not DEFAULT: @@ -3199,24 +3149,22 @@ class IntervalsContainer(AttrDict[Any]): :arg wildcard: Matches terms using a wildcard pattern. """ - all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] - any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] - fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] - match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] - prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] - wildcard: Union["types.IntervalsWildcard", Dict[str, Any], "DefaultType"] + all_of: Union["IntervalsAllOf", Dict[str, Any], DefaultType] + any_of: Union["IntervalsAnyOf", Dict[str, Any], DefaultType] + fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] + match: Union["IntervalsMatch", Dict[str, Any], DefaultType] + prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] + wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] def __init__( self, *, - all_of: Union["types.IntervalsAllOf", Dict[str, Any], "DefaultType"] = DEFAULT, - any_of: Union["types.IntervalsAnyOf", Dict[str, Any], "DefaultType"] = DEFAULT, - fuzzy: Union["types.IntervalsFuzzy", Dict[str, Any], "DefaultType"] = DEFAULT, - match: Union["types.IntervalsMatch", Dict[str, Any], "DefaultType"] = DEFAULT, - prefix: Union["types.IntervalsPrefix", Dict[str, Any], "DefaultType"] = DEFAULT, - wildcard: Union[ - "types.IntervalsWildcard", Dict[str, Any], "DefaultType" - ] = DEFAULT, + all_of: Union["IntervalsAllOf", Dict[str, Any], DefaultType] = DEFAULT, + any_of: Union["IntervalsAnyOf", Dict[str, Any], DefaultType] = DEFAULT, + fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] = DEFAULT, + match: Union["IntervalsMatch", Dict[str, Any], DefaultType] = DEFAULT, + prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] = DEFAULT, + wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if all_of is not DEFAULT: @@ -3256,44 +3204,36 @@ class IntervalsFilter(AttrDict[Any]): must return a boolean value: `true` or `false`. """ - after: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - before: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - contained_by: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - containing: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_contained_by: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_containing: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - not_overlapping: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - overlapping: Union["types.IntervalsContainer", Dict[str, Any], "DefaultType"] - script: Union["types.Script", Dict[str, Any], "DefaultType"] + after: Union["IntervalsContainer", Dict[str, Any], DefaultType] + before: Union["IntervalsContainer", Dict[str, Any], DefaultType] + contained_by: Union["IntervalsContainer", Dict[str, Any], DefaultType] + containing: Union["IntervalsContainer", Dict[str, Any], DefaultType] + not_contained_by: Union["IntervalsContainer", Dict[str, Any], DefaultType] + not_containing: Union["IntervalsContainer", Dict[str, Any], DefaultType] + not_overlapping: Union["IntervalsContainer", Dict[str, Any], DefaultType] + overlapping: Union["IntervalsContainer", Dict[str, Any], DefaultType] + script: Union["Script", Dict[str, Any], DefaultType] def __init__( self, *, - after: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" - ] = DEFAULT, - before: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" - ] = DEFAULT, + after: Union["IntervalsContainer", Dict[str, Any], DefaultType] = DEFAULT, + before: Union["IntervalsContainer", Dict[str, Any], DefaultType] = DEFAULT, contained_by: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" - ] = DEFAULT, - containing: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" + "IntervalsContainer", Dict[str, Any], DefaultType ] = DEFAULT, + containing: Union["IntervalsContainer", Dict[str, Any], DefaultType] = DEFAULT, not_contained_by: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" + "IntervalsContainer", Dict[str, Any], DefaultType ] = DEFAULT, not_containing: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" + "IntervalsContainer", Dict[str, Any], DefaultType ] = DEFAULT, not_overlapping: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" - ] = DEFAULT, - overlapping: Union[ - "types.IntervalsContainer", Dict[str, Any], "DefaultType" + "IntervalsContainer", Dict[str, Any], DefaultType ] = DEFAULT, - script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + overlapping: Union["IntervalsContainer", Dict[str, Any], DefaultType] = DEFAULT, + script: Union["Script", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if after is not DEFAULT: @@ -3325,18 +3265,18 @@ class NestedSortValue(AttrDict[Any]): :arg nested: """ - path: Union[str, "InstrumentedField", "DefaultType"] - filter: Union[Query, "DefaultType"] - max_children: Union[int, "DefaultType"] - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] + path: Union[str, InstrumentedField, DefaultType] + filter: Union[Query, DefaultType] + max_children: Union[int, DefaultType] + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] def __init__( self, *, - path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT, - filter: Union[Query, "DefaultType"] = DEFAULT, - max_children: Union[int, "DefaultType"] = DEFAULT, - nested: Union["types.NestedSortValue", Dict[str, Any], "DefaultType"] = DEFAULT, + path: Union[str, InstrumentedField, DefaultType] = DEFAULT, + filter: Union[Query, DefaultType] = DEFAULT, + max_children: Union[int, DefaultType] = DEFAULT, + nested: Union["NestedSortValue", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): if path is not DEFAULT: diff --git a/utils/generator.py b/utils/generator.py index bb4bcfc0..8da924fa 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -16,6 +16,7 @@ # under the License. import json +import re import textwrap from urllib.error import HTTPError from urllib.request import urlopen @@ -234,7 +235,7 @@ def get_python_type(self, schema_type): raise RuntimeError(f"Cannot find Python type for {schema_type}") - def add_attribute(self, k, arg): + def add_attribute(self, k, arg, for_types_py=False): """Add an attribute to the internal representation of a class. This method adds the argument `arg` to the data structure for a class @@ -243,6 +244,13 @@ def add_attribute(self, k, arg): argument is of a type that needs Python DSL specific typing details to be stored in the DslBase._param_defs attribute, then this is added to `k["params"]`. + + When `for_types_py` is `True`, type hints are formatted in the most + convenient way for the types.py file. When possible, double quotes are + removed from types, and for types that are in the same file the quotes + are kept to prevent forward references, but the "types." namespace is + removed. When `for_types_py` is `False`, all non-native types use + quotes and are namespaced. """ try: type_, param = schema.get_python_type(arg["type"]) @@ -253,6 +261,12 @@ def add_attribute(self, k, arg): if "types." in type_: type_ = add_dict_type(type_) # interfaces can be given as dicts type_ = add_not_set(type_) + if for_types_py: + type_ = type_.replace('"DefaultType"', "DefaultType") + type_ = type_.replace('"InstrumentedField"', "InstrumentedField") + type_ = re.sub(r'"(function\.[a-zA-Z0-9_]+)"', r"\1", type_) + type_ = re.sub(r'"types\.([a-zA-Z0-9_]+)"', r'"\1"', type_) + type_ = re.sub(r'"(wrappers\.[a-zA-Z0-9_]+)"', r"\1", type_) required = "(required) " if arg["required"] else "" server_default = ( f" Defaults to `{arg['serverDefault']}` if omitted." @@ -463,7 +477,7 @@ def interface_to_python_class(self, interface, interfaces): k = {"name": interface, "args": []} while True: for arg in type_["properties"]: - schema.add_attribute(k, arg) + schema.add_attribute(k, arg, for_types_py=True) if "inherits" in type_ and "type" in type_["inherits"]: if "parent" not in k: k["parent"] = type_["inherits"]["type"]["name"] diff --git a/utils/templates/types.py.tpl b/utils/templates/types.py.tpl index 85bedb87..23877603 100644 --- a/utils/templates/types.py.tpl +++ b/utils/templates/types.py.tpl @@ -20,7 +20,7 @@ from typing import Any, Dict, Literal, Mapping, Sequence, Union from elastic_transport.client_utils import DEFAULT, DefaultType from elasticsearch_dsl.document_base import InstrumentedField -from elasticsearch_dsl import function, types, Query +from elasticsearch_dsl import function, Query from elasticsearch_dsl.utils import AttrDict PipeSeparatedFlags = str From 2dc5a23ef5be35a62676ff28d02057c8f2fa2269 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 11 Sep 2024 18:10:35 +0100 Subject: [PATCH 24/27] Update utils/templates/types.py.tpl Co-authored-by: Quentin Pradet --- utils/templates/types.py.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/templates/types.py.tpl b/utils/templates/types.py.tpl index 23877603..e786e606 100644 --- a/utils/templates/types.py.tpl +++ b/utils/templates/types.py.tpl @@ -27,7 +27,7 @@ PipeSeparatedFlags = str {% for k in classes %} -class {{ k.name }}({% if k.parent %}{{ k.parent }}{% else %}AttrDict[Any]{% endif %}): +class {{ k.name }}({ k.parent if k.parent else "AttrDict[Any]" }}): {% if k.args %} """ {% for arg in k.args %} From 937ddf1009f896c2c959d76a9f850783c42538e4 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 11 Sep 2024 18:11:34 +0100 Subject: [PATCH 25/27] Update utils/generator.py Co-authored-by: Quentin Pradet --- utils/generator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/generator.py b/utils/generator.py index 8da924fa..68b98c6c 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -289,8 +289,7 @@ def add_attribute(self, k, arg, for_types_py=False): # insert in the right place so that all required arguments # appear at the top of the argument list i = 0 - for i in range(len(k["args"]) + 1): - if i == len(k["args"]): + for i, arg in enumerate(k["args"]): break if k["args"][i].get("positional"): continue From bb23d01e64b5e5dc824afa112ab6e176b9b4146f Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 11 Sep 2024 18:13:15 +0100 Subject: [PATCH 26/27] Update utils/generator.py Co-authored-by: Quentin Pradet --- utils/generator.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/utils/generator.py b/utils/generator.py index 68b98c6c..8ed27212 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -475,19 +475,19 @@ def interface_to_python_class(self, interface, interfaces): raise RuntimeError(f"Type {interface} is not an interface") k = {"name": interface, "args": []} while True: + if "inherits" not in type_ or "type" not in type_["inherits"]: + break + for arg in type_["properties"]: schema.add_attribute(k, arg, for_types_py=True) - if "inherits" in type_ and "type" in type_["inherits"]: - if "parent" not in k: - k["parent"] = type_["inherits"]["type"]["name"] - if type_["inherits"]["type"]["name"] not in interfaces: - interfaces.append(type_["inherits"]["type"]["name"]) - type_ = schema.find_type( - type_["inherits"]["type"]["name"], - type_["inherits"]["type"]["namespace"], - ) - else: - break + if "parent" not in k: + k["parent"] = type_["inherits"]["type"]["name"] + if type_["inherits"]["type"]["name"] not in interfaces: + interfaces.append(type_["inherits"]["type"]["name"]) + type_ = schema.find_type( + type_["inherits"]["type"]["name"], + type_["inherits"]["type"]["namespace"], + ) return k From 0a17b261920b525b420474a9378f8707ccfc1315 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 11 Sep 2024 18:23:09 +0100 Subject: [PATCH 27/27] final round of review improvements --- utils/generator.py | 10 +++++---- utils/templates/query.py.tpl | 43 ++++++++++++++++++++++-------------- utils/templates/types.py.tpl | 22 +++++++++--------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/utils/generator.py b/utils/generator.py index 8ed27212..c0a4f3a0 100644 --- a/utils/generator.py +++ b/utils/generator.py @@ -289,7 +289,8 @@ def add_attribute(self, k, arg, for_types_py=False): # insert in the right place so that all required arguments # appear at the top of the argument list i = 0 - for i, arg in enumerate(k["args"]): + for i in range(len(k["args"]) + 1): + if i == len(k["args"]): break if k["args"][i].get("positional"): continue @@ -475,11 +476,12 @@ def interface_to_python_class(self, interface, interfaces): raise RuntimeError(f"Type {interface} is not an interface") k = {"name": interface, "args": []} while True: - if "inherits" not in type_ or "type" not in type_["inherits"]: - break - for arg in type_["properties"]: schema.add_attribute(k, arg, for_types_py=True) + + if "inherits" not in type_ or "type" not in type_["inherits"]: + break + if "parent" not in k: k["parent"] = type_["inherits"]["type"]["name"] if type_["inherits"]["type"]["name"] not in interfaces: diff --git a/utils/templates/query.py.tpl b/utils/templates/query.py.tpl index a31e4b75..23b23809 100644 --- a/utils/templates/query.py.tpl +++ b/utils/templates/query.py.tpl @@ -153,47 +153,51 @@ class {{ k.name }}({{ parent }}): {{ line }} {% endfor %} {% if k.args %} - {% if k.docstring %} + {% if k.docstring %} - {% endif %} - {% for kwarg in k.args %} - {% for line in kwarg.doc %} + {% endif %} + {% for kwarg in k.args %} + {% for line in kwarg.doc %} {{ line }} - {% endfor %} - {% endfor %} + {% endfor %} + {% endfor %} {% endif %} """ name = "{{ k.property_name }}" {% if k.params %} _param_defs = { - {% for param in k.params %} + {% for param in k.params %} "{{ param.name }}": {{ param.param }}, - {% endfor %} - {% if k.name == "FunctionScore" %} + {% endfor %} + {% if k.name == "FunctionScore" %} + {# The FunctionScore class implements a custom solution for the `functions` + shortcut property. Until the code generator can support shortcut + properties directly that solution is added here #} "filter": {"type": "query"}, "functions": {"type": "score_function", "multi": True}, - {% endif %} + {% endif %} } {% endif %} def __init__( self, {% for arg in k.args %} - {% if arg.positional %} + {% if arg.positional %} {{ arg.name }}: {{ arg.type }} = DEFAULT, - {% endif %} + {% endif %} {% endfor %} {% if k.args and not k.args[-1].positional %} *, {% endif %} {% for arg in k.args %} - {% if not arg.positional %} + {% if not arg.positional %} {{ arg.name }}: {{ arg.type }} = DEFAULT, - {% endif %} + {% endif %} {% endfor %} **kwargs: Any ): {% if k.name == "FunctionScore" %} + {# continuation of the FunctionScore shortcut property support from above #} if functions is DEFAULT: functions = [] for name in ScoreFunction._classes: @@ -209,13 +213,15 @@ class {{ k.name }}({{ parent }}): {% endif %} super().__init__( {% for arg in k.args %} - {% if not arg.positional %} + {% if not arg.positional %} {{ arg.name }}={{ arg.name }}, - {% endif %} + {% endif %} {% endfor %} **kwargs ) + {# what follows is a set of Pythonic enhancements to some of the query classes + which are outside the scope of the code generator #} {% if k.name == "MatchAll" %} def __add__(self, other: "Query") -> "Query": return other._clone() @@ -358,7 +364,10 @@ EMPTY_QUERY = MatchAll() {% elif k.name == "Terms" %} def _setattr(self, name: str, value: Any) -> None: - super()._setattr(name, list(value)) + # here we convert any iterables that are not strings to lists + if hasattr(value, "__iter__") and not isinstance(value, (str, list)): + value = list(value) + super()._setattr(name, value) {% endif %} diff --git a/utils/templates/types.py.tpl b/utils/templates/types.py.tpl index e786e606..ea2a5c11 100644 --- a/utils/templates/types.py.tpl +++ b/utils/templates/types.py.tpl @@ -27,18 +27,18 @@ PipeSeparatedFlags = str {% for k in classes %} -class {{ k.name }}({ k.parent if k.parent else "AttrDict[Any]" }}): +class {{ k.name }}({{ k.parent if k.parent else "AttrDict[Any]" }}): {% if k.args %} """ - {% for arg in k.args %} - {% for line in arg.doc %} + {% for arg in k.args %} + {% for line in arg.doc %} {{ line }} - {% endfor %} - {% endfor %} + {% endfor %} + {% endfor %} """ - {% for arg in k.args %} + {% for arg in k.args %} {{ arg.name }}: {{ arg.type }} - {% endfor %} + {% endfor %} def __init__( self, @@ -62,14 +62,14 @@ class {{ k.name }}({ k.parent if k.parent else "AttrDict[Any]" }}): kwargs[str(field)] = value {% endif %} {% for arg in k.args %} - {% if not arg.positional %} + {% if not arg.positional %} if {{ arg.name }} is not DEFAULT: - {% if "InstrumentedField" in arg.type %} + {% if "InstrumentedField" in arg.type %} kwargs["{{ arg.name }}"] = str({{ arg.name }}) - {% else %} + {% else %} kwargs["{{ arg.name }}"] = {{ arg.name }} + {% endif %} {% endif %} - {% endif %} {% endfor %} {% if k.parent %} super().__init__(**kwargs)