I'm using elasticsearch_dsl
which works great.
However, I would like the results to filter according the the user token that gets sent.
I tried using rest_frameworks' filters, but had no success with it.
What is the right way to achieve this?
URL to access results
http://localhost:9200/_search
Models.py
class Task(models.Model):
title = models.CharField("Title", max_length=10000, blank=True)
owner = models.ForeignKey('auth.User', blank=True, null=True)
Search.py
from rest_framework import filters
connections.create_connection()
class TaskIndex(DocType):
title = String()
class Meta:
index = 'task-index'
def filter_queryset(self, request, queryset, view):
return queryset.filter(owner=request.user)
def bulk_indexing():
TaskIndex.init()
es = Elasticsearch()
bulk(client=es, actions=(b.indexing() for b in models.Task.objects.all().iterator()))
def _search(title):
s = Search().filter('term', title=title.text)
response = s.execute()
return response