I'm working on an application which uses MySQL as its database. I am however adding a search function with autocomplete/"as-you-type results" which uses ElasticSearch. Getting the relevant data from MySQL to ElasticSearch is not a problem and my searches works fine.
I do however have som performance issues but only when making the "first" search query, which takes about 1-5 seconds. By "first" I mean the first search within a couple of minutes; a second search within 10 seconds after the first search gets near instant results, while a second search five minutes after the first gets the results only after a significant delay.
My initial thought was that setting up the HTTP connection (which is pooled by .NET Framework) was causing the extra delay but it seems strange that that would take 1-5 seconds on a fast LAN network when not even using a DNS name to resolve the ElasticSearch server.
Are there any other possible culprits/usual suspects I should be looking at? Or does the initial-HTTP-connection-delay seem reasonble (and what would I do about that?)?
Searching is done like this (note that the ElasticSearch/NEST client is managed as a singleton and is already created):
public IEnumerable<Person> Search(ElasticClient esclient, IEnumerable<string> queryParts, int groupId) {
// Make the search query and return the results.
return esclient.Search<Person>(s => s
.Query(q =>
q.Terms(p => p.FirstName, queryParts) ||
q.Terms(p => p.LastName, queryParts)
)
.Filter(f => f
.Term(p => p.MemberOfGroups, new int[] { groupId })
)
).Documents;
}
EDIT: My ElasticClient is created like this:
new ElasticClient(new ConnectionSettings(new Uri(esUrl), index));