title: How to integrate Haystack with Django Rest Framework for making GET REST API for searching?
body: <p><strong>model.py</strong></p>
  
  <pre><code>class Item(models.Model):
          name=models.CharField(max_length=50)
          company=models.CharField(max_length=100)
  </code></pre>
  
  <p><strong>search_indexes.py</strong></p>
  
  <pre><code>class ItemIndex(indexes.SearchIndex, indexes.Indexable):
              text = indexes.CharField(document=True, use_template=True)
              name=indexes.CharField(model_attr='name')
              company=indexes.CharField(model_attr='company')
  
              def get_model(self):
                  return Item
  
              def index_queryset(self, using=None):
                  return self.get_model().objects.all()
  </code></pre>
  
  <p><strong>serializer.py</strong></p>
  
  <pre><code>class ItemSearchSerializer(serializers.Serializer):
      text = serializers.CharField()
      name=serializers.CharField()
      company=serializers.CharField()
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code> class ItemSearchViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
      serializer_class = ItemSearchSerializer  
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,) 
  
      def get_queryset(self):
          request = self.request
          queryset = EmptySearchQuerySet()
  
          if request.GET.get('q', ''):
              query = request.GET.get('q', '')
              queryset =SearchQuerySet().filter(content=query);
          return queryset
  </code></pre>
  
  <p><strong>And in url.py I added :</strong></p>
  
  <pre><code>router.register(r'searchquery', views.ItemSearchViewSet, base_name='searchquery')
  </code></pre>
  
  <blockquote>
    <p>Now on making GET request from postman like :</p>
    
    <p><a href="http://127.0.0.1:8000/searchquery/?q=app" rel="nofollow noreferrer">http://127.0.0.1:8000/searchquery/?q=app</a>, I am getting the response as desired as show below.</p>
  </blockquote>
  
  <pre><code>{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
      {
        "text": "apple\ndjflkj",
        "id": 14,
        "name": "apple",
        "mrp": "45.000000",
        "company": "djflkj",
        "imageid": "jfhi",
        "edible": false,
        "discount": "0.000000",
        "deliverable": true,
        "seller_uid": "ljhkh",
        "category": "ldjhgjfdk"
      },
      {
        "text": "app\nhuhiu",
        "id": 16,
        "name": "app",
        "mrp": "78.000000",
        "company": "huhiu",
        "imageid": "iyiugiy",
        "edible": false,
        "discount": "45.000000",
        "deliverable": true,
        "seller_uid": "hjh",
        "category": "hhl"
      }
    ]
  }
  </code></pre>
  
  <blockquote>
    <p>But <strong>the reponse time is very slow it takes around 2700 ms</strong> everytime ,
    and I want to make it fast. As response of elastic search is much fast
    but I don't know what I am doing wrong. Not sure but may be due to
    these reasons I am getting this delay :  1) Haystack is made for
    django, so on integrating it with django rest framework , it may be
    getting slow. 2) I am using free Bonsai Elastic search heroku add on
    and it has just 125 mb memory.</p>
  </blockquote>
  
  <p><strong>This is how I am connecting to Bonsai elastic search (setting.py)</strong></p>
  
  <pre><code>ES_URL = urlparse('https://******@pine-1455731.us-east1.bonsaisearch.net')
  print ES_URL
  HAYSTACK_CONNECTIONS = {
      'default': {
          'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
          'URL': ES_URL.scheme + '://' + ES_URL.hostname + ':443',
          'INDEX_NAME': 'haystack',
      },
  }
  
  if ES_URL.username:
      HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": ES_URL.username + ':' + ES_URL.password} 
  </code></pre>
  
  <p>Any help will be appreciated. I am new to elastic search. I want to do elastic search to search products by name for my android application.
  I even don't know whether this is the correct approach to do searching. I thought I would enter name of product I want to search and then i will send a GET request and get all the products which are related.    </p>
  
  <p>I did Python Profile please look it here: <a href="https://gist.github.com/coderbhupendra/f84905f364fa3f36003c913c1d92f82b" rel="nofollow noreferrer">gist</a></p>
  
  <p>If any one could suggest me any other way of achieving this I will appreciate your help.    </p>