diff --git a/10-indexing-records/README.md b/10-indexing-records/README.md index 1062e8b..9e25d44 100644 --- a/10-indexing-records/README.md +++ b/10-indexing-records/README.md @@ -2,7 +2,7 @@ The goal of this tutorial is to learn how to take advantage of Elasticsearch by manipulating records fields when indexing. -### Table of Contents +## Table of Contents - [Step 1: Bootstrap exercise](#step-1-bootstrap-exercise) - [Step 2: Modify the record before indexing](#step-2-modify-the-record-before-indexing) @@ -62,7 +62,7 @@ $ ./start-from.sh 09-deposit-form We are going to take advantage of the `invenio-indexer` signal [before_record_index](https://github.com/inveniosoftware/invenio-indexer/blob/master/invenio_indexer/signals.py) to modify the record fields before indexing. This signal [is called](https://github.com/inveniosoftware/invenio-indexer/blob/master/invenio_indexer/api.py#L305) every time and just before indexing a record. -Create a new file `indexer.py` and copy the following code: +If it doesn't exist, create a new file `indexer.py` and copy the following code: `my-site/my_site/records/indexer.py` @@ -100,7 +100,7 @@ def indexer_receiver( ``` -Now we need to register the signal in our Invenio instance. Change the `ext.py` to connect the signal. +Now we need to register the signal in our Invenio instance. We have to connect the signal with our indexer at `ext.py` in the `init_app` of our extension. `my-site/my_site/records/ext.py` @@ -122,7 +122,7 @@ from . import config Finally, let's change the Elasticsearch mappings to update the fields that we have changed. -`my-site/my_site/records/mappings/v6/records/record-v1.0.0.json` +`my-site/my_site/records/mappings/v7/records/record-v1.0.0.json` ```diff "id": { @@ -173,7 +173,7 @@ $ pipenv run invenio index reindex --pid-type recid --yes-i-know $ pipenv run invenio index run ``` -We can now create a new record, using the deposit of the previous exercise, and verify that in Elasticsearch we will can see the modified fields. +We can now create a new record, using the deposit of the previous exercise, and verify that in Elasticsearch we can see the modified fields. ```bash $ ./scripts/server diff --git a/10-indexing-records/solution/my-site/my_site/authors/mappings/__init__.py b/10-indexing-records/solution/my-site/my_site/authors/mappings/__init__.py index ac73b6f..292b154 100644 --- a/10-indexing-records/solution/my-site/my_site/authors/mappings/__init__.py +++ b/10-indexing-records/solution/my-site/my_site/authors/mappings/__init__.py @@ -12,5 +12,3 @@ in Elasticsearch. You need to provide one mapping per major version of Elasticsearch you want to support. """ - -from __future__ import absolute_import, print_function diff --git a/10-indexing-records/solution/my-site/my_site/authors/mappings/v6/authors/author-v1.0.0.json b/10-indexing-records/solution/my-site/my_site/authors/mappings/v6/authors/author-v1.0.0.json deleted file mode 100644 index e21f372..0000000 --- a/10-indexing-records/solution/my-site/my_site/authors/mappings/v6/authors/author-v1.0.0.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "mappings": { - "author-v1.0.0": { - "date_detection": false, - "numeric_detection": false, - "properties": { - "$schema": { - "type": "text", - "index": false - }, - "id": { - "type": "keyword" - }, - "name": { - "type": "text" - }, - "organization": { - "type": "text" - }, - "_created": { - "type": "date" - }, - "_updated": { - "type": "date" - } - } - } - } -} diff --git a/10-indexing-records/solution/my-site/my_site/authors/mappings/v6/__init__.py b/10-indexing-records/solution/my-site/my_site/authors/mappings/v7/__init__.py similarity index 67% rename from 10-indexing-records/solution/my-site/my_site/authors/mappings/v6/__init__.py rename to 10-indexing-records/solution/my-site/my_site/authors/mappings/v7/__init__.py index 018003d..5233dc2 100644 --- a/10-indexing-records/solution/my-site/my_site/authors/mappings/v6/__init__.py +++ b/10-indexing-records/solution/my-site/my_site/authors/mappings/v7/__init__.py @@ -5,6 +5,4 @@ # My site is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. -"""Mappings for Elasticsearch 5.x.""" - -from __future__ import absolute_import, print_function +"""Mappings for Elasticsearch 7.x.""" diff --git a/10-indexing-records/solution/my-site/my_site/authors/mappings/v7/authors/author-v1.0.0.json b/10-indexing-records/solution/my-site/my_site/authors/mappings/v7/authors/author-v1.0.0.json new file mode 100644 index 0000000..6912023 --- /dev/null +++ b/10-indexing-records/solution/my-site/my_site/authors/mappings/v7/authors/author-v1.0.0.json @@ -0,0 +1,27 @@ +{ + "mappings": { + "date_detection": false, + "numeric_detection": false, + "properties": { + "$schema": { + "type": "text", + "index": false + }, + "id": { + "type": "keyword" + }, + "name": { + "type": "text" + }, + "organization": { + "type": "text" + }, + "_created": { + "type": "date" + }, + "_updated": { + "type": "date" + } + } + } +} \ No newline at end of file diff --git a/10-indexing-records/solution/my-site/my_site/records/mappings/v6/records/record-v1.0.0.json b/10-indexing-records/solution/my-site/my_site/records/mappings/v6/records/record-v1.0.0.json deleted file mode 100644 index da3e2a6..0000000 --- a/10-indexing-records/solution/my-site/my_site/records/mappings/v6/records/record-v1.0.0.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "mappings": { - "record-v1.0.0": { - "date_detection": false, - "numeric_detection": false, - "properties": { - "$schema": { - "type": "text", - "index": false - }, - "title": { - "type": "text", - "copy_to": "suggest_title" - }, - "suggest_title": { - "type": "completion" - }, - "id": { - "type": "keyword" - }, - "owner": { - "type": "integer" - }, - "publication_date": { - "type": "date", - "format": "date" - }, - "contributors_count": { - "type": "short" - }, - "contributors": { - "type": "object", - "properties": { - "ids": { - "type": "object", - "properties": { - "source": { - "type": "text" - }, - "value": { - "type": "keyword" - } - } - }, - "affiliations": { - "type": "text" - }, - "role": { - "type": "keyword" - }, - "email": { - "type": "text" - }, - "name": { - "type": "text" - } - } - }, - "_created": { - "type": "date" - }, - "_updated": { - "type": "date" - } - } - } - } -} diff --git a/10-indexing-records/solution/my-site/my_site/records/mappings/v7/records/record-v1.0.0.json b/10-indexing-records/solution/my-site/my_site/records/mappings/v7/records/record-v1.0.0.json new file mode 100644 index 0000000..c183980 --- /dev/null +++ b/10-indexing-records/solution/my-site/my_site/records/mappings/v7/records/record-v1.0.0.json @@ -0,0 +1,66 @@ +{ + "mappings": { + "date_detection": false, + "numeric_detection": false, + "properties": { + "$schema": { + "type": "text", + "index": false + }, + "title": { + "type": "text", + "copy_to": "suggest_title" + }, + "suggest_title": { + "type": "completion" + }, + "id": { + "type": "keyword" + }, + "owner": { + "type": "integer" + }, + "publication_date": { + "type": "date", + "format": "date" + }, + "contributors_count": { + "type": "short" + }, + "contributors": { + "type": "object", + "properties": { + "ids": { + "type": "object", + "properties": { + "source": { + "type": "text" + }, + "value": { + "type": "keyword" + } + } + }, + "affiliations": { + "type": "text" + }, + "role": { + "type": "keyword" + }, + "email": { + "type": "text" + }, + "name": { + "type": "text" + } + } + }, + "_created": { + "type": "date" + }, + "_updated": { + "type": "date" + } + } + } +} \ No newline at end of file