Refresh Search result without altering the state

Hi everyone
Is there any way I can refresh the search results without altering the search state, it would great if such feature would exist, As I tried to do it by exporting the SearchDriver but I didn't succeed.

Please this is a cry for help situation.

The search state should all be persisted to the URL, so refreshing the page will maintain the state.

1 Like

You’re saying that I should refresh the page. Can I refresh the results without refreshing the page??

Sorry, I think I misunderstood. Why do you want to refresh the search results without updating the search state, I don't think I understand.

Let me give you an example. I want to delete an item after a search has been made, when I delete that item I want the search results to update, so here I am not altering the search state I’m not adding anything just want the result to update. how can I do that without refreshing the page ?

Ah, got it.

  1. First, make sure "cacheResponses" is set to false on your App Search connector: App Search Connector | Elastic Docs
  2. Second, there is no explicit action to refresh, but you can refresh by calling setSearchTerm with the current searchTerm.

If you aren't already using the React API directly, you access these things through something like the WithSearch HOC: Connectors | Elastic Docs

<SearchProvider config={config}>
  <WithSearch
    mapContextToProps={({ searchTerm, setSearchTerm }) => ({
      searchTerm,
      setSearchTerm,
    })}
  >
    {({ searchTerm, setSearchTerm }) => (
      <div className="App">
        <button onClick={() => setSearchTerm(searchTerm)}></button>
      </div>
    )}
  </WithSearch>
</SearchProvider>

Hope that helps. I wish we had a better way to do this!

1 Like

That what I've been missing the cacheResponses attribute, you should really emphasise the use of this configuration attribute in your docs , as I didn't find any mention of it and its really a necessary attribute.

Thank you so much, you save my day.

That's good feedback, we will definitely do that, thank you!

1 Like

Perhaps that should be an opt-in optimization rather than an opt-out.

1 Like

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