mozilla / elasticutils

[deprecated] A friendly chainable ElasticSearch interface for python
http://elasticutils.rtfd.org
BSD 3-Clause "New" or "Revised" License
243 stars 76 forks source link

query[0] yields index out of range where list(query)[0] works fine #227

Closed jmizgajski closed 10 years ago

jmizgajski commented 10 years ago

Hi there,

We created a custom type based on Indexable and MappingType that registers all subclasses in a meta class so that they can be used in commands that do very fast batch indexing and tests that set up all indices (properly prefixed) for you (soon I'll do a pull request). However I have run in to a very unusual problem where I cannot get the first result of a query in a regular way when list(query)[0] works fine, the query is in simple form of: S(UserMapping).filter(id=some_id).

Here is a gist of the few files that we wrote, BatchIndexable is a class we use as a parent for all our mappings.

jmizgajski commented 10 years ago

A problem seems to be with the self._clone() method of S when debuging

    def __getitem__(self, k):
        """Handles slice and indexes for Elasticsearch results"""
        new = self._clone()
        if isinstance(k, slice):
            new.start, new.stop = k.start or 0, k.stop
            return new
        else:
            new.start, new.stop = k, k + 1
            return list(new)[0]

list(self) returns 1 element when list(new) with is empty

jmizgajski commented 10 years ago

btw, we are running elasticsearch 1.1, but did not have any problems without our custom modifications.

jmizgajski commented 10 years ago

We figured it out, our es got broken by https://github.com/elasticsearch/elasticsearch-lang-python/tree/es-1.1. Nonetheless please chekout the gist and tell me what you think. I was hoping for some directions about where to put it in elasticutils when I'll do a pull request.

willkg commented 10 years ago

Sticking this in the ElasticUtils 0.10 milestone.

jmizgajski commented 10 years ago

That's awesome, maybe we could arrange a hangout so you could instruct me how to structure it for a PR, by the way we updated it a bit in the meantime and it works great. You can reach me at mizgajski dottt jan attt gmail.

willkg commented 10 years ago

Is this fixed now? I thought it was still an issue.

jmizgajski commented 10 years ago

I'm not experiencing this issue anymore, but I uninstalled the culprit plugin