-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_type parameter is deprecated in the MoreLikeThis query #269
Comments
Leaving this note here for anyone trying to get more_like_this working with Elasticsearch 7 or higher. I could not get it to work in the AWS version of Elasticsearch. The fix proposed by @Prakash2403 works, my solution was to use a local version of the class:- from rest_framework.decorators import action
from elasticsearch_dsl.query import MoreLikeThis
from rest_framework.response import Response
import copy
"""
The current version of django-elasticsearch-dsl-drf will not work with Elasticsearch 7 or higher more_like_this
reason being that the _type parameter is deprecated. So we copy their code and fix it locally
"""
class MoreLikeThisMixin(object):
"""More-like-this mixin."""
@action(detail=True)
def more_like_this(self, request, pk=None, id=None):
"""More-like-this functionality detail view.
:param request:
:return:
"""
if 'view' in request.parser_context:
view = request.parser_context['view']
kwargs = copy.copy(getattr(view, 'more_like_this_options', {}))
id_ = pk if pk else id
queryset = self.filter_queryset(self.get_queryset())
fields = kwargs.pop('fields', [])
if fields:
queryset = queryset.query(
MoreLikeThis(
fields=fields,
like={
'_id': "{}".format(id_),
'_index': "{}".format(self.index)
},
**kwargs
)
).sort('_score')
else:
queryset = queryset.query(
MoreLikeThis(
like={
'_id': "{}".format(id_),
'_index': "{}".format(self.index)
},
**kwargs
)
).sort('_score')
# Standard list-view implementation
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
_type parameter is deprecated in
MoreLikeThis
query in the latest version of ES. I get the following deprecation warning after I query atmore_like_this
endpointEnvironment
Python environment:
pip list
python --version
3.9.6
Which version of Elasticsearch are you using?
7.12.1
To Reproduce
Steps to reproduce the behavior:
ViewSet
and inheritMoreLikeThisMixin
more_like_this
endpointExpected behavior
Deprecation warnings shouldn't appear
@barseghyanartur I've fixed it on my fork. If you feel that this should be merged here, kindly let me know. I'll make a PR
The text was updated successfully, but these errors were encountered: