Empty search term should not perform a search quers or should respond no results

Hi all,

in my application we are using Search UI with App Search connector. The default behavior of Search UI seems to match all documents if an empty query is fired.

Search API | App Search documentation [8.10] | Elastic

In our use case no query should be fired OR no results should be displayed if the user enters an empty or whitespaces only query string. (The user should also be able to delete the query per button in the UI. At the moment a query is performed then.)

So, is it possible to change that default behavior in Search UI or App Search or Enterprise Search/Elasticsearch? Or what other options I may have?

The best case would be that no query is performed if the search term is empty or whitespaces only.

But if it is not possible to avoid a query what options I have then? We will try to play a bit around with initialState and an "impossible" search term (e.g. an GUID which is unusal). SearchProvider | Documentation (elastic.co)

I saw also that other users modified the SearchBox. Reset filters to initial state on setSearchTerm · Issue #619 · elastic/search-ui · GitHub

There is also an beforeSearchCall option which may help - but I've never used them. App Search Connector | Documentation (elastic.co)

But maybe there is a "no-workaround" solution?

Best regards


Hi Sebastian,

You could still allow the search to proceed but the Results component does not render the results, potentially providing a list of common search queries to the user to select, rather than the results themselves.

I would advise you to adjust the SearchBox component too, to give visual feedback to the user they cannot search when the input is empty.

The suggestions are OK because search-ui wasn't built for this UX pattern - searching on an empty query string still provides options for the user to filter on facets for example.


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.