Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hussaintamboli opened this issue Apr 6, 2016 · 5 comments · May be fixed by #17
Open

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

hussaintamboli opened this issue Apr 6, 2016 · 5 comments · May be fixed by #17

Comments

@hussaintamboli
Copy link

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'
    }
}
@loverajoel
Copy link
Owner

@hussaintamboli hey, take a look here

@hussaintamboli
Copy link
Author

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

@christopher11
Copy link

christopher11 commented Jan 3, 2020

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),

@loverajoel
Copy link
Owner

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

@walirt
Copy link

walirt commented Mar 23, 2021

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

christopher11 added a commit to christopher11/sqlalchemy-elasticquery that referenced this issue Mar 23, 2021
Fixes loverajoel#11
loverajoel#11

Change these lambda functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants