emilly
emilly

Reputation: 10530

Elastic search for caching and searching the product?

I need to design the feature like in ecommerce(consider hotel booking site) we can enter the keyword/partial-keyword and need to return the relevant results. For Example :- If site admin or hotel owner needs to add the below hotel details in system , It will be added in cache also(basically it will be write through cache).

Hotel-Name: New River       
City: NewYork         
Rating:4 Star
Rate($):500

My question is how to design the below points in the system

  1. Do I need to store the Hotel data in cache as key value pair may be using Redis or Memcache ? What will be the key and value ?
  2. If I store it as key value pair, how will I serach using partial keyword(like entering river newyork instead of new river newyork) which can be combination of partial hotel name and city?
  3. What can be possible sharded key to distribute the data in cache ?

Consider this system as scalable as Goibibo .

My proposed solution :-

After reading below two resources, looks like I can use Elastic search(ES) for all three points mentioned above. What it will do is :-

  1. Create the index with name say hotel_data which will contain index on all searchable fields of hotel json document
  2. ES will store the index in memory
  3. Then I can search partial words like search partial words

Links

elasticsearch-from-the-bottom-up

elasticsearch-hello-world-example

But when I discussed this approach with CTO, he told you are mixing elastic search and elastic cache and said elastic search can be used for search and elastic cache for caching .

But when I again re- read those resources, I found elastic search is used for both caching and searching. So I found nothing wrong in my approach. Is there something in my approach ?

Upvotes: 4

Views: 1517

Answers (1)

Santhosh S
Santhosh S

Reputation: 792

Elasticsearch can be used as cache or an searchengine. By default elasticsearch index data is persistent (filesystem), you can also configure it for memorymap

Refer below for various File system storage Types https://www.elastic.co/guide/en/elasticsearch/reference/6.3/index-modules-store.html

ElastiCache is an in-memory data store service provided by Amazon (AWS) which you can use for caching.

Your proposed solution of selecting Elasticsearch is a good choice since its open source it can be used on-premise or you can use cloud services. Elasticsearch would give your more control over your search compared to caching frameworks like Redis.

You can do more complex searches like giving custom Weights based on your keywords and search a result. e.g. For your case search for Hotels, you can create any possible filters flexibly like Pricing Class, With Parking, With Balcony...etc.

But the main thing is you need to build the index from your datasource and the index would serve your site. Where as in cache your cache is getting build whenever you make queries to datasources.

Upvotes: 2

Related Questions