Problem/Motivation
While reviewing/testing #3551591: Filter does not work with date range fields, we noticed that using the Is empty (NULL) and Is not empty (NOT NULL) operators would result in Invalid condition field_example = NULL and Invalid condition field_example <> NULL respectively being written to the site's log as warnings.
This appears to be because !$condition->getValue() evaluates to TRUE in \Drupal\elasticsearch_connector\SearchAPI\Query\FilterBuilder::buildFilters(); but a value of NULL is an expected condition (see FilterBuilder::buildFilterTerm())!
Steps to reproduce
- Follow the docs to Setup for working on an issue. Log in as an administrator.
- Go to
/admin/modules, and enable Core's Datetime Range (datetime_rangemodule) and its dependencies. - Go to
/admin/structure/types/add, and add anEventcontent type (machine nameevent). - Go to
/admin/structure/types/manage/event/fields/add-field, click Date and time, enter Label =Event date(machine namefield_event_date), Choose a field type =Date range, click theContinuebutton, then click theSavebutton to accept the defaults on the second page. - Go to
/node/add/event, set Title =Sprints, Start date =2026-04-10 09:45:00, End date =2026-04-11 16:15:00, then click theSavebutton. - Go to
/admin/config/search/search-api/add-index, set Index name =Events, Datasources =Content, Server =elasticsearch_server, then click theSavebutton. - Go to
/admin/config/search/search-api/index/events/fields/add/nojs; and click theAddbutton in the Title (title) row and the Event date (field_event_date) row. Then click theDonebutton. On theManage fields for search index Events, in thefield_event_daterow, set Type =Date. Click theSave changesbutton. - Go to
/admin/config/search/search-api/index/events. Under Start indexing now, click theIndex nowbutton. Wait for the batch job to complete. You should see the Status message Successfully indexed 3 items. - Go to
/admin/structure/views/add. Set View name =Event search(machine nameevent_search). Under View settings, ShowIndex Eventssorted by:Unsorted. Under Page settings, checkCreate a page, and make sure that Path is set toevent-search. Click theSave and editbutton. - You are taken to the view/edit page at
/admin/structure/views/view/event_search. Under Fields, remove all existing fields, then click theAddbutton, and checkTitle (indexed field)in the Content data-source category. Click theAdd and configure fieldsbutton, then click theApplybutton to accept the defaults on the second page. Under Filter criteria, click theAddbutton, and checkEvent datein the Content datasource category. Click theAdd and configure filter criteriabutton, then checkExpose this filter to visitors, to allow them to change it. Also checkExpose operator. Click theApplybutton. Don't forget to clickSaveon the view itself. - Go to
/event-search. You see the Event search view you created. You see 1 result: Sprints. - Set Event Date =
Is empty (NULL), then click theApplybutton. You see 0 results.
Expected result: 0 warnings are logged.
Actual result: The warning Invalid condition field_event_date = NULL is logged. - Set Event Date =
Is not empty (NOT NULL), then click theApplybutton. You see 1 result: Sprints.
Expected result: 0 warnings are logged.
Actual result: The warning Invalid condition field_event_date = NULL is logged.
Proposed resolution
Turns out that Search API OpenSearch already removed this condition for generating a warning in #3576198: Irrelevant warnings when filter value is null. So we can probably safely remove it too.
Remaining tasks
Add a merge request for 9.0.x- merge request !191 created by @mparker17 in #3Community review and testing, move to RTBC if passes- done by @fathershawn in #5Maintainer review and testing- skipped by @mparker17 because a maintainer wrote the merge requestAdd a merge request for 8.0.x- done by @mparker17 in #8Merge to 9.0.x- done by @mparker17 in #10Merge to 8.0.x- done by @mparker17 in #12Release 9.0.x- released in 9.0.0-alpha3 by @mparker17Release 8.0.x- released in 8.0.0-alpha7 by @mparker17
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
To be done.
Issue fork elasticsearch_connector-3584210
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mparker17Added #3576198: Irrelevant warnings when filter value is null as a related link.
Comment #4
mparker17I've written a patch. I would appreciate a review from the community!
Comment #5
fathershawnThis code looks good to me!
Comment #6
mparker17@dewalt, @hetal.solanki, @vivibdev, @oulalahakabu: if you have some time, I would also appreciate it if you could test this merge request to see if it fixes the issue you were seeing! If it does, please change its status to Reviewed & tested by the community in your reply!
Comment #7
mparker17Thanks @fathershawn for the review in #5
I haven't heard back from @dewalt, @hetal.solanki, @vivibdev, @oulalahakabu so I'm going to merge this shortly.
Comment #9
mparker17Created an 8.0.x merge request; leaving the tag so I remember to merge it.
Comment #11
mparker17Merged to 9.0.x; merging to 8.0.x next.
Comment #13
mparker17Merged to 8.0.x as well now. I will update this issue when I make a release.
Comment #15
mparker17The changes in this issue were released in elasticsearch_connector-9.0.0-alpha3, and elasticsearch_connector-8.0.0-alpha7