python - how to send a plain query to elasticsearch with pyes -
i have plain query send elasticsearch through pyes without using pyes's builtin methods. query works when it's curled.
further below code, can't make work. returns error when iterate on result object
traceback (most recent call last): file "testqualifier.py", line 9, in <module> r in results: file "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1384, in __next__ self._do_search() file "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1212, in _do_search self._results = self._search_raw(self.start, self.chuck_size) file "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 1428, in _search_raw doc_types=self.doc_types, headers=self.headers, **query_params) file "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 931, in search_raw return self._send_request('get', path, body, params=query_params, headers=headers) file "/usr/local/lib/python2.7/dist-packages/pyes/es.py", line 419, in _send_request raise_if_error(response.status, decoded) file "/usr/local/lib/python2.7/dist-packages/pyes/convert_errors.py", line 94, in raise_if_error raise exceptions.elasticsearchexception(error, status, result, request) pyes.exceptions.elasticsearchexception: queryparsingexception[[test] no query registered [facets]]; }]
can point me right direction?
#!/usr/bin/env python #-*- coding: utf-8 -*- pyes import * import json conn = es('127.0.0.1:9200') # use http q = { "facets": { "terms": { "terms": { "field": "breadcrumb", "size": 2, "order": "count", "exclude": [] }, "facet_filter": { "fquery": { "query": { "filtered": { "query": { "bool": { "should": [ { "query_string": { "fields": [ "title" ], "query": "solar panel" } } ] } }, "filter": { "bool": { "must": [ { "fquery": { "query": { "query_string": { "query": "vendorname:(\"abcdedf\")" } }, "_cache": true } } ] } } } } } } } }, "size": 0 } results = conn.search(query = q) r in results: print r
found out. works...
#!/usr/bin/env python #-*- coding: utf-8 -*- pyes import * conn = es('127.0.0.1:9200') # use http q = { "facets": { "terms": { "terms": { "field": "breadcrumb", "size": 2, "order": "count", "exclude": [] }, "facet_filter": { "fquery": { "query": { "filtered": { "query": { "bool": { "should": [ { "query_string": { "fields": [ "title" ], "query": "solar panel" } } ] } }, "filter": { "bool": { "must": [ { "fquery": { "query": { "query_string": { "query": "vendorname:(\"abcdef\")" } }, "_cache": true } } ] } } } } } } } }, "size": 0 } results = conn._send_request('get', 'vendor/_search', q) r in results: print r
Comments
Post a Comment