Elasticsearch-dsl-py: How to make nested query?

Created on 3 Mar 2016  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

Right now I'm just passing in the dict representing the JSON DSL:

        s = s.query({
            'nested': {
                'path': 'activity_tags',
                'query': {
                    'terms': {
                        'activity_tags.id': data['activity_tags[]']
                    }
                }
            }
        })

But is there a way to rephrase this using the Python DSL directly?

s = s.filter('nested', path='activity_tags', ... ?)

Most helpful comment

from elasticsearch_dsl import Q
s = s.query("nested", path="activity_tags", query=Q("terms", activity_tags__id=data['activity_tags[]']))

Should do the trick

All 2 comments

from elasticsearch_dsl import Q
s = s.query("nested", path="activity_tags", query=Q("terms", activity_tags__id=data['activity_tags[]']))

Should do the trick

Sweet, thanks again! :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

berinhard picture berinhard  路  3Comments

quasiben picture quasiben  路  4Comments

njoannin picture njoannin  路  3Comments

leoliuxd picture leoliuxd  路  4Comments

amih90 picture amih90  路  4Comments