Skip to content

Commit 5d7ea0d

Browse files
fix helpers
1 parent a78e1f7 commit 5d7ea0d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/django_elasticsearch_dsl_drf/helpers.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from six import PY3
1313

14+
from .versions import ELASTICSEARCH_GTE_7_0
1415

1516
__title__ = 'django_elasticsearch_dsl_drf.helpers'
1617
__author__ = 'Artur Barseghyan <[email protected]>'
@@ -146,14 +147,17 @@ def more_like_this(obj,
146147
if max_doc_freq is not None:
147148
kwargs['max_doc_freq'] = max_doc_freq
148149

150+
_like_options = {
151+
'_id': "{}".format(obj.pk),
152+
'_index': "{}".format(_index),
153+
}
154+
if not ELASTICSEARCH_GTE_7_0:
155+
_like_options.update({'_type': "{}".format(_mapping)})
156+
149157
return _search.query(
150158
MoreLikeThis(
151159
fields=fields,
152-
like={
153-
'_id': "{}".format(obj.pk),
154-
'_index': "{}".format(_index),
155-
'_type': "{}".format(_mapping)
156-
},
160+
like=_like_options,
157161
**kwargs
158162
)
159163
)

0 commit comments

Comments
 (0)