Skip to content

Commit

Permalink
Make Mapping.from_es work for aliases as well.
Browse files Browse the repository at this point in the history
Fixes #158 thanks for the report, wataru-chocola!
  • Loading branch information
honzakral committed May 12, 2015
1 parent ecbd230 commit 9bef3ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elasticsearch_dsl/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def save(self, index, using='default'):
def update_from_es(self, index, using='default'):
es = connections.get_connection(using)
raw = es.indices.get_mapping(index=index, doc_type=self.doc_type)
raw = raw[index]['mappings'][self.doc_type]
_, raw = raw.popitem()
raw = raw['mappings'][self.doc_type]

for name, definition in iteritems(raw['properties']):
self.field(name, definition)
Expand Down
6 changes: 6 additions & 0 deletions test_elasticsearch_dsl/test_integration/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ def test_mapping_gets_updated_from_es(write_client):
}
}
} == m.to_dict()

# test same with alias
write_client.indices.put_alias(index='test-mapping', name='test-alias')

m2 = mapping.Mapping.from_es('test-alias', 'my_doc', using=write_client)
assert m2.to_dict() == m.to_dict()

0 comments on commit 9bef3ab

Please sign in to comment.