Skip to content
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

indexer: update mapping #70

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions rero_mef/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from invenio_oaiharvester.cli import oaiharvester
from invenio_oaiharvester.models import OAIHarvestConfig
from invenio_records_rest.utils import obj_or_import_string
from invenio_search.cli import es_version_check
from invenio_search.proxies import current_search, current_search_client
from sqlitedict import SqliteDict
from werkzeug.local import LocalProxy

Expand Down Expand Up @@ -902,6 +904,28 @@ def reindex(pid_type, no_info):
)


@utils.command('update_mapping')
@click.option('--aliases', '-a', multiple=True, help='all if not specified')
@with_appcontext
@es_version_check
def update_mapping(aliases):
"""Update the mapping of a given alias."""
if not aliases:
aliases = current_search.aliases.keys()
for alias in aliases:
for index, f_mapping in iter(
current_search.aliases.get(alias).items()
):
mapping = json.load(open(f_mapping))
res = current_search_client.indices.put_mapping(
mapping.get('mappings'), index)
if res.get('acknowledged'):
click.secho(
f'index: {index} has been sucessfully updated', fg='green')
else:
click.secho(f'error: {res}', fg='red')


def queue_count():
"""Count tasks in celery."""
inspector = inspect()
Expand Down