search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

nested filters in search ui seem to be unsupported

Open dankoz51 opened this issue 2 years ago • 4 comments

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:

  1. Go to the App.js file
  2. add the national parks filter
  3. run the search ui page
  4. 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]

dankoz51 avatar Aug 12 '22 12:08 dankoz51

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

joemcelroy avatar Aug 12 '22 17:08 joemcelroy

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

joemcelroy avatar Aug 15 '22 14:08 joemcelroy

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" } }) } };

dankoz51 avatar Aug 15 '22 21:08 dankoz51

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!

joemcelroy avatar Aug 17 '22 11:08 joemcelroy

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.

botelastic[bot] avatar Nov 07 '22 16:11 botelastic[bot]

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?

Katsivelisp avatar Nov 08 '22 19:11 Katsivelisp

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.

botelastic[bot] avatar Jan 07 '23 19:01 botelastic[bot]

https://github.com/elastic/search-ui/issues/850#issuecomment-1307712371

Any news here? I have related issue

sergiusticiffw avatar Jul 27 '23 11:07 sergiusticiffw

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.

joemcelroy avatar Jul 27 '23 12:07 joemcelroy