9

I am using elasticsearch as backend for haystack in my Django project. I created everything required for a search as mentioned here. But when i search i throws a traceback error with TransportError(400, 'parsing_exception', 'no [query] registered for [filtered]').

I have googled for this issue. But don't get any solution. I would appreciate helping me solve this.

My traceback:

Traceback (most recent call last):
  File "c:\python34\lib\site- packages\haystack\backends\elasticsearch_backend.py", line 524, in search
_source=True)
  File "c:\python34\lib\site-packages\elasticsearch\client\utils.py", line 71, in _wrapped
    return func(*args, params=params, **kwargs)
  File "c:\python34\lib\site-packages\elasticsearch\client\__init__.py", line 569, in search
    doc_type, '_search'), params=params, body=body)
 File "c:\python34\lib\site-packages\elasticsearch\transport.py", line 327, in perform_request
   status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "c:\python34\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 124, in perform_request
    self._raise_error(response.status, raw_data)
  File "c:\python34\lib\site-packages\elasticsearch\connection\base.py", line 122, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400,  'parsing_exception', 'no [query] registered for [filtered]')
[28/Dec/2016 17:06:58]"GET /search/?q=code HTTP/1.1" 200 395

Update-1 : TraceBack after downgraded to elasticsearch==1.7.0

GET /haystack/modelresult/_search?_source=true [status:400 request:0.001s]
Failed to query Elasticsearch using '(code)': TransportError(400, 'parsing_exception')
Traceback (most recent call last):
  File "c:\python34\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 524, in search
_source=True)
  File "c:\python34\lib\site-packages\elasticsearch\client\utils.py", line 69, in _wrapped
    return func(*args, params=params, **kwargs)
  File "c:\python34\lib\site-packages\elasticsearch\client\__init__.py", line 527, in search
    doc_type, '_search'), params=params, body=body)
  File "c:\python34\lib\site-packages\elasticsearch\transport.py", line 307, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "c:\python34\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 93, in perform_request
    self._raise_error(response.status, raw_data)
  File "c:\python34\lib\site-packages\elasticsearch\connection\base.py", line 105, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception')
[28/Dec/2016 17:58:50]"GET /search/?q=code HTTP/1.1" 200 395
sumanth
  • 751
  • 2
  • 15
  • 34

3 Answers3

4

no [query] registered for [filtered]

From what I can see you are running ES 5.0 and you're sending a filtered query which has been deprecated in ES 2.x and removed in ES 5.x.

You need to replace it with a bool/filter query instead.

So if you had something like this:

{
  "query": {
    "filtered": {
      "filter": {}
    }
  }
}

Simply replace it with

{
  "query": {
    "bool": {
      "filter": {}
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Thanks for your kind answer. I am new using Django haystack and elasticsearch. Where should I replace the filtered with bool in my index. I can't find any query or filtered terms in my indexes. And even i tried switching to V2.4.0, it returns the same error. Can you please help me!! – sumanth Dec 28 '16 at 12:20
  • 2
    You need to downgrade your ES to [1.7.5](https://www.elastic.co/downloads/past-releases/elasticsearch-1-7-5) because [ES 2 and 5 are not yet supported](https://github.com/django-haystack/django-haystack/issues/1465) by Haystack apparently. – Val Dec 28 '16 at 12:25
  • I downgraded as you suggested, But now it throws back the same error except no [query] registered for [filtered]'). – sumanth Dec 28 '16 at 12:32
  • That's unlikely. If you really have ES 1.7.5 running then that error cannot be thrown. What do you get when running `curl -XGET localhost:9200` ? – Val Dec 28 '16 at 12:33
  • when i do $/bin:elasticsearch in my CLI, my server get connected to localhost:9200. But when i do service install it returns Installing service : "elasticsearch-service-x64" Using JAVA_HOME (64-bit): "C:\Program Files\Java\jre1.8.0_111" Failed installing 'elasticsearch-service-x64' service.. May i know how can i install it properly – sumanth Dec 28 '16 at 13:13
  • That's a different issue that would belong to a new question, so as not to cram too much into this one. – Val Dec 28 '16 at 13:15
  • Below I have posted the same problem that I faced as the above question. Please reply. Also I have asked question related to my problem here https://stackoverflow.com/questions/45410041/requesterror-transporterror400-uparsing-exception – Manish Ojha Aug 02 '17 at 07:26
0

Elasticsearch already deprecate filtered query. Use bool instead.

It works for me.

Zhu Xiaohu
  • 589
  • 6
  • 8
  • I am using elasticsearch 6 and django-haystack 2.6.1. Its still not working. Do i have to downgrade my elasticsearch? Also where can i replace filtered to bool? – Tushant Dec 09 '17 at 15:10
  • I suggest you to check the version to ensure them be matched. – Zhu Xiaohu Dec 09 '17 at 17:08
  • I downgraded elasticsearch to 5.0.1 and also installed elasticsearch in the system of same version. But when i curl localhost:9200, it shows me the version 6.0.1 but I have deleted it and reinstalled 5.0.1 version – Tushant Dec 10 '17 at 00:14
  • I downgraded to 5.6.5 and I am getting elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception', 'no [query] registered for [filtered]') . Where do i change that filter to bool? I dont know the path. Can you help me fix this, please? – Tushant Dec 10 '17 at 02:56
0

According to the haystack docs to fix this error you should set correct version of haystack engine backend in settings. For elasticsearch v 5.x.x it will be

H_ENGINE = 'haystack.backends.elasticsearch5_backend.Elasticsearch5SearchEngine'
Arseniy Lebedev
  • 440
  • 4
  • 9