How to cache default facets

Hi App Search Team,

I have a use case where I would like to show facets with a count against all the documents in an index at the initial app load.

The challenge is that my index can be large and the query can timeout as it tries to compute the facet values and their count values against all documents.

To overcome this challenge, I thought about caching my default facets that show approximate count values so that the facets can be loaded fast at the initial app load and let users refine their searches. (Displaying a default search results at the page load would be nice too, but that is optional)

I have reviewed the App Search documentation, but I didn't find any guidance on it so I wanted to ask the team here to see if there are any ways to achieve this.

So far, the 2 options that I have thought of so far are:

Option 1 - Introduce a constant helper field
For every documents in the index, introduce a constant helper and configure the App Search to include this field in the global filter. This will force the query to have a filter context that can in turn make Elasticsearch cache the query results. To warm up the cache, my server will issue the same query periodically or whenever changes are introduced to the index.

Option 2 - Build a custom server-side facet component
Build a custom facet component that fetches facet values server-side and retrieve values from my own system's cache or from Elasticsearch's Aggregation query that can be cached on Elasticsearch according to the official documentation.

Does any of these options make sense? Is there any other option that your team would recommend?

Thanks in advance for looking into this question and I am looking forward to hear your response!

Hey @wentaoxu-sf

Another option which requires minimal changes is to put a CDN in the middle like cloudflare. For the initial request, the same search call is called frequently. CDN will cache the first origin response re-serve the request for others. Then setting a reasonable stale timeout / pro-actively expiring the cache when an update is performed will keep data fresh.

Joe

Thanks for your response @joemcelroy. Utilizing CDN is an interesting alternative and it's something my team will have to give more consideration.

If we were limited to just utilizing the caching within Elasticsearch, are there any viable/easy options?

As an App Search + Search UI user, it would be great if there's a way to set a config somewhere in the App Search console or Search UI config to tell the engine to cache default or other specific requests.

The challenge is that my index can be large and the query can timeout as it tries to compute the facet values and their count values against all documents.

Is there some other optimization that you could make to try to solve this underlying performance issue? It seems like that query should not be timing out.

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