diff --git a/elasticsearch/dsl/aggs.py b/elasticsearch/dsl/aggs.py index ba5150803..3b7a8e8ba 100644 --- a/elasticsearch/dsl/aggs.py +++ b/elasticsearch/dsl/aggs.py @@ -678,9 +678,8 @@ class CategorizeText(Bucket[_R]): :arg categorization_analyzer: The categorization analyzer specifies how the text is analyzed and tokenized before being categorized. The syntax is very similar to that used to define the analyzer in - the [Analyze endpoint](https://www.elastic.co/guide/en/elasticsear - ch/reference/8.0/indices-analyze.html). This property cannot be - used at the same time as categorization_filters. + the `_analyze` endpoint. This property cannot be used at the same + time as categorization_filters. :arg shard_size: The number of categorization buckets to return from each shard before merging all the results. :arg size: The number of buckets to return. Defaults to `10` if diff --git a/elasticsearch/dsl/field.py b/elasticsearch/dsl/field.py index e3ed5dfcd..1aa7a4bca 100644 --- a/elasticsearch/dsl/field.py +++ b/elasticsearch/dsl/field.py @@ -280,7 +280,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -387,7 +390,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -463,7 +469,10 @@ def __init__( if subobjects is not DEFAULT: kwargs["subobjects"] = subobjects if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -575,6 +584,7 @@ class AggregateMetricDouble(Field): """ :arg default_metric: (required) :arg metrics: (required) + :arg ignore_malformed: :arg time_series_metric: :arg meta: Metadata about the field. :arg properties: @@ -595,6 +605,7 @@ def __init__( *args: Any, default_metric: Union[str, "DefaultType"] = DEFAULT, metrics: Union[Sequence[str], "DefaultType"] = DEFAULT, + ignore_malformed: Union[bool, "DefaultType"] = DEFAULT, time_series_metric: Union[ Literal["gauge", "counter", "summary", "histogram", "position"], "DefaultType", @@ -615,6 +626,8 @@ def __init__( kwargs["default_metric"] = default_metric if metrics is not DEFAULT: kwargs["metrics"] = metrics + if ignore_malformed is not DEFAULT: + kwargs["ignore_malformed"] = ignore_malformed if time_series_metric is not DEFAULT: kwargs["time_series_metric"] = time_series_metric if meta is not DEFAULT: @@ -727,7 +740,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -838,7 +854,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -953,7 +972,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1043,7 +1065,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1251,7 +1276,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1376,7 +1404,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1455,7 +1486,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1658,7 +1692,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1733,7 +1770,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1762,6 +1802,7 @@ class Flattened(Field): :arg null_value: :arg similarity: :arg split_queries_on_whitespace: + :arg time_series_dimensions: :arg meta: Metadata about the field. :arg properties: :arg ignore_above: @@ -1790,6 +1831,7 @@ def __init__( null_value: Union[str, "DefaultType"] = DEFAULT, similarity: Union[str, "DefaultType"] = DEFAULT, split_queries_on_whitespace: Union[bool, "DefaultType"] = DEFAULT, + time_series_dimensions: Union[Sequence[str], "DefaultType"] = DEFAULT, meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT, properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT, ignore_above: Union[int, "DefaultType"] = DEFAULT, @@ -1820,6 +1862,8 @@ def __init__( kwargs["similarity"] = similarity if split_queries_on_whitespace is not DEFAULT: kwargs["split_queries_on_whitespace"] = split_queries_on_whitespace + if time_series_dimensions is not DEFAULT: + kwargs["time_series_dimensions"] = time_series_dimensions if meta is not DEFAULT: kwargs["meta"] = meta if properties is not DEFAULT: @@ -1892,7 +1936,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -1918,6 +1965,7 @@ class GeoPoint(Field): :arg index: :arg on_script_error: :arg script: + :arg time_series_metric: :arg doc_values: :arg copy_to: :arg store: @@ -1951,6 +1999,9 @@ def __init__( index: Union[bool, "DefaultType"] = DEFAULT, on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT, script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT, + time_series_metric: Union[ + Literal["gauge", "counter", "position"], "DefaultType" + ] = DEFAULT, doc_values: Union[bool, "DefaultType"] = DEFAULT, copy_to: Union[ Union[str, "InstrumentedField"], @@ -1982,10 +2033,15 @@ def __init__( kwargs["on_script_error"] = on_script_error if script is not DEFAULT: kwargs["script"] = script + if time_series_metric is not DEFAULT: + kwargs["time_series_metric"] = time_series_metric if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2074,7 +2130,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2177,7 +2236,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2360,7 +2422,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2435,7 +2500,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2527,7 +2595,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2611,7 +2682,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2781,7 +2855,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2884,7 +2961,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -2959,7 +3039,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3016,7 +3099,10 @@ def __init__( if meta is not DEFAULT: kwargs["meta"] = meta if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) super().__init__(*args, **kwargs) @@ -3064,7 +3150,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3134,7 +3223,10 @@ def __init__( if include_in_root is not DEFAULT: kwargs["include_in_root"] = include_in_root if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3205,7 +3297,10 @@ def __init__( if time_series_dimension is not DEFAULT: kwargs["time_series_dimension"] = time_series_dimension if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3334,7 +3429,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3452,6 +3550,62 @@ def __init__( super().__init__(*args, **kwargs) +class RankVectors(Field): + """ + Technical preview + + :arg element_type: + :arg dims: + :arg meta: Metadata about the field. + :arg properties: + :arg ignore_above: + :arg dynamic: + :arg fields: + :arg synthetic_source_keep: + """ + + name = "rank_vectors" + _param_defs = { + "properties": {"type": "field", "hash": True}, + "fields": {"type": "field", "hash": True}, + } + + def __init__( + self, + *args: Any, + element_type: Union[Literal["byte", "float", "bit"], "DefaultType"] = DEFAULT, + dims: Union[int, "DefaultType"] = DEFAULT, + meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT, + properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT, + ignore_above: Union[int, "DefaultType"] = DEFAULT, + dynamic: Union[ + Literal["strict", "runtime", "true", "false"], bool, "DefaultType" + ] = DEFAULT, + fields: Union[Mapping[str, Field], "DefaultType"] = DEFAULT, + synthetic_source_keep: Union[ + Literal["none", "arrays", "all"], "DefaultType" + ] = DEFAULT, + **kwargs: Any, + ): + if element_type is not DEFAULT: + kwargs["element_type"] = element_type + if dims is not DEFAULT: + kwargs["dims"] = dims + if meta is not DEFAULT: + kwargs["meta"] = meta + if properties is not DEFAULT: + kwargs["properties"] = properties + if ignore_above is not DEFAULT: + kwargs["ignore_above"] = ignore_above + if dynamic is not DEFAULT: + kwargs["dynamic"] = dynamic + if fields is not DEFAULT: + kwargs["fields"] = fields + if synthetic_source_keep is not DEFAULT: + kwargs["synthetic_source_keep"] = synthetic_source_keep + super().__init__(*args, **kwargs) + + class ScaledFloat(Float): """ :arg null_value: @@ -3541,7 +3695,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3657,7 +3814,10 @@ def __init__( if term_vector is not DEFAULT: kwargs["term_vector"] = term_vector if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3689,11 +3849,6 @@ class SemanticText(Field): by using the Update mapping API. Use the Create inference API to create the endpoint. If not specified, the inference endpoint defined by inference_id will be used at both index and query time. - :arg chunking_settings: Settings for chunking text into smaller - passages. If specified, these will override the chunking settings - sent in the inference endpoint associated with inference_id. If - chunking settings are updated, they will not be applied to - existing documents until they are reindexed. """ name = "semantic_text" @@ -3704,9 +3859,6 @@ def __init__( meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT, inference_id: Union[str, "DefaultType"] = DEFAULT, search_inference_id: Union[str, "DefaultType"] = DEFAULT, - chunking_settings: Union[ - "types.ChunkingSettings", Dict[str, Any], "DefaultType" - ] = DEFAULT, **kwargs: Any, ): if meta is not DEFAULT: @@ -3715,8 +3867,6 @@ def __init__( kwargs["inference_id"] = inference_id if search_inference_id is not DEFAULT: kwargs["search_inference_id"] = search_inference_id - if chunking_settings is not DEFAULT: - kwargs["chunking_settings"] = chunking_settings super().__init__(*args, **kwargs) @@ -3783,7 +3933,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3886,7 +4039,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -3906,6 +4062,7 @@ def __init__( class SparseVector(Field): """ + :arg store: :arg meta: Metadata about the field. :arg properties: :arg ignore_above: @@ -3923,6 +4080,7 @@ class SparseVector(Field): def __init__( self, *args: Any, + store: Union[bool, "DefaultType"] = DEFAULT, meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT, properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT, ignore_above: Union[int, "DefaultType"] = DEFAULT, @@ -3935,6 +4093,8 @@ def __init__( ] = DEFAULT, **kwargs: Any, ): + if store is not DEFAULT: + kwargs["store"] = store if meta is not DEFAULT: kwargs["meta"] = meta if properties is not DEFAULT: @@ -4070,7 +4230,10 @@ def __init__( if term_vector is not DEFAULT: kwargs["term_vector"] = term_vector if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -4153,7 +4316,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -4256,7 +4422,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -4318,7 +4487,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: @@ -4384,7 +4556,10 @@ def __init__( if doc_values is not DEFAULT: kwargs["doc_values"] = doc_values if copy_to is not DEFAULT: - kwargs["copy_to"] = str(copy_to) + if isinstance(copy_to, list): + kwargs["copy_to"] = [str(field) for field in copy_to] + else: + kwargs["copy_to"] = str(copy_to) if store is not DEFAULT: kwargs["store"] = store if meta is not DEFAULT: diff --git a/elasticsearch/dsl/query.py b/elasticsearch/dsl/query.py index 720f49f78..f203332e4 100644 --- a/elasticsearch/dsl/query.py +++ b/elasticsearch/dsl/query.py @@ -2034,8 +2034,9 @@ def __init__( class Rule(Query): """ :arg organic: (required) - :arg ruleset_ids: (required) :arg match_criteria: (required) + :arg ruleset_ids: + :arg ruleset_id: :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 @@ -2053,16 +2054,18 @@ def __init__( self, *, organic: Union[Query, "DefaultType"] = DEFAULT, - ruleset_ids: Union[Sequence[str], "DefaultType"] = DEFAULT, match_criteria: Any = DEFAULT, + ruleset_ids: Union[str, Sequence[str], "DefaultType"] = DEFAULT, + ruleset_id: Union[str, "DefaultType"] = 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, + ruleset_ids=ruleset_ids, + ruleset_id=ruleset_id, boost=boost, _name=_name, **kwargs, diff --git a/elasticsearch/dsl/types.py b/elasticsearch/dsl/types.py index d21f70698..5d7b88b32 100644 --- a/elasticsearch/dsl/types.py +++ b/elasticsearch/dsl/types.py @@ -170,48 +170,6 @@ def __init__( super().__init__(kwargs) -class ChunkingSettings(AttrDict[Any]): - """ - :arg strategy: (required) The chunking strategy: `sentence` or `word`. - Defaults to `sentence` if omitted. - :arg max_chunk_size: (required) The maximum size of a chunk in words. - This value cannot be higher than `300` or lower than `20` (for - `sentence` strategy) or `10` (for `word` strategy). Defaults to - `250` if omitted. - :arg overlap: The number of overlapping words for chunks. It is - applicable only to a `word` chunking strategy. This value cannot - be higher than half the `max_chunk_size` value. Defaults to `100` - if omitted. - :arg sentence_overlap: The number of overlapping sentences for chunks. - It is applicable only for a `sentence` chunking strategy. It can - be either `1` or `0`. Defaults to `1` if omitted. - """ - - strategy: Union[str, DefaultType] - max_chunk_size: Union[int, DefaultType] - overlap: Union[int, DefaultType] - sentence_overlap: Union[int, DefaultType] - - def __init__( - self, - *, - strategy: Union[str, DefaultType] = DEFAULT, - max_chunk_size: Union[int, DefaultType] = DEFAULT, - overlap: Union[int, DefaultType] = DEFAULT, - sentence_overlap: Union[int, DefaultType] = DEFAULT, - **kwargs: Any, - ): - if strategy is not DEFAULT: - kwargs["strategy"] = strategy - if max_chunk_size is not DEFAULT: - kwargs["max_chunk_size"] = max_chunk_size - if overlap is not DEFAULT: - kwargs["overlap"] = overlap - if sentence_overlap is not DEFAULT: - kwargs["sentence_overlap"] = sentence_overlap - super().__init__(kwargs) - - class ClassificationInferenceOptions(AttrDict[Any]): """ :arg num_top_classes: Specifies the number of top class predictions to @@ -969,7 +927,7 @@ def __init__( class GeoGridQuery(AttrDict[Any]): """ - :arg geogrid: + :arg geotile: :arg geohash: :arg geohex: :arg boost: Floating point number used to decrease or increase the @@ -980,7 +938,7 @@ class GeoGridQuery(AttrDict[Any]): :arg _name: """ - geogrid: Union[str, DefaultType] + geotile: Union[str, DefaultType] geohash: Union[str, DefaultType] geohex: Union[str, DefaultType] boost: Union[float, DefaultType] @@ -989,15 +947,15 @@ class GeoGridQuery(AttrDict[Any]): def __init__( self, *, - geogrid: Union[str, DefaultType] = DEFAULT, + geotile: Union[str, DefaultType] = DEFAULT, geohash: Union[str, DefaultType] = DEFAULT, geohex: Union[str, DefaultType] = DEFAULT, boost: Union[float, DefaultType] = DEFAULT, _name: Union[str, DefaultType] = DEFAULT, **kwargs: Any, ): - if geogrid is not DEFAULT: - kwargs["geogrid"] = geogrid + if geotile is not DEFAULT: + kwargs["geotile"] = geotile if geohash is not DEFAULT: kwargs["geohash"] = geohash if geohex is not DEFAULT: @@ -1823,6 +1781,8 @@ class IntervalsContainer(AttrDict[Any]): :arg match: Matches analyzed text. :arg prefix: Matches terms that start with a specified set of characters. + :arg range: + :arg regexp: :arg wildcard: Matches terms using a wildcard pattern. """ @@ -1831,6 +1791,8 @@ class IntervalsContainer(AttrDict[Any]): fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] match: Union["IntervalsMatch", Dict[str, Any], DefaultType] prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] + range: Union["IntervalsRange", Dict[str, Any], DefaultType] + regexp: Union["IntervalsRegexp", Dict[str, Any], DefaultType] wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] def __init__( @@ -1841,6 +1803,8 @@ def __init__( fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] = DEFAULT, match: Union["IntervalsMatch", Dict[str, Any], DefaultType] = DEFAULT, prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] = DEFAULT, + range: Union["IntervalsRange", Dict[str, Any], DefaultType] = DEFAULT, + regexp: Union["IntervalsRegexp", Dict[str, Any], DefaultType] = DEFAULT, wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] = DEFAULT, **kwargs: Any, ): @@ -1854,6 +1818,10 @@ def __init__( kwargs["match"] = match if prefix is not DEFAULT: kwargs["prefix"] = prefix + if range is not DEFAULT: + kwargs["range"] = range + if regexp is not DEFAULT: + kwargs["regexp"] = regexp if wildcard is not DEFAULT: kwargs["wildcard"] = wildcard super().__init__(kwargs) @@ -2074,6 +2042,8 @@ class IntervalsQuery(AttrDict[Any]): :arg match: Matches analyzed text. :arg prefix: Matches terms that start with a specified set of characters. + :arg range: + :arg regexp: :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 @@ -2088,6 +2058,8 @@ class IntervalsQuery(AttrDict[Any]): fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] match: Union["IntervalsMatch", Dict[str, Any], DefaultType] prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] + range: Union["IntervalsRange", Dict[str, Any], DefaultType] + regexp: Union["IntervalsRegexp", Dict[str, Any], DefaultType] wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] boost: Union[float, DefaultType] _name: Union[str, DefaultType] @@ -2100,6 +2072,8 @@ def __init__( fuzzy: Union["IntervalsFuzzy", Dict[str, Any], DefaultType] = DEFAULT, match: Union["IntervalsMatch", Dict[str, Any], DefaultType] = DEFAULT, prefix: Union["IntervalsPrefix", Dict[str, Any], DefaultType] = DEFAULT, + range: Union["IntervalsRange", Dict[str, Any], DefaultType] = DEFAULT, + regexp: Union["IntervalsRegexp", Dict[str, Any], DefaultType] = DEFAULT, wildcard: Union["IntervalsWildcard", Dict[str, Any], DefaultType] = DEFAULT, boost: Union[float, DefaultType] = DEFAULT, _name: Union[str, DefaultType] = DEFAULT, @@ -2115,6 +2089,10 @@ def __init__( kwargs["match"] = match if prefix is not DEFAULT: kwargs["prefix"] = prefix + if range is not DEFAULT: + kwargs["range"] = range + if regexp is not DEFAULT: + kwargs["regexp"] = regexp if wildcard is not DEFAULT: kwargs["wildcard"] = wildcard if boost is not DEFAULT: @@ -2124,6 +2102,83 @@ def __init__( super().__init__(kwargs) +class IntervalsRange(AttrDict[Any]): + """ + :arg analyzer: Analyzer used to analyze the `prefix`. + :arg gte: Lower term, either gte or gt must be provided. + :arg gt: Lower term, either gte or gt must be provided. + :arg lte: Upper term, either lte or lt must be provided. + :arg lt: Upper term, either lte or lt must be provided. + :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] + gte: Union[str, DefaultType] + gt: Union[str, DefaultType] + lte: Union[str, DefaultType] + lt: Union[str, DefaultType] + use_field: Union[str, InstrumentedField, DefaultType] + + def __init__( + self, + *, + analyzer: Union[str, DefaultType] = DEFAULT, + gte: Union[str, DefaultType] = DEFAULT, + gt: Union[str, DefaultType] = DEFAULT, + lte: Union[str, DefaultType] = DEFAULT, + lt: Union[str, DefaultType] = DEFAULT, + use_field: Union[str, InstrumentedField, DefaultType] = DEFAULT, + **kwargs: Any, + ): + if analyzer is not DEFAULT: + kwargs["analyzer"] = analyzer + if gte is not DEFAULT: + kwargs["gte"] = gte + if gt is not DEFAULT: + kwargs["gt"] = gt + if lte is not DEFAULT: + kwargs["lte"] = lte + if lt is not DEFAULT: + kwargs["lt"] = lt + if use_field is not DEFAULT: + kwargs["use_field"] = str(use_field) + super().__init__(kwargs) + + +class IntervalsRegexp(AttrDict[Any]): + """ + :arg pattern: (required) Regex pattern. + :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. + """ + + 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, + **kwargs: Any, + ): + 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) + + class IntervalsWildcard(AttrDict[Any]): """ :arg pattern: (required) Wildcard pattern used to find matching terms. @@ -4828,7 +4883,7 @@ class ErrorCause(AttrDict[Any]): """ type: str - reason: str + reason: Union[str, None] stack_trace: str caused_by: "ErrorCause" root_cause: Sequence["ErrorCause"] diff --git a/test_elasticsearch/test_dsl/test_integration/_async/test_document.py b/test_elasticsearch/test_dsl/test_integration/_async/test_document.py index e72955a0a..99f475cf1 100644 --- a/test_elasticsearch/test_dsl/test_integration/_async/test_document.py +++ b/test_elasticsearch/test_dsl/test_integration/_async/test_document.py @@ -23,7 +23,7 @@ from datetime import datetime from ipaddress import ip_address -from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, List, Tuple, Union +from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, List, Optional, Tuple, Union import pytest from pytest import raises @@ -42,6 +42,7 @@ Ip, Keyword, Long, + M, Mapping, MetaField, Nested, @@ -52,6 +53,8 @@ analyzer, mapped_field, ) +from elasticsearch.dsl.query import Match +from elasticsearch.dsl.types import MatchQuery from elasticsearch.dsl.utils import AttrList from elasticsearch.helpers.errors import BulkIndexError @@ -850,3 +853,51 @@ class Index: assert docs[0].float_vector == doc.float_vector assert docs[0].byte_vector == doc.byte_vector assert docs[0].bit_vector == doc.bit_vector + + +@pytest.mark.asyncio +async def test_copy_to(async_client: AsyncElasticsearch) -> None: + class Person(AsyncDocument): + first_name: M[str] = mapped_field(Text(copy_to=["full_name", "all"])) + last_name: M[str] = mapped_field(Text(copy_to=["full_name", "all"])) + birth_place: M[str] = mapped_field(Text(copy_to="all")) + full_name: M[Optional[str]] = mapped_field(init=False) + all: M[Optional[str]] = mapped_field(init=False) + + class Index: + name = "people" + + await Person._index.delete(ignore_unavailable=True) + await Person.init() + + person = Person(first_name="Jane", last_name="Doe", birth_place="Springfield") + await person.save() + await Person._index.refresh() + + match = ( + await Person.search() + .query(Match(Person.full_name, MatchQuery(query="Jane"))) + .execute() + ) + assert len(match) == 1 + + match = ( + await Person.search() + .query(Match(Person.all, MatchQuery(query="Doe"))) + .execute() + ) + assert len(match) == 1 + + match = ( + await Person.search() + .query(Match(Person.full_name, MatchQuery(query="Springfield"))) + .execute() + ) + assert len(match) == 0 + + match = ( + await Person.search() + .query(Match(Person.all, MatchQuery(query="Springfield"))) + .execute() + ) + assert len(match) == 1 diff --git a/test_elasticsearch/test_dsl/test_integration/_sync/test_document.py b/test_elasticsearch/test_dsl/test_integration/_sync/test_document.py index 13b60f71b..05dd05fd9 100644 --- a/test_elasticsearch/test_dsl/test_integration/_sync/test_document.py +++ b/test_elasticsearch/test_dsl/test_integration/_sync/test_document.py @@ -23,7 +23,7 @@ from datetime import datetime from ipaddress import ip_address -from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Tuple, Union +from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Union import pytest from pytest import raises @@ -41,6 +41,7 @@ Ip, Keyword, Long, + M, Mapping, MetaField, Nested, @@ -52,6 +53,8 @@ analyzer, mapped_field, ) +from elasticsearch.dsl.query import Match +from elasticsearch.dsl.types import MatchQuery from elasticsearch.dsl.utils import AttrList from elasticsearch.helpers.errors import BulkIndexError @@ -842,3 +845,47 @@ class Index: assert docs[0].float_vector == doc.float_vector assert docs[0].byte_vector == doc.byte_vector assert docs[0].bit_vector == doc.bit_vector + + +@pytest.mark.sync +def test_copy_to(client: Elasticsearch) -> None: + class Person(Document): + first_name: M[str] = mapped_field(Text(copy_to=["full_name", "all"])) + last_name: M[str] = mapped_field(Text(copy_to=["full_name", "all"])) + birth_place: M[str] = mapped_field(Text(copy_to="all")) + full_name: M[Optional[str]] = mapped_field(init=False) + all: M[Optional[str]] = mapped_field(init=False) + + class Index: + name = "people" + + Person._index.delete(ignore_unavailable=True) + Person.init() + + person = Person(first_name="Jane", last_name="Doe", birth_place="Springfield") + person.save() + Person._index.refresh() + + match = ( + Person.search() + .query(Match(Person.full_name, MatchQuery(query="Jane"))) + .execute() + ) + assert len(match) == 1 + + match = Person.search().query(Match(Person.all, MatchQuery(query="Doe"))).execute() + assert len(match) == 1 + + match = ( + Person.search() + .query(Match(Person.full_name, MatchQuery(query="Springfield"))) + .execute() + ) + assert len(match) == 0 + + match = ( + Person.search() + .query(Match(Person.all, MatchQuery(query="Springfield"))) + .execute() + ) + assert len(match) == 1 diff --git a/utils/templates/field.py.tpl b/utils/templates/field.py.tpl index 030060d23..8a4c73f33 100644 --- a/utils/templates/field.py.tpl +++ b/utils/templates/field.py.tpl @@ -245,7 +245,14 @@ class {{ k.name }}({{ k.parent }}): {% if not arg.positional %} if {{ arg.name }} is not DEFAULT: {% if "InstrumentedField" in arg.type %} + {% if "Sequence" in arg.type %} + if isinstance({{ arg.name }}, list): + kwargs["{{ arg.name }}"] = [str(field) for field in {{ arg.name }}] + else: + kwargs["{{ arg.name }}"] = str({{ arg.name }}) + {% else %} kwargs["{{ arg.name }}"] = str({{ arg.name }}) + {% endif %} {% else %} kwargs["{{ arg.name }}"] = {{ arg.name }} {% endif %}