There is no drop-in solution for Elasticsearch in order to get it set up for your website you will actually have to setup middleware to communicate with your database using one of Elasticsearch’s clients. (See here: https://www.elastic.co/guide/en/elasticsearch/client/index.html)
I’m no expert on the subject but I would set it up as follows.
- Elastic Search Server
- Hugo Website
*The middleware can be on it’s own server or on the same server as Elasticsearch using Apache or something similar. Again I’m not an expert in this field so IDK if putting them on the same server would be good or bad in the long run.
I’d create a simple API on the middle-ware server based on my needs. This is good since none of your Elasticsearch credentials get exposed to the client. They remain on that middleware server.
So basically the search process would be like this:
- Visitor types something Client-side (in search bar on the Hugo website)
- Hugo website uses AJAX (https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX) to send a request to middleware server
- Middleware server sends query based on the request to Elasticsearch
- Elasticsearch returns results to middleware server
- Middleware server spits out JSON based on the result and sends it back to the Hugo website
- Hugo website display results using the JSON.
Hopefully that helps you wrap your head around what would be involved.
Alternatives that don’t require users to download a large JSON file.
If this seems like too much work I recommend you check out these options.
Forestry made a tutorial about how to sync up your Hugo site with Algolia. See here: https://forestry.io/blog/search-with-algolia-in-hugo/?q=&hPP=10&idx=blog&p=0
It involves generating a JSON file for search, but it’s not for users to download in the browser. It’s sent to Algolia to update the database so it scales much better than Lunr for large indexes. After you sync things up you can use Algolia’s instantsearch.js libary on your hugo website to search for results in your index. https://community.algolia.com/instantsearch.js/v2/getting-started.html
Algolia is a SaaS but it has a generous free tier
A commercial product by elastic. It allows you to add search to your site with by pasting a bit of code. It starts at $79/month though