Reputation: 3502
I have a plain query that I would like to send to Elasticsearch through pyes without using pyes's builtin methods. The query works when it's CURLed.
further below is my code, but I can't make it work. It returns this error when I iterate over the result object
Traceback (most recent call last):
File "testQualifier.py", line 9, in <module>
for 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 for [facets]]; }]
Can anyone point me into the right direction?
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from 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)
for r in results:
print r
Upvotes: 0
Views: 613
Reputation: 3502
found it out. this works...
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from 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)
for r in results:
print r
Upvotes: 0