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

  1. Follow the docs to Setup for working on an issue. Log in as an administrator.
  2. Go to /admin/modules, and enable Core's Datetime Range (datetime_range module) and its dependencies.
  3. Go to /admin/structure/types/add, and add an Event content type (machine name event).
  4. Go to /admin/structure/types/manage/event/fields/add-field, click Date and time, enter Label = Event date (machine name field_event_date), Choose a field type = Date range, click the Continue button, then click the Save button to accept the defaults on the second page.
  5. 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 the Save button.
  6. Go to /admin/config/search/search-api/add-index, set Index name = Events, Datasources = Content, Server = elasticsearch_server, then click the Save button.
  7. Go to /admin/config/search/search-api/index/events/fields/add/nojs; and click the Add button in the Title (title) row and the Event date (field_event_date) row. Then click the Done button. On the Manage fields for search index Events, in the field_event_date row, set Type = Date. Click the Save changes button.
  8. Go to /admin/config/search/search-api/index/events. Under Start indexing now, click the Index now button. Wait for the batch job to complete. You should see the Status message Successfully indexed 3 items.
  9. Go to /admin/structure/views/add. Set View name = Event search (machine name event_search). Under View settings, Show Index Events sorted by: Unsorted. Under Page settings, check Create a page, and make sure that Path is set to event-search. Click the Save and edit button.
  10. You are taken to the view/edit page at /admin/structure/views/view/event_search. Under Fields, remove all existing fields, then click the Add button, and check Title (indexed field) in the Content data-source category. Click the Add and configure fields button, then click the Apply button to accept the defaults on the second page. Under Filter criteria, click the Add button, and check Event date in the Content datasource category. Click the Add and configure filter criteria button, then check Expose this filter to visitors, to allow them to change it. Also check Expose operator. Click the Apply button. Don't forget to click Save on the view itself.
  11. Go to /event-search. You see the Event search view you created. You see 1 result: Sprints.
  12. Set Event Date = Is empty (NULL), then click the Apply button. You see 0 results.
    Expected result: 0 warnings are logged.
    Actual result: The warning Invalid condition field_event_date = NULL is logged.
  13. Set Event Date = Is not empty (NOT NULL), then click the Apply button. 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

  1. Add a merge request for 9.0.x - merge request !191 created by @mparker17 in #3
  2. Community review and testing, move to RTBC if passes - done by @fathershawn in #5
  3. Maintainer review and testing - skipped by @mparker17 because a maintainer wrote the merge request
  4. Add a merge request for 8.0.x - done by @mparker17 in #8
  5. Merge to 9.0.x - done by @mparker17 in #10
  6. Merge to 8.0.x - done by @mparker17 in #12
  7. Release 9.0.x - released in 9.0.0-alpha3 by @mparker17
  8. Release 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.

Command icon 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

mparker17 created an issue. See original summary.

mparker17’s picture

mparker17’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +needs backport to 8.0.x

I've written a patch. I would appreciate a review from the community!

fathershawn’s picture

This code looks good to me!

mparker17’s picture

@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!

mparker17’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks @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.

mparker17’s picture

Issue summary: View changes

Created an 8.0.x merge request; leaving the tag so I remember to merge it.

  • mparker17 committed f348761c on 9.0.x
    fix: #3584210 Irrelevant warnings when filter value is null
    
    By:...
mparker17’s picture

Version: 9.0.x-dev » 8.0.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: -needs backport to 8.0.x

Merged to 9.0.x; merging to 8.0.x next.

  • mparker17 committed 6ed5780a on 8.0.x
    fix: #3584210 Irrelevant warnings when filter value is null
    
    By:...
mparker17’s picture

Issue summary: View changes
Status: Patch (to be ported) » Fixed

Merged to 8.0.x as well now. I will update this issue when I make a release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mparker17’s picture

Issue summary: View changes

The changes in this issue were released in elasticsearch_connector-9.0.0-alpha3, and elasticsearch_connector-8.0.0-alpha7

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.