Skip to content

Commit

Permalink
Fallback to default index in to_dict(True)
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed May 15, 2015
1 parent 21c30a6 commit 3c8af33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def to_dict(self, include_meta=False):
for k in META_FIELDS
if k in self.meta
)
if 'index' not in meta and self._doc_type.index:
meta['_index'] = self._doc_type.index
meta['_type'] = self._doc_type.name
meta['_source'] = d
d = meta
Expand Down
7 changes: 3 additions & 4 deletions test_elasticsearch_dsl/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class DocWithNested(document.DocType):
comments = field.Nested(properties={'title': field.String()})

def test_to_dict_with_meta():
d = MyDoc(title='hello')
d = MySubDoc(title='hello')
d.meta.parent = 'some-parent'
d.meta.index = 'other-index'

assert {
'_index': 'other-index',
'_index': 'default-index',
'_parent': 'some-parent',
'_type': 'my_doc',
'_type': 'my_custom_doc',
'_source': {'title': 'hello'},
} == d.to_dict(True)

Expand Down

0 comments on commit 3c8af33

Please sign in to comment.