Django/Haystack error: elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception',...)
Asked Answered
K

3

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
Kathikathiawar answered 28/12, 2016 at 11:38 Comment(1)
can you please write the search query. I have the same problem and am not able to solve it.Plait
L
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": {}
    }
  }
}
Laveen answered 28/12, 2016 at 12:4 Comment(7)
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!!Kathikathiawar
You need to downgrade your ES to 1.7.5 because ES 2 and 5 are not yet supported by Haystack apparently.Laveen
I downgraded as you suggested, But now it throws back the same error except no [query] registered for [filtered]').Kathikathiawar
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 ?Laveen
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 properlyKathikathiawar
That's a different issue that would belong to a new question, so as not to cram too much into this one.Laveen
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 #45410541Plait
E
0

Elasticsearch already deprecate filtered query. Use bool instead.

It works for me.

Ethelynethene answered 4/7, 2017 at 10:10 Comment(4)
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?Consign
I suggest you to check the version to ensure them be matched.Ethelynethene
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 versionConsign
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?Consign
C
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'
Carthage answered 19/11, 2020 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.