From 1849f0d54a16432eda2471fda5a602a26d5a5740 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 28 Feb 2018 14:04:46 +0000 Subject: [PATCH] Pass index name in URL to Bulk API We currently index all items in Elasticsearch using the root bulk api (at ``/_bulk``). This API is to allow multiple indices to be inserted into at once. However, Wagtail inserts into one index at a time so this is not needed. If we pass the index name as a parameter in the call to ``bulk()``, the index-specific bulk API will be used instead (at ``//_bulk``. The advantage of this change is it makes it possible to implement access control by checking the URL an application is using. This is required in order for the Bulk API to work on certain hosts (such as Divio). --- CHANGELOG.txt | 1 + docs/releases/2.1.rst | 1 + wagtail/search/backends/elasticsearch2.py | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d8c32ae5b..606656aca 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -57,6 +57,7 @@ Changelog * Fix: Restored ability to use non-model fields with FieldPanel (Matt Westcott, LB (Ben Johnston)) * Fix: Stop revision comparison view from crashing when non-model FieldPanels are in use (LB (Ben Johnston)) * Fix: Ordering in the page explorer now respects custom `get_admin_display_title` methods when sorting <100 pages (Matt Westcott) + * Fix: Use index-specific Elasticsearch endpoints for bulk insertion, for compatibility with providers that lock down the root endpoint (Karl Hobley) 2.0.2 (xx.xx.xxxx) - IN DEVELOPMENT diff --git a/docs/releases/2.1.rst b/docs/releases/2.1.rst index 467902333..87a962701 100644 --- a/docs/releases/2.1.rst +++ b/docs/releases/2.1.rst @@ -86,6 +86,7 @@ Bug fixes * Restored ability to use non-model fields with FieldPanel (Matt Westcott, LB (Ben Johnston)) * Stop revision comparison view from crashing when non-model FieldPanels are in use (LB (Ben Johnston)) * Ordering in the page explorer now respects custom ``get_admin_display_title`` methods when sorting <100 pages (Matt Westcott) + * Use index-specific Elasticsearch endpoints for bulk insertion, for compatibility with providers that lock down the root endpoint (Karl Hobley) Upgrade considerations diff --git a/wagtail/search/backends/elasticsearch2.py b/wagtail/search/backends/elasticsearch2.py index 3f7cddc3c..1f5e911c0 100644 --- a/wagtail/search/backends/elasticsearch2.py +++ b/wagtail/search/backends/elasticsearch2.py @@ -806,7 +806,6 @@ class Elasticsearch2Index: for item in items: # Create the action action = { - '_index': self.name, '_type': doc_type, '_id': mapping.get_document_id(item), } @@ -814,7 +813,7 @@ class Elasticsearch2Index: actions.append(action) # Run the actions - bulk(self.es, actions) + bulk(self.es, actions, index=self.name) def delete_item(self, item): # Make sure the object can be indexed