Skip to content

Commit

Permalink
Pass update_all_types=True to put_mapping on ES2 - workaround for #2968
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Oct 5, 2016
1 parent 882facf commit b4a4e5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ deps =
dj110head: git+https://github.com/django/django.git@stable/1.10.x#egg=Django
postgres: psycopg2>=2.6
mysql: mysqlclient==1.3.6
elasticsearch: elasticsearch>=1,<2
elasticsearch2: elasticsearch>=2,<3

setenv =
Expand Down
12 changes: 11 additions & 1 deletion wagtail/wagtailsearch/backends/elasticsearch2.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ def get_document(self, obj):


class Elasticsearch2Index(ElasticsearchIndex):
pass
def add_model(self, model):
# Get mapping
mapping = self.mapping_class(model)

# Put mapping
self.es.indices.put_mapping(
# pass update_all_types=True as a workaround to avoid "Can't redefine search field" errors -
# see https://github.com/torchbox/wagtail/issues/2968
index=self.name, doc_type=mapping.get_document_type(), body=mapping.get_mapping(),
update_all_types=True
)


class Elasticsearch2SearchQuery(ElasticsearchSearchQuery):
Expand Down

0 comments on commit b4a4e5e

Please sign in to comment.