-
Notifications
You must be signed in to change notification settings - Fork 18
Null search filter #879
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
Null search filter #879
Conversation
api/handlers/dataexplorerhandler.py
Outdated
] | ||
} | ||
}, | ||
{"exists":{"field":k.split('.')[0]}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be rare that they would reference a top-level key like container_type
, but we might want to be a bit more fault tolerant if they do reference a top level key. In that case, this line is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see below where you are appending to the should - my mistake. Also this comment is supposed to go with the comment above, but I'm sure you picked that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I might have been confusing with my original comment about removing this line - I was assuming it would only be dynamically removed when there is no dot notation in the key (a top level key would have no dot notation). Wouldn't we still need it to prevent the return of documents that would never have the key anyway?
api/handlers/dataexplorerhandler.py
Outdated
if "null" in v: | ||
try: | ||
v.remove("null") | ||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which cases would this fail? When v is a string, not a list? Mind making that more clear? Maybe checking v's type and acting on that knowledge instead?
Nice work, glad it was possible without too much complication. Mind adding the |
v = None | ||
null_filter = { | ||
'bool': { | ||
'should': [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the only bool keyword at this level, it works out having this be a should
, but should
s are used mostly to affect the scoring and it is not required that they match (when with more strict bool options like must
). I would switch it to a must
so if new logic is added here, it has the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading the docs again it looks like since this is also in a filter
context and not a query
context, should
means "must match at least one".
If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query.
Which doesn't actually make a difference in this context but ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was needed for when multiple boxes were checked because if a must was used would that not return only docs that both have the field set to a value and not, which would be none of them?
Changes look good, nice work. I'm going to test locally before giving it the final LGTM. |
Seems to be something off in the logic: Request:
Result:
Using the UI I started a new search and checked the "null" option for subject sex. |
Small typo in parse_request function fixed that was causing that error when I added the |
Fix works for me, feel free to merge! |
When search is given a list of values for a field in filters, if "null" is included, it will return all containers with those values and those for which the field does not have a value.
Review Checklist