aparo/pyes — Issue #141: ResultSet.total raises AttributeError on dict queries
Author: davedash
Created: 2011-12-22 22:18:31+00:00
State: open

Here's my testcase:

In [7]: es.search(dict(text=dict(message="test"))).total
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/dash/Projects/elasticutils/the_code/elasticutils/__init__.py in ()
----> 1 es.search(dict(text=dict(message="test"))).total

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/es.pyc in __getattr__(self, name)
1412 def __getattr__(self, name):
1413 if self._results is None:
-> 1414 self._do_search()
1415 if name == "facets":
1416 return self._facets

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/es.pyc in _do_search(self, auto_increment)
1333
1334 self._results = self.connection.search_raw(self.query, indices=self.indices,
-> 1335 doc_types=self.doc_types, **self.query_params)
1336 if 'search_type' in self.query_params and self.query_params['search_type'] == "scan":
1337 self.scroller_parameters['search_type'] = self.query_params['search_type']

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/es.pyc in search_raw(self, query, indices, doc_types, **query_params)
1090 if hasattr(query, 'to_search_json'):
1091 # Common case - a Search or Query object.

-> 1092 body = query.to_search_json()
1093 elif isinstance(query, dict):
1094 # A direct set of search parameters.

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/query.pyc in to_search_json(self)
202
203 """
--> 204 return json.dumps(self.q, cls=ESJsonEncoder)
205
206

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/query.pyc in q(self)
125 @property
126 def q(self):
--> 127 return self.serialize()
128
129 def serialize(self):

/Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/query.pyc in serialize(self)
133 res = {}
134 if self.query:
--> 135 res["query"] = self.query.serialize()
136 if self.filter:
137 res['filter'] = self.filter.serialize()

AttributeError: 'dict' object has no attribute 'serialize'
> /Users/dash/.virtualenvs/elasticutils/src/pyes/pyes/query.py(135)serialize()
134 if self.query:
--> 135 res["query"] = self.query.serialize()
136 if self.filter: