Skip to content

Commit 9bc84b6

Browse files
committed
Document with no index should always match hits
Fixes #1203
1 parent 93e5c5d commit 9bc84b6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

elasticsearch_dsl/document.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class Document(ObjectBase):
111111
"""
112112
@classmethod
113113
def _matches(cls, hit):
114+
if cls._index._name is None:
115+
return True
114116
return fnmatch(hit.get('_index', ''), cls._index._name)
115117

116118
@classmethod

test_elasticsearch_dsl/test_document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ def test_matches_uses_index():
140140
'_index': 'not-test-git'
141141
})
142142

143+
def test_matches_with_no_name_always_matches():
144+
class D(document.Document):
145+
pass
146+
147+
assert D._matches({})
148+
assert D._matches({'_index': 'whatever'})
149+
143150
def test_matches_accepts_wildcards():
144151
class MyDoc(document.Document):
145152
class Index:

0 commit comments

Comments
 (0)