0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Fixed bug causing nested objects to be mapped with parents mapping class (#2572)

Nested objects that are defined using RelatedFields were being mapped into Elasticsearch using the parent model's mapping.

For example, if we index a page with tags, the tags were being mapped with the Page mapping instead of the Tag mapping.

This doesn't make any difference for Elasticsearch 1, but Elasticsearch 2 needs to prefix fields if there are defined on a child model and it was doing this across the related fields as well.

This fix is covered by the tests coming in the Elasticsearch 2 backend.
This commit is contained in:
Karl Hobley 2016-07-29 11:16:26 +01:00 committed by Mikalai Radchuk
parent 210b8532d9
commit 2ea14994ff

View File

@ -59,9 +59,11 @@ class ElasticsearchMapping(object):
def get_field_mapping(self, field):
if isinstance(field, RelatedFields):
mapping = {'type': 'nested', 'properties': {}}
nested_model = field.get_field(self.model).related_model
nested_mapping = type(self)(nested_model)
for sub_field in field.fields:
sub_field_name, sub_field_mapping = self.get_field_mapping(sub_field)
sub_field_name, sub_field_mapping = nested_mapping.get_field_mapping(sub_field)
mapping['properties'][sub_field_name] = sub_field_mapping
return self.get_field_column_name(field), mapping