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

Add has_child and has_parent support #226

Open pziemkowski opened 10 years ago

pziemkowski commented 10 years ago

I would like to use has_child query, which requires me to pass another query as a value.

Here is the process_query method.

class HasChildS(S):
            def process_query_has_child(self, key, val, action):
                return {'has_child', {'type': key, 'query': val}}

From what I understand, right now it is impossible to pass another query as a value, e.g.

HasChildS(SomeMappingType).query(type_name__has_child=Q(foo="bar"))
willkg commented 10 years ago

With the code you've written, you can't accept a Q argument. You need to process the Q turning it into Elasticsearch JSON stuff.

You probably want something like this:

    def process_query_has_child(self, key, val, action):
        return {'has_child', {'type': key, 'query': self._process_queries([val])}}
jmizgajski commented 10 years ago

Or we could do it using Q and F parametrized with child type, to keep the API clean, something like:

S().query(has_child=Q(child_field=search_text), child_type=some_type) 

which would give more flexibility

willkg commented 10 years ago

I don't think you can do that without rewriting how S._process_queries works.

Now that I'm re-reading what you've written, I don't think I understand what you're asking for in this issue. Are you asking for support on code you've written that isn't working? Or are you asking to have support for something new in ElasticUtils and tossing around how it could be implemented?

willkg commented 10 years ago

@jmizgajski ^^^ ?

jmizgajski commented 10 years ago

I think your solution is sound, you can close it or add support to the new release the way you described it.

willkg commented 10 years ago

I'm going to bump this to post-0.10 where we'll have a lot more wiggle room for new features and refactoring.

gregorth commented 10 years ago

any news here?

jmizgajski commented 10 years ago

Parent child can be easily implemented by appropriate mapping definition and raw queries.

2014-07-31 14:50 GMT+02:00 Grzegorz Ślusarek notifications@github.com:

any news here?

— Reply to this email directly or view it on GitHub https://github.com/mozilla/elasticutils/issues/226#issuecomment-50754072 .