Skip to content

Commit a8bf1ff

Browse files
safwanrahmanhonzakral
authored andcommitted
[Fix #1091] Index.document() does not set index on Document class
1 parent 150add9 commit a8bf1ff

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

elasticsearch_dsl/document.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def __new__(cls, name, bases, attrs):
3737
new_cls = super(IndexMeta, cls).__new__(cls, name, bases, attrs)
3838
if cls._document_initialized:
3939
index_opts = attrs.pop('Index', None)
40-
new_cls._index = cls.construct_index(index_opts, bases)
41-
new_cls._index.document(new_cls)
40+
index = cls.construct_index(index_opts, bases)
41+
if index:
42+
new_cls._index = index
43+
index.document(new_cls)
4244
cls._document_initialized = True
4345
return new_cls
4446

@@ -48,8 +50,9 @@ def construct_index(cls, opts, bases):
4850
for b in bases:
4951
if hasattr(b, '_index'):
5052
return b._index
51-
# create an all-matching index pattern
52-
return Index('*')
53+
54+
# return None as there are no index_opts
55+
return None
5356

5457
i = Index(
5558
getattr(opts, 'name', '*'),

elasticsearch_dsl/index.py

+5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ class Post(Document):
159159
'Index object cannot have multiple types, %s already set, '
160160
'trying to assign %s.' % (doc_type, name))
161161
self._doc_types.append(document)
162+
163+
# If the document does not have any index, set this index as document index
164+
if document._index is None:
165+
document._index = self
166+
162167
return document
163168
doc_type = document
164169

0 commit comments

Comments
 (0)