Elastic Search is a search engine built on top of Lucene. Auto-complete capability can be built using Elastic Search as the data provider.

Setting up Elastic Search

Setting up Elastic Search is very simple.

  1. Download the zip file from Elastic site.
  2. Extract the zip file to a suitable folder.
  3. In the bin folder, run “service.bat install”.
  4. In the service manager, adjust the settings for the Elastic Service.
  5. If you encounter Java errors, install Java runtime (8) from Oracle website.
  6. Set the JAVA_HOME environment variable to point to JVM location. (path where bin folder is located)

Auto-complete using jQuery UI

The next step is to use jQuery UI to convert a textbox into an autocomplete widget. Please refer to an earlier post: Autocomplete textbox using jQuery. Please ensure that the path to the jQuery style bundle is nested to avoid any HTTP errors. With the autocomplete textbox all set, it is time to build the server API to fetch data from Elastic Search.

Fetching data from Elastic Search

The following code shows how to retrieve a list of localities from Elastic Search.

The location of Elastic server is http://localhost:9200. Data in Elastic is organized into indexes and types. A list of localities is retrieved from the “my-application” index and “localitydocument” type.

There are many ways to implement Autocomplete feature using Elastic. In this example, the Wildcard Query search is chosen. The Wildcard Query search has the least performance. But, it offers a quick and dirty way to show how Elastic can be used to setup an autocomplete textbox.

Indexing data to Elastic Search

Indexing data to Elastic search is fairly straight-forward.

A list of localities is indexed into the “my-application” index and “localitydocument” type. Indexing should be done by a console application or background service outside of the web application.

Auto-complete using Elastic Search as the provider
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *