search-ui
search-ui copied to clipboard
nested filters in search ui seem to be unsupported
Describe the bug
When trying to nest a filter such as in the national parks example
curl -X GET '[<ENTERPRISE_SEARCH_BASE_URL>](https://www.elastic.co/guide/en/enterprise-search/8.3/endpoints-ref.html#enterprise-search-base-url)/api/as/v1/engines/national-parks-demo/search' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \ -d '{ "query": "parks", "filters": { "any": [ { "all": [ { "states": "California" }, { "world_heritage_site": "true" } ] } ] } }'
There is no syntax i can find that works for the search ui filter. The basic filter works but I cant find a way to nest it.
const config = { searchQuery: { facets: buildFacetConfigFromConfig(), ...buildSearchOptionsFromConfig(), filters : [{field: 'world_heritage_site', values: ["true"]}], }, autocompleteQuery: buildAutocompleteQueryConfig(), apiConnector: connector, alwaysSearchOnInitialLoad: true };
To Reproduce Steps to reproduce the behavior:
- Go to the App.js file
- add the national parks filter
- run the search ui page
- See error, An unexpected error occurred: Cannot read properties of undefined (reading 'map')
Expected behavior Page would be filtered by the nested filter
Backend: [App Search]
hey @dankoz51 thanks for the bug report. We will look into it soon.
Context https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/4 Related #837
Had a look into this issue today.
What happening is Search UI facets controls what filters are applied. Although you can put in initial filters into filters
state, this cannot be nested as the facets only assume it's one level deep and work with a simple model of managing filters. If we introduce nesting here, there will likely be issues that arise from facets using the filter state.
What I believe you want is base filters which are nested and computed ahead of time outside of Search UI. One way we can help with this is adding a baseFilters
property. On request, we combine both the Search UI controlled facet filters with developer provided baseFilters to be performed in the API request.
One way to workaround this issue is implement the beforeSearchCall on the connector docs & where its called and include within the filters property your nested filters before its dispatched to app search API.
Also to note filters can also be in api signed keys where your nested filters are in the key itself see api-keys blog article on how to use. When a customer makes a request with their own signed key, it will apply the filters on top of the search request.
Hope this helps Joe
Thanks for the feedback
I am trying to call the beforeSearchCall hook in this way but I dont think its working it does not seem to be firing
Also I did not understand from the "where its called" do i need to modify the where its called function as well?
const config = { searchQuery: { facets: buildFacetConfigFromConfig(), ...buildSearchOptionsFromConfig(), }, autocompleteQuery: buildAutocompleteQueryConfig(), apiConnector: connector, alwaysSearchOnInitialLoad: true, beforeSearchCall: (existingSearchOptions, next) => { console.log("existingSearchOptions",existingSearchOptions); next({ ...existingSearchOptions, group: { field: "title" } }) } };
Hey @dankoz51
This hook is implemented on the connector. created an example here https://codesandbox.io/s/thirsty-shape-hyzs3d?file=/src/pages/app-search/index.js:752-847
Hope this helps!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.
Hello @joemcelroy , just to expand on this. How can this be done with an ElasticSearchAPIConnector?
beforeSearchCall is not supported there yet, it seems. Are there any plans? Alternatively, Is there any other way to create facets on nested fields?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.
https://github.com/elastic/search-ui/issues/850#issuecomment-1307712371
Any news here? I have related issue
Hi there, No news, and not planned.
Alternatives are using www.github.com/searchkit/searchkit which does support nested fields for facets and field results.