Skip to content

Commit

Permalink
recid
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz committed Oct 5, 2023
1 parent 07ba24b commit 7b5fb53
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions invenio_stats/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import click
from dateutil.parser import parse as dateutil_parse
from datetime import datetime
from flask import current_app
from flask.cli import with_appcontext
from invenio_search.engine import search
Expand Down Expand Up @@ -174,6 +175,22 @@ def _aggregations_list_bookmarks(
def _migrate():
"""Migrate the statistics from zenodo."""
print("Checking if there are any `legacy` indices")
my_date = datetime.utcnow().isoformat()
painless = f'ctx._source.parent_recid=ctx._source.conceptrecid;ctx._source.updated_timestamp="{my_date}"'
# Removing obsolete fields
for f in [
"conceptdoi",
"resource_type",
"access_right",
"bucket_id",
"file_key",
"referrer",
"size",
"file_id",
"conceprecid",
"doi",
]:
painless += f'ctx,_source.remove("{f}")'
legacy_indices = current_search_client.cat.indices("legacy*", format="json")
i = 0
total = len(legacy_indices)
Expand All @@ -193,11 +210,12 @@ def _migrate():
try:
current_search_client.reindex(
{
"conflicts": "proceed",
"source": {"index": my_index["index"]},
"dest": {"index": target},
"dest": {"index": target, "op_type": "create"},
"script": {
"lang": "painless",
"source": 'ctx._source.remove("conceptdoi");ctx._source.remove( "resource_type");ctx._source.remove("access_right");ctx._source.remove("bucket_id");ctx._source.remove("file_key");ctx._source.remove("referrer");ctx._source.remove("size");ctx._source.remove("file_id");ctx._source.remove("conceptrecid");ctx._source.remove("recid");ctx._source.remove("doi")',
"source": painless,
},
}
)
Expand Down

0 comments on commit 7b5fb53

Please sign in to comment.