简体   繁体   中英

Cache the client connection with ElasticSearch Nest so the first call to the client is fast

I'm about to set up suggestion search for ElasticSearch with the NEST client. Ideally I'd start matching as of the 2nd character entered. However, it takes 600ms the first time I call the client. Every subsequent call is more like 20ms. Is there a way to cache or prepare the NEST client?

I've read this post: Elasticsearch and .NET

I've also read that I can either create a new client or use the same instance of the client with no repercussions.

I just want to get the client ready for use before I call it so the user isn't waiting for the client to validate itself.

For the moment I'm making a connection to the client as soon as the user hits the website, then saving the client reference in the session. However, the first search is still slow even though I've already established the connection. Is there a way to preload/cache the connection so the delay occurs during page load?

The first hit cache built up is per AppDomain. So you do not need to cache the client itself. Every client you are going to instantiate after the first hit is going to be warm .

I've opened up a working ticket so you are able to initiate the warmup process in your application startup so you are no longer penalizing the first user of your system with the warmup costs.

https://github.com/elasticsearch/elasticsearch-net/issues/742

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM