Is Elasticsearch, Jamstack’s best friend?

Akshay Sura - Partner

25 Mar 2021

Share on social media

Is Elasticsearch, Jamstack’s best friend? I absolutely think it is. We spent a few months going through all the search solutions available on the market and tested them out.

Some stood out due to their out of the box capabilities. Overall when you take all aspects of owning a search application the only one which lasted our scrutiny was Elasticsearch.

We use Elastic Cloud which is the manages service on Azure.

Running a managed service gives you the peace of mind that the infrastructure is managed, one less this for you to do.

What this also gives you is that you are not limited to the number of calls. What we found restricting with so many of the other API-based Search solutions is the cost and the limit on calls.

We were running 2 - 3 million queries for a customer of ours a day! Imagine the cost of the API call based system.

Once your managed service is up, you can create indexes and push up data as JSON.

The documentation is phenomenal. You can browse through all the APIs: https://www.elastic.co/guide/index.html

The dev tools are great and let you prototype and work with your indexes and pretty much do anything you choose to.

Look at the speed, it took 2 milliseconds to pull 10,000 records. It is mind blowing.

You can auto scale and modify your deployment any time you choose.

Pushing content into an index is super simple using the Document APIs.

Here is some code in .NET Core:

using var client = new HttpClient(); var settings = new JsonSerializerSettings(); settings.ContractResolver = new ManipulateJsonFieldResolver(); client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("ElasticCloudBaseUrl")); client.DefaultRequestHeaders.Add("User-Agent", Environment.GetEnvironmentVariable("UserAgent")); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ElasticCloudAuthenticationType"), Environment.GetEnvironmentVariable("ElasticCloudAuthenticationToken")); var url = string.Format("/resellers/_doc/{0}", reseller.DealerNumber); StringContent content = new StringContent(JsonConvert.SerializeObject(reseller, Formatting.Indented, settings), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PutAsync(url, content); var resp = await response.Content.ReadAsStringAsync();

All we are doing is pushing up a serialized model. This model can contain all or some of the fields for the document as long as the identifier matches. You also do not need to create any schema before pushing up documents. You need to make sure there are no special characters in your JSON field names and they need to be lowercase.

You have access to a ton of field types and you can nest fields as well.

I have not been able to break the indexing yet, I pushed about 500,000 indexing requests in less than 3 mins, it broke my Azure Function limit though ;)

All in all, we are loving Elasticsearch and I think with it's API capability, Elasticsearch is truly Jamstack's friend.

If you have any questions, please get in touch with me. @akshaysura13 on Twitter or on Slack.

Follow us on Twitter

Follow us on LinkedIn

Follow us on YouTube


Sign up to our newsletter


Tags:

Jamstack
Elasticsearch

Share on social media

Akshay Sura

Akshay is an nine-time Sitecore MVP who has spent more than a decade working exclusively on Sitecore projects.

In addition to his work as a solution architect, Akshay is also one of the founders of SUGCON North America 2015, SUGCON India 2018 & 2019, Unofficial Sitecore Training, and the Sitecore Slack.

Akshay founded and continues to run the Sitecore Hackathon. As one of the managing partners of Konabos Consulting, Akshay will continue to work with clients to lead projects and mentor their existing teams.


Subscribe to newsletter