Skip to content

ElasticSearch refresh parameter unused? #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ccancellieri opened this issue Nov 27, 2024 · 3 comments
Closed

ElasticSearch refresh parameter unused? #315

ccancellieri opened this issue Nov 27, 2024 · 3 comments

Comments

@ccancellieri
Copy link

ccancellieri commented Nov 27, 2024

Describe the bug
The pagination does not work properly after massive items upload over ElasticSearch as the number of items should still be calculated by ES (probably).
After a while the number is correct and the pagination starts to work.

I noticed that in the driver we have the support for the refresh parameter correctly exposed but it is never used by the stac-api as it is an abstraction layer while 'refresh' is something specific for ElasticSearch:

F.e.:

    async def delete_item(
        self, item_id: str, collection_id: str, refresh: bool = False
    ):
        """Delete a single item from the database.

        Args:
            item_id (str): The id of the Item to be deleted.
            collection_id (str): The id of the Collection that the Item belongs to.
            refresh (bool, optional): Whether to refresh the index after the deletion. Default is False.

        Raises:
            NotFoundError: If the Item does not exist in the database.
        """
        try:
            await self.client.delete(
                index=index_by_collection_id(collection_id),
                id=mk_item_id(item_id, collection_id),
                refresh=refresh,
            )
        except exceptions.NotFoundError:
            raise NotFoundError(
                f"Item {item_id} in collection {collection_id} not found"
            )

But from the stac-api refresh is never passed. Am I wrong?

Should we hardcode 'wait_for' or at least use the kwargs in some way?

@jonhealy1
Copy link
Collaborator

Hi @ccancellieri did you ever think of a good solution for this?

@jonhealy1
Copy link
Collaborator

In this pr, refresh can be passed via kwargs, or set globally for all transaction methods #370

jonhealy1 added a commit that referenced this issue May 10, 2025
… kwargs (#370)

**Related Issue(s):**

- #315 

**Description:**

- Introduced the `DATABASE_REFRESH` environment variable to control
whether database operations refresh the index immediately after changes.
If set to `true`, changes will be immediately searchable. If set to
`false`, changes may not be immediately visible but can improve
performance for bulk operations. If set to `wait_for`, changes will wait
for the next refresh cycle to become visible.
- Refactored CRUD methods in `TransactionsClient` to use the
`_resolve_refresh` helper method for consistent and reusable handling of
the `refresh` parameter.
- Fixed an issue where some routes were not passing the `refresh`
parameter from `kwargs` to the database logic, ensuring consistent
behavior across all CRUD operations.

**PR Checklist:**

- [x] Code is formatted and linted (run `pre-commit run --all-files`)
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable
- [x] Changes are added to the changelog
@jonhealy1
Copy link
Collaborator

reopen if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants