From 1671ffda874fd722962a6820663898f298551054 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 11 Nov 2024 17:08:22 +0000 Subject: [PATCH 1/4] support composable templates --- elasticsearch_dsl/__init__.py | 11 +++- elasticsearch_dsl/_async/index.py | 54 +++++++++++++++++++ elasticsearch_dsl/_sync/index.py | 50 +++++++++++++++++ elasticsearch_dsl/index.py | 8 ++- examples/alias_migration.py | 3 +- examples/async/alias_migration.py | 3 +- examples/async/parent_child.py | 2 +- examples/parent_child.py | 2 +- tests/conftest.py | 4 ++ tests/test_integration/_async/test_index.py | 25 ++++++++- tests/test_integration/_sync/test_index.py | 34 +++++++++++- .../_async/test_alias_migration.py | 2 +- .../test_examples/_async/test_parent_child.py | 2 +- .../_sync/test_alias_migration.py | 2 +- .../test_examples/_sync/test_parent_child.py | 2 +- utils/run-unasync.py | 1 + 16 files changed, 191 insertions(+), 14 deletions(-) diff --git a/elasticsearch_dsl/__init__.py b/elasticsearch_dsl/__init__.py index 31ba148f..7426d654 100644 --- a/elasticsearch_dsl/__init__.py +++ b/elasticsearch_dsl/__init__.py @@ -79,7 +79,14 @@ construct_field, ) from .function import SF -from .index import AsyncIndex, AsyncIndexTemplate, Index, IndexTemplate +from .index import ( + AsyncIndex, + AsyncIndexTemplate, + AsyncNewIndexTemplate, + Index, + IndexTemplate, + NewIndexTemplate, +) from .mapping import AsyncMapping, Mapping from .query import Q, Query from .response import AggResponse, Response, UpdateByQueryResponse @@ -109,6 +116,7 @@ "AsyncIndexTemplate", "AsyncMapping", "AsyncMultiSearch", + "AsyncNewIndexTemplate", "AsyncSearch", "AsyncUpdateByQuery", "AttrDict", @@ -158,6 +166,7 @@ "Murmur3", "Nested", "NestedFacet", + "NewIndexTemplate", "Object", "Percolator", "Q", diff --git a/elasticsearch_dsl/_async/index.py b/elasticsearch_dsl/_async/index.py index 765e7438..35fc0030 100644 --- a/elasticsearch_dsl/_async/index.py +++ b/elasticsearch_dsl/_async/index.py @@ -73,6 +73,47 @@ async def save( ) +class AsyncNewIndexTemplate: + def __init__( + self, + name: str, + template: str, + index: Optional["AsyncIndex"] = None, + priority: Optional[int] = None, + **kwargs: Any, + ): + if index is None: + self._index = AsyncIndex(template, **kwargs) + else: + if kwargs: + raise ValueError( + "You cannot specify options for Index when" + " passing an Index instance." + ) + self._index = index.clone() + self._index._name = template + self._template_name = name + self.priority = priority + + def __getattr__(self, attr_name: str) -> Any: + return getattr(self._index, attr_name) + + def to_dict(self) -> Dict[str, Any]: + d: Dict[str, Any] = {"template": self._index.to_dict()} + d["index_patterns"] = [self._index._name] + if self.priority is not None: + d["priority"] = self.priority + return d + + async def save( + self, using: Optional[AsyncUsingType] = None + ) -> "ObjectApiResponse[Any]": + es = get_connection(using or self._index._using) + return await es.indices.put_index_template( + name=self._template_name, **self.to_dict() + ) + + class AsyncIndex(IndexBase): _using: AsyncUsingType @@ -109,6 +150,19 @@ def as_template( template_name, pattern or self._name, index=self, order=order ) + def as_new_template( + self, + template_name: str, + pattern: Optional[str] = None, + priority: Optional[int] = None, + ) -> AsyncNewIndexTemplate: + # TODO: should we allow pattern to be a top-level arg? + # or maybe have an IndexPattern that allows for it and have + # Document._index be that? + return AsyncNewIndexTemplate( + template_name, pattern or self._name, index=self, priority=priority + ) + async def load_mappings(self, using: Optional[AsyncUsingType] = None) -> None: await self.get_or_create_mapping().update_from_es( self._name, using=using or self._using diff --git a/elasticsearch_dsl/_sync/index.py b/elasticsearch_dsl/_sync/index.py index 59508d51..a2193d04 100644 --- a/elasticsearch_dsl/_sync/index.py +++ b/elasticsearch_dsl/_sync/index.py @@ -69,6 +69,43 @@ def save(self, using: Optional[UsingType] = None) -> "ObjectApiResponse[Any]": return es.indices.put_template(name=self._template_name, body=self.to_dict()) +class NewIndexTemplate: + def __init__( + self, + name: str, + template: str, + index: Optional["Index"] = None, + priority: Optional[int] = None, + **kwargs: Any, + ): + if index is None: + self._index = Index(template, **kwargs) + else: + if kwargs: + raise ValueError( + "You cannot specify options for Index when" + " passing an Index instance." + ) + self._index = index.clone() + self._index._name = template + self._template_name = name + self.priority = priority + + def __getattr__(self, attr_name: str) -> Any: + return getattr(self._index, attr_name) + + def to_dict(self) -> Dict[str, Any]: + d: Dict[str, Any] = {"template": self._index.to_dict()} + d["index_patterns"] = [self._index._name] + if self.priority is not None: + d["priority"] = self.priority + return d + + def save(self, using: Optional[UsingType] = None) -> "ObjectApiResponse[Any]": + es = get_connection(using or self._index._using) + return es.indices.put_index_template(name=self._template_name, **self.to_dict()) + + class Index(IndexBase): _using: UsingType @@ -103,6 +140,19 @@ def as_template( template_name, pattern or self._name, index=self, order=order ) + def as_new_template( + self, + template_name: str, + pattern: Optional[str] = None, + priority: Optional[int] = None, + ) -> NewIndexTemplate: + # TODO: should we allow pattern to be a top-level arg? + # or maybe have an IndexPattern that allows for it and have + # Document._index be that? + return NewIndexTemplate( + template_name, pattern or self._name, index=self, priority=priority + ) + def load_mappings(self, using: Optional[UsingType] = None) -> None: self.get_or_create_mapping().update_from_es( self._name, using=using or self._using diff --git a/elasticsearch_dsl/index.py b/elasticsearch_dsl/index.py index ef9f4b0b..f840e4b2 100644 --- a/elasticsearch_dsl/index.py +++ b/elasticsearch_dsl/index.py @@ -15,5 +15,9 @@ # specific language governing permissions and limitations # under the License. -from ._async.index import AsyncIndex, AsyncIndexTemplate # noqa: F401 -from ._sync.index import Index, IndexTemplate # noqa: F401 +from ._async.index import ( # noqa: F401 + AsyncIndex, + AsyncIndexTemplate, + AsyncNewIndexTemplate, +) +from ._sync.index import Index, IndexTemplate, NewIndexTemplate # noqa: F401 diff --git a/examples/alias_migration.py b/examples/alias_migration.py index c9fe4ede..b8cb906a 100644 --- a/examples/alias_migration.py +++ b/examples/alias_migration.py @@ -44,6 +44,7 @@ ALIAS = "test-blog" PATTERN = ALIAS + "-*" +PRIORITY = 100 class BlogPost(Document): @@ -81,7 +82,7 @@ def setup() -> None: deploy. """ # create an index template - index_template = BlogPost._index.as_template(ALIAS, PATTERN) + index_template = BlogPost._index.as_new_template(ALIAS, PATTERN, priority=PRIORITY) # upload the template into elasticsearch # potentially overriding the one already there index_template.save() diff --git a/examples/async/alias_migration.py b/examples/async/alias_migration.py index bede9098..9e01368b 100644 --- a/examples/async/alias_migration.py +++ b/examples/async/alias_migration.py @@ -45,6 +45,7 @@ ALIAS = "test-blog" PATTERN = ALIAS + "-*" +PRIORITY = 100 class BlogPost(AsyncDocument): @@ -82,7 +83,7 @@ async def setup() -> None: deploy. """ # create an index template - index_template = BlogPost._index.as_template(ALIAS, PATTERN) + index_template = BlogPost._index.as_new_template(ALIAS, PATTERN, priority=PRIORITY) # upload the template into elasticsearch # potentially overriding the one already there await index_template.save() diff --git a/examples/async/parent_child.py b/examples/async/parent_child.py index 6668a77c..70fc2325 100644 --- a/examples/async/parent_child.py +++ b/examples/async/parent_child.py @@ -226,7 +226,7 @@ async def save(self, **kwargs: Any) -> None: # type: ignore[override] async def setup() -> None: """Create an IndexTemplate and save it into elasticsearch.""" - index_template = Post._index.as_template("base") + index_template = Post._index.as_new_template("base", priority=100) await index_template.save() diff --git a/examples/parent_child.py b/examples/parent_child.py index 5acbbd72..335205a4 100644 --- a/examples/parent_child.py +++ b/examples/parent_child.py @@ -225,7 +225,7 @@ def save(self, **kwargs: Any) -> None: # type: ignore[override] def setup() -> None: """Create an IndexTemplate and save it into elasticsearch.""" - index_template = Post._index.as_template("base") + index_template = Post._index.as_new_template("base", priority=100) index_template.save() diff --git a/tests/conftest.py b/tests/conftest.py index 1a07670e..6a2589b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -122,6 +122,7 @@ def teardown_method(self, _: Any) -> None: ) self.client.indices.delete(index="*", expand_wildcards=expand_wildcards) self.client.indices.delete_template(name="*") + self.client.indices.delete_index_template(name="*") def es_version(self) -> Tuple[int, ...]: if not hasattr(self, "_es_version"): @@ -172,6 +173,9 @@ def write_client(client: Elasticsearch) -> Generator[Elasticsearch, None, None]: for index_name in client.indices.get(index="test-*", expand_wildcards="all"): client.indices.delete(index=index_name) client.options(ignore_status=404).indices.delete_template(name="test-template") + client.options(ignore_status=404).indices.delete_index_template( + name="test-template" + ) @pytest_asyncio.fixture diff --git a/tests/test_integration/_async/test_index.py b/tests/test_integration/_async/test_index.py index 21e4fa7c..e2f19252 100644 --- a/tests/test_integration/_async/test_index.py +++ b/tests/test_integration/_async/test_index.py @@ -22,6 +22,7 @@ AsyncDocument, AsyncIndex, AsyncIndexTemplate, + AsyncNewIndexTemplate, Date, Text, analysis, @@ -35,7 +36,29 @@ class Post(AsyncDocument): @pytest.mark.asyncio async def test_index_template_works(async_write_client: AsyncElasticsearch) -> None: - it = AsyncIndexTemplate("test-template", "test-*") + it = AsyncIndexTemplate("test-template", "test-legacy-*") + it.document(Post) + it.settings(number_of_replicas=0, number_of_shards=1) + await it.save() + + i = AsyncIndex("test-legacy-blog") + await i.create() + + assert { + "test-legacy-blog": { + "mappings": { + "properties": { + "title": {"type": "text", "analyzer": "my_analyzer"}, + "published_from": {"type": "date"}, + } + } + } + } == await async_write_client.indices.get_mapping(index="test-legacy-blog") + + +@pytest.mark.asyncio +async def test_new_index_template_works(async_write_client: AsyncElasticsearch) -> None: + it = AsyncNewIndexTemplate("test-template", "test-*") it.document(Post) it.settings(number_of_replicas=0, number_of_shards=1) await it.save() diff --git a/tests/test_integration/_sync/test_index.py b/tests/test_integration/_sync/test_index.py index ff435bdf..277faa2c 100644 --- a/tests/test_integration/_sync/test_index.py +++ b/tests/test_integration/_sync/test_index.py @@ -18,7 +18,15 @@ import pytest from elasticsearch import Elasticsearch -from elasticsearch_dsl import Date, Document, Index, IndexTemplate, Text, analysis +from elasticsearch_dsl import ( + Date, + Document, + Index, + IndexTemplate, + NewIndexTemplate, + Text, + analysis, +) class Post(Document): @@ -28,7 +36,29 @@ class Post(Document): @pytest.mark.sync def test_index_template_works(write_client: Elasticsearch) -> None: - it = IndexTemplate("test-template", "test-*") + it = IndexTemplate("test-template", "test-legacy-*") + it.document(Post) + it.settings(number_of_replicas=0, number_of_shards=1) + it.save() + + i = Index("test-legacy-blog") + i.create() + + assert { + "test-legacy-blog": { + "mappings": { + "properties": { + "title": {"type": "text", "analyzer": "my_analyzer"}, + "published_from": {"type": "date"}, + } + } + } + } == write_client.indices.get_mapping(index="test-legacy-blog") + + +@pytest.mark.sync +def test_new_index_template_works(write_client: Elasticsearch) -> None: + it = NewIndexTemplate("test-template", "test-*") it.document(Post) it.settings(number_of_replicas=0, number_of_shards=1) it.save() diff --git a/tests/test_integration/test_examples/_async/test_alias_migration.py b/tests/test_integration/test_examples/_async/test_alias_migration.py index 81202706..dae4c973 100644 --- a/tests/test_integration/test_examples/_async/test_alias_migration.py +++ b/tests/test_integration/test_examples/_async/test_alias_migration.py @@ -28,7 +28,7 @@ async def test_alias_migration(async_write_client: AsyncElasticsearch) -> None: await alias_migration.setup() # verify that template, index, and alias has been set up - assert await async_write_client.indices.exists_template(name=ALIAS) + assert await async_write_client.indices.exists_index_template(name=ALIAS) assert await async_write_client.indices.exists(index=PATTERN) assert await async_write_client.indices.exists_alias(name=ALIAS) diff --git a/tests/test_integration/test_examples/_async/test_parent_child.py b/tests/test_integration/test_examples/_async/test_parent_child.py index 9a1027f4..b12d445f 100644 --- a/tests/test_integration/test_examples/_async/test_parent_child.py +++ b/tests/test_integration/test_examples/_async/test_parent_child.py @@ -45,7 +45,7 @@ @pytest_asyncio.fixture async def question(async_write_client: AsyncElasticsearch) -> Question: await setup() - assert await async_write_client.indices.exists_template(name="base") + assert await async_write_client.indices.exists_index_template(name="base") # create a question object q = Question( diff --git a/tests/test_integration/test_examples/_sync/test_alias_migration.py b/tests/test_integration/test_examples/_sync/test_alias_migration.py index 59cdb372..9a74b699 100644 --- a/tests/test_integration/test_examples/_sync/test_alias_migration.py +++ b/tests/test_integration/test_examples/_sync/test_alias_migration.py @@ -28,7 +28,7 @@ def test_alias_migration(write_client: Elasticsearch) -> None: alias_migration.setup() # verify that template, index, and alias has been set up - assert write_client.indices.exists_template(name=ALIAS) + assert write_client.indices.exists_index_template(name=ALIAS) assert write_client.indices.exists(index=PATTERN) assert write_client.indices.exists_alias(name=ALIAS) diff --git a/tests/test_integration/test_examples/_sync/test_parent_child.py b/tests/test_integration/test_examples/_sync/test_parent_child.py index dcbbde86..12d93914 100644 --- a/tests/test_integration/test_examples/_sync/test_parent_child.py +++ b/tests/test_integration/test_examples/_sync/test_parent_child.py @@ -44,7 +44,7 @@ @pytest.fixture def question(write_client: Elasticsearch) -> Question: setup() - assert write_client.indices.exists_template(name="base") + assert write_client.indices.exists_index_template(name="base") # create a question object q = Question( diff --git a/utils/run-unasync.py b/utils/run-unasync.py index bae0c7a6..27d1f04b 100644 --- a/utils/run-unasync.py +++ b/utils/run-unasync.py @@ -57,6 +57,7 @@ def main(check=False): "AsyncIndexMeta": "IndexMeta", "AsyncIndexTemplate": "IndexTemplate", "AsyncIndex": "Index", + "AsyncNewIndexTemplate": "NewIndexTemplate", "AsyncUpdateByQuery": "UpdateByQuery", "AsyncMapping": "Mapping", "AsyncFacetedSearch": "FacetedSearch", From 5d5b68f39d2c628b664e05441fb7a631a9cf2660 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 20 Nov 2024 10:39:33 +0000 Subject: [PATCH 2/4] do not error on aiohttp warning --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index fc099da6..dab811f9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,5 +11,6 @@ filterwarnings = error ignore:Legacy index templates are deprecated in favor of composable templates.:elasticsearch.exceptions.ElasticsearchWarning ignore:datetime.datetime.utcfromtimestamp\(\) is deprecated and scheduled for removal in a future version..*:DeprecationWarning + default:enable_cleanup_closed ignored.*:DeprecationWarning markers = sync: mark a test as performing I/O without asyncio. From d177fa398576c16e5d28fa93766fc26538190d75 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 9 Dec 2024 15:51:59 +0000 Subject: [PATCH 3/4] rename new index template to composable index template --- .gitignore | 2 ++ elasticsearch_dsl/__init__.py | 8 ++++---- elasticsearch_dsl/_async/index.py | 8 ++++---- elasticsearch_dsl/_sync/index.py | 8 ++++---- elasticsearch_dsl/index.py | 4 ++-- examples/alias_migration.py | 4 +++- examples/async/alias_migration.py | 4 +++- examples/async/parent_child.py | 2 +- examples/parent_child.py | 2 +- tests/test_integration/_async/test_index.py | 8 +++++--- tests/test_integration/_sync/test_index.py | 8 +++++--- utils/run-unasync.py | 2 +- 12 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index ebf415e9..d857636f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ venv # sample code for GitHub issues issues +.direnv +.envrc diff --git a/elasticsearch_dsl/__init__.py b/elasticsearch_dsl/__init__.py index 7426d654..55ca065e 100644 --- a/elasticsearch_dsl/__init__.py +++ b/elasticsearch_dsl/__init__.py @@ -80,12 +80,12 @@ ) from .function import SF from .index import ( + AsyncComposableIndexTemplate, AsyncIndex, AsyncIndexTemplate, - AsyncNewIndexTemplate, + ComposableIndexTemplate, Index, IndexTemplate, - NewIndexTemplate, ) from .mapping import AsyncMapping, Mapping from .query import Q, Query @@ -109,6 +109,7 @@ "A", "Agg", "AggResponse", + "AsyncComposableIndexTemplate", "AsyncDocument", "AsyncEmptySearch", "AsyncFacetedSearch", @@ -116,7 +117,6 @@ "AsyncIndexTemplate", "AsyncMapping", "AsyncMultiSearch", - "AsyncNewIndexTemplate", "AsyncSearch", "AsyncUpdateByQuery", "AttrDict", @@ -125,6 +125,7 @@ "Boolean", "Byte", "Completion", + "ComposableIndexTemplate", "ConstantKeyword", "CustomField", "Date", @@ -166,7 +167,6 @@ "Murmur3", "Nested", "NestedFacet", - "NewIndexTemplate", "Object", "Percolator", "Q", diff --git a/elasticsearch_dsl/_async/index.py b/elasticsearch_dsl/_async/index.py index 35fc0030..a96a7fa4 100644 --- a/elasticsearch_dsl/_async/index.py +++ b/elasticsearch_dsl/_async/index.py @@ -73,7 +73,7 @@ async def save( ) -class AsyncNewIndexTemplate: +class AsyncComposableIndexTemplate: def __init__( self, name: str, @@ -150,16 +150,16 @@ def as_template( template_name, pattern or self._name, index=self, order=order ) - def as_new_template( + def as_composable_template( self, template_name: str, pattern: Optional[str] = None, priority: Optional[int] = None, - ) -> AsyncNewIndexTemplate: + ) -> AsyncComposableIndexTemplate: # TODO: should we allow pattern to be a top-level arg? # or maybe have an IndexPattern that allows for it and have # Document._index be that? - return AsyncNewIndexTemplate( + return AsyncComposableIndexTemplate( template_name, pattern or self._name, index=self, priority=priority ) diff --git a/elasticsearch_dsl/_sync/index.py b/elasticsearch_dsl/_sync/index.py index a2193d04..4a63cc13 100644 --- a/elasticsearch_dsl/_sync/index.py +++ b/elasticsearch_dsl/_sync/index.py @@ -69,7 +69,7 @@ def save(self, using: Optional[UsingType] = None) -> "ObjectApiResponse[Any]": return es.indices.put_template(name=self._template_name, body=self.to_dict()) -class NewIndexTemplate: +class ComposableIndexTemplate: def __init__( self, name: str, @@ -140,16 +140,16 @@ def as_template( template_name, pattern or self._name, index=self, order=order ) - def as_new_template( + def as_composable_template( self, template_name: str, pattern: Optional[str] = None, priority: Optional[int] = None, - ) -> NewIndexTemplate: + ) -> ComposableIndexTemplate: # TODO: should we allow pattern to be a top-level arg? # or maybe have an IndexPattern that allows for it and have # Document._index be that? - return NewIndexTemplate( + return ComposableIndexTemplate( template_name, pattern or self._name, index=self, priority=priority ) diff --git a/elasticsearch_dsl/index.py b/elasticsearch_dsl/index.py index f840e4b2..368e58d4 100644 --- a/elasticsearch_dsl/index.py +++ b/elasticsearch_dsl/index.py @@ -16,8 +16,8 @@ # under the License. from ._async.index import ( # noqa: F401 + AsyncComposableIndexTemplate, AsyncIndex, AsyncIndexTemplate, - AsyncNewIndexTemplate, ) -from ._sync.index import Index, IndexTemplate, NewIndexTemplate # noqa: F401 +from ._sync.index import ComposableIndexTemplate, Index, IndexTemplate # noqa: F401 diff --git a/examples/alias_migration.py b/examples/alias_migration.py index b8cb906a..ba1204a9 100644 --- a/examples/alias_migration.py +++ b/examples/alias_migration.py @@ -82,7 +82,9 @@ def setup() -> None: deploy. """ # create an index template - index_template = BlogPost._index.as_new_template(ALIAS, PATTERN, priority=PRIORITY) + index_template = BlogPost._index.as_composable_template( + ALIAS, PATTERN, priority=PRIORITY + ) # upload the template into elasticsearch # potentially overriding the one already there index_template.save() diff --git a/examples/async/alias_migration.py b/examples/async/alias_migration.py index 9e01368b..2f9dbf73 100644 --- a/examples/async/alias_migration.py +++ b/examples/async/alias_migration.py @@ -83,7 +83,9 @@ async def setup() -> None: deploy. """ # create an index template - index_template = BlogPost._index.as_new_template(ALIAS, PATTERN, priority=PRIORITY) + index_template = BlogPost._index.as_composable_template( + ALIAS, PATTERN, priority=PRIORITY + ) # upload the template into elasticsearch # potentially overriding the one already there await index_template.save() diff --git a/examples/async/parent_child.py b/examples/async/parent_child.py index 70fc2325..c96455ed 100644 --- a/examples/async/parent_child.py +++ b/examples/async/parent_child.py @@ -226,7 +226,7 @@ async def save(self, **kwargs: Any) -> None: # type: ignore[override] async def setup() -> None: """Create an IndexTemplate and save it into elasticsearch.""" - index_template = Post._index.as_new_template("base", priority=100) + index_template = Post._index.as_composable_template("base", priority=100) await index_template.save() diff --git a/examples/parent_child.py b/examples/parent_child.py index 335205a4..09b03adb 100644 --- a/examples/parent_child.py +++ b/examples/parent_child.py @@ -225,7 +225,7 @@ def save(self, **kwargs: Any) -> None: # type: ignore[override] def setup() -> None: """Create an IndexTemplate and save it into elasticsearch.""" - index_template = Post._index.as_new_template("base", priority=100) + index_template = Post._index.as_composable_template("base", priority=100) index_template.save() diff --git a/tests/test_integration/_async/test_index.py b/tests/test_integration/_async/test_index.py index e2f19252..db570cc7 100644 --- a/tests/test_integration/_async/test_index.py +++ b/tests/test_integration/_async/test_index.py @@ -19,10 +19,10 @@ from elasticsearch import AsyncElasticsearch from elasticsearch_dsl import ( + AsyncComposableIndexTemplate, AsyncDocument, AsyncIndex, AsyncIndexTemplate, - AsyncNewIndexTemplate, Date, Text, analysis, @@ -57,8 +57,10 @@ async def test_index_template_works(async_write_client: AsyncElasticsearch) -> N @pytest.mark.asyncio -async def test_new_index_template_works(async_write_client: AsyncElasticsearch) -> None: - it = AsyncNewIndexTemplate("test-template", "test-*") +async def test_composable_index_template_works( + async_write_client: AsyncElasticsearch, +) -> None: + it = AsyncComposableIndexTemplate("test-template", "test-*") it.document(Post) it.settings(number_of_replicas=0, number_of_shards=1) await it.save() diff --git a/tests/test_integration/_sync/test_index.py b/tests/test_integration/_sync/test_index.py index 277faa2c..9f8da73e 100644 --- a/tests/test_integration/_sync/test_index.py +++ b/tests/test_integration/_sync/test_index.py @@ -19,11 +19,11 @@ from elasticsearch import Elasticsearch from elasticsearch_dsl import ( + ComposableIndexTemplate, Date, Document, Index, IndexTemplate, - NewIndexTemplate, Text, analysis, ) @@ -57,8 +57,10 @@ def test_index_template_works(write_client: Elasticsearch) -> None: @pytest.mark.sync -def test_new_index_template_works(write_client: Elasticsearch) -> None: - it = NewIndexTemplate("test-template", "test-*") +def test_composable_index_template_works( + write_client: Elasticsearch, +) -> None: + it = ComposableIndexTemplate("test-template", "test-*") it.document(Post) it.settings(number_of_replicas=0, number_of_shards=1) it.save() diff --git a/utils/run-unasync.py b/utils/run-unasync.py index 27d1f04b..7a55e7b5 100644 --- a/utils/run-unasync.py +++ b/utils/run-unasync.py @@ -57,7 +57,7 @@ def main(check=False): "AsyncIndexMeta": "IndexMeta", "AsyncIndexTemplate": "IndexTemplate", "AsyncIndex": "Index", - "AsyncNewIndexTemplate": "NewIndexTemplate", + "AsyncComposableIndexTemplate": "ComposableIndexTemplate", "AsyncUpdateByQuery": "UpdateByQuery", "AsyncMapping": "Mapping", "AsyncFacetedSearch": "FacetedSearch", From 6e2bd0c75db1fecb25dd6ddf20c0951577143922 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 10 Dec 2024 16:14:43 +0000 Subject: [PATCH 4/4] remove old comment --- elasticsearch_dsl/_async/index.py | 6 ------ elasticsearch_dsl/_sync/index.py | 6 ------ 2 files changed, 12 deletions(-) diff --git a/elasticsearch_dsl/_async/index.py b/elasticsearch_dsl/_async/index.py index a96a7fa4..22da1b14 100644 --- a/elasticsearch_dsl/_async/index.py +++ b/elasticsearch_dsl/_async/index.py @@ -143,9 +143,6 @@ def as_template( pattern: Optional[str] = None, order: Optional[int] = None, ) -> AsyncIndexTemplate: - # TODO: should we allow pattern to be a top-level arg? - # or maybe have an IndexPattern that allows for it and have - # Document._index be that? return AsyncIndexTemplate( template_name, pattern or self._name, index=self, order=order ) @@ -156,9 +153,6 @@ def as_composable_template( pattern: Optional[str] = None, priority: Optional[int] = None, ) -> AsyncComposableIndexTemplate: - # TODO: should we allow pattern to be a top-level arg? - # or maybe have an IndexPattern that allows for it and have - # Document._index be that? return AsyncComposableIndexTemplate( template_name, pattern or self._name, index=self, priority=priority ) diff --git a/elasticsearch_dsl/_sync/index.py b/elasticsearch_dsl/_sync/index.py index 4a63cc13..3b562a67 100644 --- a/elasticsearch_dsl/_sync/index.py +++ b/elasticsearch_dsl/_sync/index.py @@ -133,9 +133,6 @@ def as_template( pattern: Optional[str] = None, order: Optional[int] = None, ) -> IndexTemplate: - # TODO: should we allow pattern to be a top-level arg? - # or maybe have an IndexPattern that allows for it and have - # Document._index be that? return IndexTemplate( template_name, pattern or self._name, index=self, order=order ) @@ -146,9 +143,6 @@ def as_composable_template( pattern: Optional[str] = None, priority: Optional[int] = None, ) -> ComposableIndexTemplate: - # TODO: should we allow pattern to be a top-level arg? - # or maybe have an IndexPattern that allows for it and have - # Document._index be that? return ComposableIndexTemplate( template_name, pattern or self._name, index=self, priority=priority )