From d14150eb43030c38dddd58869564ea5b6e521f89 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 14 Jul 2016 08:50:10 +0100 Subject: [PATCH] Elasticsearch: Replaced usage of index_analyzer (#2568) index_analyzer has been removed in Elasticsearch 2.0. But the new way works in older versions as well so I think it's worth switching to the new way now. https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_20_mapping_changes.html#_analyzer_mappings --- wagtail/wagtailsearch/backends/elasticsearch.py | 5 +++-- .../tests/test_elasticsearch_backend.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/wagtail/wagtailsearch/backends/elasticsearch.py b/wagtail/wagtailsearch/backends/elasticsearch.py index 548aa1e59..52a31c16a 100644 --- a/wagtail/wagtailsearch/backends/elasticsearch.py +++ b/wagtail/wagtailsearch/backends/elasticsearch.py @@ -62,7 +62,8 @@ class ElasticSearchMapping(object): mapping['boost'] = field.boost if field.partial_match: - mapping['index_analyzer'] = 'edgengram_analyzer' + mapping['analyzer'] = 'edgengram_analyzer' + mapping['search_analyzer'] = 'standard' mapping['include_in_all'] = True @@ -81,7 +82,7 @@ class ElasticSearchMapping(object): fields = { 'pk': dict(type='string', index='not_analyzed', store='yes', include_in_all=False), 'content_type': dict(type='string', index='not_analyzed', include_in_all=False), - '_partials': dict(type='string', index_analyzer='edgengram_analyzer', include_in_all=False), + '_partials': dict(type='string', analyzer='edgengram_analyzer', search_analyzer='standard', include_in_all=False), } fields.update(dict( diff --git a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py index 0c30a8e5d..fc246f90e 100644 --- a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py +++ b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py @@ -755,17 +755,17 @@ class TestElasticSearchMapping(TestCase): 'properties': { 'pk': {'index': 'not_analyzed', 'type': 'string', 'store': 'yes', 'include_in_all': False}, 'content_type': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, - '_partials': {'index_analyzer': 'edgengram_analyzer', 'include_in_all': False, 'type': 'string'}, + '_partials': {'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard', 'include_in_all': False, 'type': 'string'}, 'live_filter': {'index': 'not_analyzed', 'type': 'boolean', 'include_in_all': False}, 'published_date_filter': {'index': 'not_analyzed', 'type': 'date', 'include_in_all': False}, - 'title': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'title': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'title_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, 'content': {'type': 'string', 'include_in_all': True}, 'callable_indexed_field': {'type': 'string', 'include_in_all': True}, 'tags': { 'type': 'nested', 'properties': { - 'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'name': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, } }, @@ -837,11 +837,11 @@ class TestElasticSearchMappingInheritance(TestCase): 'properties': { # New 'extra_content': {'type': 'string', 'include_in_all': True}, - 'subtitle': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'subtitle': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'page': { 'type': 'nested', 'properties': { - 'title': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'title': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'search_description': {'type': 'string', 'include_in_all': True}, 'live_filter': {'index': 'not_analyzed', 'type': 'boolean', 'include_in_all': False}, } @@ -850,17 +850,17 @@ class TestElasticSearchMappingInheritance(TestCase): # Inherited 'pk': {'index': 'not_analyzed', 'type': 'string', 'store': 'yes', 'include_in_all': False}, 'content_type': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, - '_partials': {'index_analyzer': 'edgengram_analyzer', 'include_in_all': False, 'type': 'string'}, + '_partials': {'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard', 'include_in_all': False, 'type': 'string'}, 'live_filter': {'index': 'not_analyzed', 'type': 'boolean', 'include_in_all': False}, 'published_date_filter': {'index': 'not_analyzed', 'type': 'date', 'include_in_all': False}, - 'title': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'title': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'title_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, 'content': {'type': 'string', 'include_in_all': True}, 'callable_indexed_field': {'type': 'string', 'include_in_all': True}, 'tags': { 'type': 'nested', 'properties': { - 'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'name': {'type': 'string', 'include_in_all': True, 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard'}, 'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, } },