Skip to content

Commit b122a36

Browse files
committed
Make sure DJANGO_CT and DJANGO_ID fields are not analyzed
1 parent 33b2b08 commit b122a36

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

haystack/backends/elasticsearch_backend.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,10 @@ def _process_results(self, raw_results, highlight=False,
614614

615615
def build_schema(self, fields):
616616
content_field_name = ''
617-
mapping = {}
617+
mapping = {
618+
DJANGO_CT: {'type': 'string', 'index': 'not_analyzed', 'include_in_all': False},
619+
DJANGO_ID: {'type': 'string', 'index': 'not_analyzed', 'include_in_all': False},
620+
}
618621

619622
for field_name, field_class in fields.items():
620623
field_mapping = FIELD_MAPPINGS.get(field_class.field_type, DEFAULT_FIELD_MAPPING).copy()

tests/elasticsearch_tests/tests/test_elasticsearch_backend.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ def test_build_schema(self):
438438

439439
(content_field_name, mapping) = self.sb.build_schema(old_ui.all_searchfields())
440440
self.assertEqual(content_field_name, 'text')
441-
self.assertEqual(len(mapping), 4)
441+
self.assertEqual(len(mapping), 4+2) # +2 management fields
442442
self.assertEqual(mapping, {
443+
'django_id': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
444+
'django_ct': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
443445
'text': {'type': 'string', 'analyzer': 'snowball'},
444446
'pub_date': {'type': 'date'},
445447
'name': {'type': 'string', 'analyzer': 'snowball'},
@@ -450,8 +452,10 @@ def test_build_schema(self):
450452
ui.build(indexes=[ElasticsearchComplexFacetsMockSearchIndex()])
451453
(content_field_name, mapping) = self.sb.build_schema(ui.all_searchfields())
452454
self.assertEqual(content_field_name, 'text')
453-
self.assertEqual(len(mapping), 15)
455+
self.assertEqual(len(mapping), 15+2) # +2 management fields
454456
self.assertEqual(mapping, {
457+
'django_id': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
458+
'django_ct': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
455459
'name': {'type': 'string', 'analyzer': 'snowball'},
456460
'is_active_exact': {'type': 'boolean'},
457461
'created': {'type': 'date'},
@@ -1068,6 +1072,8 @@ def test_build_schema(self):
10681072
self.sb = connections['default'].get_backend()
10691073
content_name, mapping = self.sb.build_schema(self.ui.all_searchfields())
10701074
self.assertEqual(mapping, {
1075+
'django_id': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
1076+
'django_ct': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False},
10711077
'name_auto': {
10721078
'type': 'string',
10731079
'analyzer': 'edgengram_analyzer',

0 commit comments

Comments
 (0)