Elasticsearch-dsl-py: How do i make a range query/filter for a nested field using DSL?

Created on 1 Dec 2015  路  6Comments  路  Source: elastic/elasticsearch-dsl-py

Tried:

query = query.filter('range', **{'field.name': {'lt': 1.22}})

always comes up with empty results

Most helpful comment

For nested fields you need to use nested filters:

query = query.filter('nested', path='field', filter=F('range', field__name={'lt': 1.22}))

Note also that you can use double underscore instead of . to avoid having to use the **{} construct.

Hope this helps.

All 6 comments

For nested fields you need to use nested filters:

query = query.filter('nested', path='field', filter=F('range', field__name={'lt': 1.22}))

Note also that you can use double underscore instead of . to avoid having to use the **{} construct.

Hope this helps.

thanks! already figured that out

@HonzaKral : is there any way to query fields which are not nested using F object notations?
basically i want something like
query = query.filter('match', filter=F('fs.mount_point': '/'))

@siddhism you can either use python's ** expansion (query.filter('match', **{"fs.mount_point": "/"})) or use the fact that elasticsearch-dsl will expand __ to dot: query.filter('match', fs__mount_point='/')

Hi, I am using elasticsearch 5.4.0 and elasticsearch-dsl 5.3.0
I am trying the above command

s = Search().using(client).index("my_index").filter("nested", path="comment", filter=filter("range", comment__comment_value={'gte':"1"}))

It returns

TypeError: filter() does not take keyword arguments

What am I doing wrong ?
Also, I can't seem to find F shortcut ... is it deprecated ?

I think you are missing an underscore in comment__comment_value, which should read comment__comment__value.

And yes, if I am not mistaken, the F is deprecated (see changelog)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MauriJHN picture MauriJHN  路  4Comments

abuzakaria picture abuzakaria  路  4Comments

gabrielpjordao picture gabrielpjordao  路  3Comments

rokcarl picture rokcarl  路  4Comments

leoliuxd picture leoliuxd  路  4Comments