Skip to content

Commit

Permalink
Added _matches() to DocType for alias pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
oehrlein committed Oct 6, 2021
1 parent 39d1ba2 commit 80fdf34
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions django_elasticsearch_dsl/documents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

from collections import deque
from fnmatch import fnmatch
from functools import partial

from django import VERSION as DJANGO_VERSION
Expand Down Expand Up @@ -66,6 +67,18 @@ def __eq__(self, other):
def __hash__(self):
return id(self)

@classmethod
def _matches(cls, hit):
"""
Determine which index or indices in a pattern to be used in a hit.
Overrides DSLDocument _matches function to match indices in a pattern,
which is needed in case of using aliases. This is needed as the
document class will not be used to deserialize the documents. The
documents will have the index set to the concrete index, whereas the
class refers to the alias.
"""
return fnmatch(hit['_index'], cls._index._name + "-*")

@classmethod
def search(cls, using=None, index=None):
return Search(
Expand Down

0 comments on commit 80fdf34

Please sign in to comment.