How to "reuse" last search results for searching a more easy sentence?

I am developing a application which needs to search word by word in a sentence but searching first the complete sentence, then the complete sentence without the last word, and so on.
For example, i have the sentence "Searches for files and media" and i want that my application shows something like this in the same view/page:

Results for "Searches":
Here goes the results
Results for "for":
...
Results for "files":
...
...
Results for "Searches for":
...
Results for "Searches for files":
...
...
Results for "Searches for files and media":
...

Note: Each search is of type "phrase".
There is a way to make this type of search using Elasticsearch in a unique query or reusing(for example with Memoization) previous results(discarding results that don't match and searching where have been found previous matches)?

Named queries is kind of that way, though that is really more useful if you want to get a single list of results back and say "this matched these two queries" rather than have an independent result list for all of the queries.

If you want individual lists you can use _msearch but that doesn't do any memoizing beyond caching filters. The portions of the indices needed to service the query will be pulled into ram by the OS only one time per shard, but that'll happen if you issue the queries in order. You could use preference to push the queries to one shard - you'd want a random preference to make sure you didn't overload any shards.

I'd just try it and see what performance you got. If these are term searches I expect them to be fast enough any way. If these are phrase searches they'll be slower but maybe good enough for you. If it isn't we can cross that bridge when we come to it.

1 Like

Ok thanks for your answer. Maybe it is a feature that require a more powerful infraestructure(servers). It takes too much time to load results so i have reconsidered that feature.