search-ui
search-ui copied to clipboard
Toogle index in search provider
We are building an search experiance for an eccomerce platform. We have a few different content types (different document types) indexed in a few diffrent indicies.
We have tried a few different approaches without any luck to change the current index being used by the search provider but nothing seems to be working, it keep sending the search request to the first index that it was initialized with.
Switching between two diffent indices
Last attemt was to create a whole new AppSearchAPIConnector
with new searchKey
and engineName
in but that didn’t work either.
Any ideas on how to toggle the index and make a new search at the same time
@elastic/search-ui: 1.5.1 @elastic/search-ui-app-search-connector: 1.5.1
Working example would be great.
Thank you for a good product!
Hi @artcups,
My recommendation would be to put Products and Content into the same index / engine, and simply tag them with a type
attribute, so you can easily toggle between Products and Content with filters.
Alternatively, you use an App Search Meta Engine to make both engines searchable from the same query: https://www.elastic.co/guide/en/app-search/current/meta-engines-guide.html
The connector is cached by the SearchProvider so you won't be able to simply pass a new connector. You could try forcing the SearchProvider
to re-render completely using a key
prop when you pass it an updated connector.
Do something like:
<SearchProvider /*.... all of your normal config */ key={selectedType} />
selectedType
would be a simple string that changes any time you change between Products and Content.
Please let me know how you decide to proceed out how it works out.
We went with an index/metaindex with documents containing content_type with an beforeSearch method setting the fieldset depending on what type is choosen.
My problem now is that all the filter is added to the url. Is it possible to state what filters shoud be hidden in the address. The initial filter set in the config is only used on the first search.
Would be a great feature to add to the library since I dont think its an uncommon thing to do?
That would be a great feature, we've talked about that before. I can't totally grasp what you're describing as your solution, but I will say that if you configure a "global filter" like described here, it won't show up in the URL... but it WILL be applied to every query, not sure if that's what you want or not: https://github.com/elastic/search-ui/blob/master/ADVANCED.md#global-filters
Keeping this open as a feature request to be able to dynamically update the index being used in search.
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.
Can confirm we hit this issue We've hit the same issue with having one searchprovider and multiple indices(elasticsearch connector). If the state is set on reload it will use the proper url, but changing the QueryConfig can change everything but the URL/Index. Stepping through the code, it seems the apiConnector isn't properly updated. This also makes changing API-keys at run-time difficult, which we use to manage tiered access security.
Hey @cpebble
Thank you for your comment. As Jason mentioned above The connector is cached by the SearchProvider so you won't be able to simply pass a new connector. You could try forcing the SearchProvider to re-render completely using a key prop when you pass it an updated connector.
. Did you try to use key prop for SearchProvider?