Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toogle index in search provider #584

Open
artcups opened this issue Aug 29, 2021 · 9 comments
Open

Toogle index in search provider #584

artcups opened this issue Aug 29, 2021 · 9 comments

Comments

@artcups
Copy link

artcups commented Aug 29, 2021

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
image

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!

@JasonStoltz
Copy link
Member

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.

@JasonStoltz
Copy link
Member

Please let me know how you decide to proceed out how it works out.

@artcups
Copy link
Author

artcups commented Sep 2, 2021

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?

@JasonStoltz
Copy link
Member

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

@JasonStoltz
Copy link
Member

Keeping this open as a feature request to be able to dynamically update the index being used in search.

@botelastic
Copy link

botelastic bot commented Dec 11, 2021

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 botelastic bot added the wontfix This will not be worked on label Dec 11, 2021
@JasonStoltz JasonStoltz added pinned and removed wontfix This will not be worked on labels Dec 13, 2021
@cpebble
Copy link

cpebble commented May 2, 2024

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.

@yansavitski
Copy link
Contributor

yansavitski commented May 3, 2024

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?

@cpebble
Copy link

cpebble commented May 24, 2024

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?

Yeah; the Key prop works. I just wanted to check up on whether you think this is worth fixing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants