sqlalchemy-elasticquery icon indicating copy to clipboard operation
sqlalchemy-elasticquery copied to clipboard

How to do "is NULL"/"is NOT NULL" query?

Open hussaintamboli opened this issue 8 years ago • 5 comments

I have tried

filter = {
    'filter': {
        'deleted_on': None
    }
}
# Err - UnboundLocalError: local variable 'operator' referenced before assignment

filter = {
    'filter': {
        'deleted_on': {
            'is': None
        }
    }
}

filter = {
    'filter': {
        'deleted_on': 'is_null'
    }
}

hussaintamboli avatar Apr 06 '16 07:04 hussaintamboli

@hussaintamboli hey, take a look here

loverajoel avatar Apr 13 '16 21:04 loverajoel

I have tried that with

 filter = {
     'filter': {
         'deleted_on': 'is_null'
     }
 }

But the query formed has

User.deleted_on = NULL

Instead of

User.deleted_on is NULL

hussaintamboli avatar Apr 14 '16 05:04 hussaintamboli

You have to change these lambda functions.

from

    'is_null': lambda f: f is None,
    'is_not_null': lambda f: f is not None,

to

    'is_null': lambda f: f.is_(None),
    'is_not_null': lambda f: f.isnot(None),

christopher11 avatar Jan 03 '20 01:01 christopher11

@christopher11 true, do you want to send a PR?

loverajoel avatar Jan 14 '20 19:01 loverajoel

change

from

    'is_null': lambda f: f is None,
    'is_not_null': lambda f: f is not None,

to

    'null': lambda f, a: f.is_(None) if a else f.isnot(None)

use

filter = {
    'field': {
        'null': true // or false
    }
}

its work

walirt avatar Mar 23 '21 03:03 walirt