@@ -0,0 +1,2706 @@
+# -*- coding: utf-8 -*-%0A%22%22%22Update Elasticsearch mappings for Archivematica 1.12%0A%0AThis command updates the Elasticsearch mappings for the aips and%0Aaipfiles indices for Archivematica 1.12 to enable sorting on all fields%0Adisplayed in the new Archival Storage DataTable and populates the new%0AfilePath.raw subfield in the aipfiles index using an Update By Query.%0A%0AExecution example:%0A%0A./manage.py update_elasticsearch_mappings%0A%22%22%22%0Afrom __future__ import absolute_import, print_function%0A%0Aimport sys%0A%0Afrom django.conf import settings%0Afrom elasticsearch import ElasticsearchException%0A%0Afrom main.management.commands import DashboardCommand%0Aimport elasticSearchFunctions as es%0A%0A%0Aclass Command(DashboardCommand):%0A%0A    help = __doc__%0A%0A    def handle(self, *args, **options):%0A        # Check that the AIPs index is enabled before proceeding.%0A        if es.AIPS_INDEX not in settings.SEARCH_ENABLED:%0A            self.error(%0A                %22The AIPs indexes are not enabled. Please, make sure to %22%0A                %22set the *_SEARCH_ENABLED environment variables to %60true%60 %22%0A                %22to enable the AIPs and Transfers indexes, or to %60aips%60 %22%0A                %22to only enable the AIPs indexes.%22%0A            )%0A            sys.exit(1)%0A%0A        try:%0A            es.setup_reading_from_conf(settings)%0A            es_client = es.get_client()%0A        except ElasticsearchException:%0A            self.error(%22Error: Elasticsearch may not be running.%22)%0A            sys.exit(1)%0A%0A        # Update the AIPs index mappings.%0A        es_client.indices.put_mapping(%0A            index=es.AIPS_INDEX,%0A            doc_type=es.DOC_TYPE,%0A            body=%7B%0A                %22properties%22: %7B%0A                    %22accessionids%22: %7B%22type%22: %22keyword%22%7D,%0A                    %22status%22: %7B%22type%22: %22keyword%22%7D,%0A                    %22file_count%22: %7B%22type%22: %22integer%22%7D,%0A                %7D%0A            %7D,%0A        )%0A%0A        # Update the AIP files index mapping.%0A        es_client.indices.put_mapping(%0A            index=es.AIP_FILES_INDEX,%0A            doc_type=es.DOC_TYPE,%0A            body=%7B%0A                %22properties%22: %7B%0A                    %22accessionid%22: %7B%22type%22: %22keyword%22%7D,%0A                    %22status%22: %7B%22type%22: %22keyword%22%7D,%0A                    %22filePath%22: %7B%0A                        %22type%22: %22text%22,%0A                        %22analyzer%22: %22file_path_and_name%22,%0A                        %22fields%22: %7B%22raw%22: %7B%22type%22: %22keyword%22%7D%7D,%0A                    %7D,%0A                %7D%0A            %7D,%0A        )%0A%0A        # Perform an update by query on the aipfiles index to populate%0A        # the filePath.raw subfield from existing text values. We do%0A        # not specify a query to ensure that all documents are updated.%0A        es_client.update_by_query(es.AIP_FILES_INDEX)%0A

Add management command to update ES mappings