Skip to content

Commit

Permalink
rename new index template to composable index template
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Dec 9, 2024
1 parent 5d5b68f commit d177fa3
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ venv

# sample code for GitHub issues
issues
.direnv
.envrc
8 changes: 4 additions & 4 deletions elasticsearch_dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -109,14 +109,14 @@
"A",
"Agg",
"AggResponse",
"AsyncComposableIndexTemplate",
"AsyncDocument",
"AsyncEmptySearch",
"AsyncFacetedSearch",
"AsyncIndex",
"AsyncIndexTemplate",
"AsyncMapping",
"AsyncMultiSearch",
"AsyncNewIndexTemplate",
"AsyncSearch",
"AsyncUpdateByQuery",
"AttrDict",
Expand All @@ -125,6 +125,7 @@
"Boolean",
"Byte",
"Completion",
"ComposableIndexTemplate",
"ConstantKeyword",
"CustomField",
"Date",
Expand Down Expand Up @@ -166,7 +167,6 @@
"Murmur3",
"Nested",
"NestedFacet",
"NewIndexTemplate",
"Object",
"Percolator",
"Q",
Expand Down
8 changes: 4 additions & 4 deletions elasticsearch_dsl/_async/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def save(
)


class AsyncNewIndexTemplate:
class AsyncComposableIndexTemplate:
def __init__(
self,
name: str,
Expand Down Expand Up @@ -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
)

Expand Down
8 changes: 4 additions & 4 deletions elasticsearch_dsl/_sync/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch_dsl/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion examples/alias_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion examples/async/alias_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/async/parent_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion examples/parent_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
8 changes: 5 additions & 3 deletions tests/test_integration/_async/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from elasticsearch import AsyncElasticsearch

from elasticsearch_dsl import (
AsyncComposableIndexTemplate,
AsyncDocument,
AsyncIndex,
AsyncIndexTemplate,
AsyncNewIndexTemplate,
Date,
Text,
analysis,
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions tests/test_integration/_sync/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from elasticsearch import Elasticsearch

from elasticsearch_dsl import (
ComposableIndexTemplate,
Date,
Document,
Index,
IndexTemplate,
NewIndexTemplate,
Text,
analysis,
)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion utils/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main(check=False):
"AsyncIndexMeta": "IndexMeta",
"AsyncIndexTemplate": "IndexTemplate",
"AsyncIndex": "Index",
"AsyncNewIndexTemplate": "NewIndexTemplate",
"AsyncComposableIndexTemplate": "ComposableIndexTemplate",
"AsyncUpdateByQuery": "UpdateByQuery",
"AsyncMapping": "Mapping",
"AsyncFacetedSearch": "FacetedSearch",
Expand Down

0 comments on commit d177fa3

Please sign in to comment.