SlideShare a Scribd company logo
Created by - Amit Juneja
PART 1 - Overview and Real World
Applications
The Problem
● You are selling beer online
● You have a huge database of beers and brewreis ( Approx ~ 2
million )
● You want simple keyword based searching
● You also want structured searching
( All beers > 7% ABV )
● You want some real time analytics on how many beers are being
viewed and bought
Enter Elasticsearch
● Lucene Based
● Distributed
● Fast
● RESTful interface
● Document-Based with JSON
● Real Time search and analytics engine
● Open Source - Apache licence
● Platform Independent
Why not
Relational Database Management Systems (RDBMS) ?
● Full text search generally slower
● Cannot provide relevancy score for results
● Not suitable for unstructured data
● Limited partition tolerance ( cannot be distributed easily )
Elasticsearch - Basic Terminology
Real World Examples
Real World Use Case 1 - Dell
● Switched to Elasticsearch to index 27 million documents which contained product
information
● Dell uses two Elasticsearch cluster running on Windows server (.NET framework)
● Dell uses one cluster for searching and the other for analytics. The analytics cluster
has 1 billion documents with their site and product analytics
● Dell leveraged Elasticsearch’s real time feature to create a virtual assistant which
gives relevant suggestions based on partial keywords
Real World Use Case 1 - The Guardian
● Switched to Elasticsearch for realtime insight into audience engagement
● Every user with access privileges can see realtime traffic and viewership data for
stories on The Guardian which helps them modify content to attract more traffic
and get more exposure during peak rates
● The guardian processes 27 million documents per day with their in house analytics
system which consists of Elasticsearch at the core
● Dell leveraged Elasticsearch’s real time feature to create a virtual assistant which
gives relevant suggestions based on partial keywords
shardsMaster Client 1 Client 2
Inverted Index
Part 2 - Indexing, Updating and Deleting
Mapping in Elasticsearch
● Each index can have different types
● You can define the datatype of fields in a type with mapping
{
“sample_index” : {
“mappings” : {
“sample_type1” : {
“properties” : {
“date_a_sample_field” : {
“type” : “date”,
“format” : “dateOptionalTime”
}
}
}
}
}
}
Data Types available in Elasticsearch
Mapping
● Core Types
○ String
○ Numeric
○ Date
○ Boolean
● Arrays
● Multi-fields
● Pre-defined fields ( _timestamp, _uid, _ttle )
Creating an Index
PUT /my_index_name
{
"settings": {
"number_of_replicas": 1,
"number_of_shards": 3,
"analysis": {},
"refresh_interval": "1s"
},
"mappings": {
"my_type_name": {
"properties": {
"title": {
"type": "text",
"analyzer": "english"
}
}
}
}
}
Update an Index Setting
PUT /my_index_name/_settings
{
"index": {
"refresh_interval": "-1",
"number_of_replicas": 0
}
}
Update Index mapping by adding a Field to
a Type
PUT /my_index_name/_mapping/my_type_name
{
"my_type_name": {
"properties": {
"tag": {
"type": "keyword"
}
}
}
}
Get Mapping and Settings
GET /my_index_name/_mapping
GET /my_index_name/_settings
Create a Document
POST /my_index_name/my_type_name
{
"title": "Elastic is funny",
"tag": [
"lucene"
]
}
Update a Document
PUT /my_index_name/my_type_name/12abc <This is the Document ID>
{
"title": "Elastic is funny",
"tag": [
"lucene"
]
}
Delete a Document
DELETE /my_index_name/my_type_name/12abc
Open / Close an Index to save
memory/CPU
POST /my_index_name/_close
POST /my_index_name/_open
Part 3 - Searching and Filtering
Search Scopes
GET /_search -d “...” ---> Entire cluster
GET /index_name/_search -d “...” ----> Just the index
GET /index_name/type_name/_search -d “...” ----> Just the type in the index
GET /_all/type_name/_search -d “...” ----> All type with name type_name in the cluster
GET /*/type_name/_search -d “...” ----> All type with name type_name in the cluster
GET /index_name_1,index_name_2/type_name_1,type_name_2/_search -d “...”
-----> the types in the indexes
Basic components of a Search request
● Query : Configures the best documents to return based on a score
● Size : Amount of documents to return
● From : Used to do pagination. Can be expensive since ES orders results.
Example - A value of 7 will return result from 8th result
● _source : The fields to return with the result
● Sort : Default or customized sorting for results
URL based search requests
GET /index_name/_search?from=7&size=5
GET /index_name/_search?sort=date:asc
GET /index_name/_search?sort=date:asc&q=title:elasticsearch
Components of a response from Search
{
"took": 1,
"timed_out": false,
"_shards":{
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits":{
"total" : 1,
"max_score": 1.3862944,
"hits" : [
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "0",
"_score": 1.3862944,
"_source" : {
"user" :
"kimchy",
"message":
"trying out Elasticsearch",
"date" :
"2009-11-15T14:12:12",
"likes" :
0
}
}
]
}
Query DSL
GET _search
{
"query": {
"match": {
"FIELD": "TEXT"
}
}
}
GET _search
{
"query": {
"match_all": {}
}
}
Filters
● Filters perform a simple YES/NO operation on the documents to form the result set
Example of a Query with filter
{
"query": {
"bool": {
"must": {
"match": {
"text": "quick brown fox"
}
},
"filter": {
"term": {
"status": "published"
}
}
}
Simple Queries / Filters
Term Query
{
"query": {
"term" : {
"user" : "Kimchy"
}
}
}
Terms Query
{
"query": {
"term" : { "user" :
["Kimchy", “Ash”] }
}
}
Multi Match
{
"query": {
"multi_match" : {
"query" : "lucene",
"fields" :
["title","tags"],
}
}
}
More Queries / Filters
Range Query
{
"query": {
"range" : {
"field_name" :{
"gte":"Value"}
}
}
}
Prefix query
{
"query": {
"prefix" : { "title" :
"elas"}
}
}
Wildcard query
{
"query": {
"wildcard" : {
"title" : "ba*r?",
}
}
}
bool Query
must Combine clauses with AND
must_not Combine clauses with binary NOT
should Combine clauses with binary OR
Aliases in Elasticsearch
● Grouping multiple indexes or a single index and
giving it an alias name for the purpose of
querying / searching
● Aliases can be used with a filter to create
multiple “views” of the same index
Create an Alias for single Index
POST /_aliases
{
"actions":
{
"add": {
"index": "my_index_name",
"alias": "alias_name_1",
}
}
}
Remove an Alias for single Index
POST /_aliases
{
"actions":
{
"remove": {
"index": "my_index_name",
"alias": "alias_name_1",
}
}
}
Create an Alias for multiple Indicies
POST /_aliases
{
"actions":
{
"add": {
"indices": ["my_index_name","my_index_name2"]
"alias": "alias_name_1",
}
}
}
Create an Alias for multiple Indicies with
wildcard
POST /_aliases
{
"actions":
{
"add": {
"index": "my_index_name*"
"alias": "alias_name_1",
}
}
}
Create an Alias with filter term and routing value
POST /_aliases
{
"actions":
{
"add": {
"index": "my_index_name",
"alias": "bar",
"filter" : { "term" : { "customer_id" : "1" } }
"routing" : 1
}
}
}
Routing values can be used
To avoid unnecessary shard operations
They are added to the document automaticall
And will be added to the search query which is
Using the alias
Design Problem
Your application has multiple users and each user
has multiple subscriptions. Assume subscriptions
follow the same format more or less
What is the best way to design an elasticsearch
cluster for this type of problem?
Potential Designs
● Have an index per user and each user has subscription documents
Advantages
● Searches are fairly easy
● In line with relational database mentality
● Controlling shards and replica of each index gives us the advantage
of independent scaling
Disadvantages
● Too many shards!
● Waste of space as not all shards will have documents up to their
capacity
● Couple thousand customers can make elasticsearch unresponsive
Potential Designs…(contd)
● Single Index + Aliasing
Advantages
● No extra shards needed
Disadvantages
● Each shard will be hit when querying making queries slower
Best Solution
Single Index + Aliasing with Routing enabled
● Create alias for each customer in the single index
● Assign a routing key to each alias which is the same as customer
id
● Now each query hits only specific shards making queries really
fast

More Related Content

What's hot (20)

PPTX
Dbabstraction
Bruce McPherson
 
PDF
MongoDB and Schema Design
Matias Cascallares
 
PPT
Core Data Migration
Monica Kurup
 
PDF
Cubes 1.0 Overview
Stefan Urbanek
 
PDF
Data modeling for Elasticsearch
Florian Hopf
 
PDF
Elasticsearch 101 - Cluster setup and tuning
Petar Djekic
 
ODP
Indexed db
Martin Giger
 
PPTX
Lightning talk: elasticsearch at Cogenta
Yann Cluchey
 
PPT
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Cloudera, Inc.
 
PPTX
Google apps script database abstraction exposed version
Bruce McPherson
 
PDF
Tapping into Scientific Data with Hadoop and Flink
Michael Häusler
 
PDF
Starting with MongoDB
DoThinger
 
PDF
Sanjar Akhmedov - Joining Infinity – Windowless Stream Processing with Flink
Flink Forward
 
PDF
Analyze and visualize non-relational data with DocumentDB + Power BI
Sriram Hariharan
 
PPTX
ElasticSearch - Introduction to Aggregations
enterprisesearchmeetup
 
PDF
elasticsearch - advanced features in practice
Jano Suchal
 
PPTX
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
PPTX
Azure DocumentDB for Healthcare Integration
BizTalk360
 
KEY
Data Abstraction for Large Web Applications
brandonsavage
 
PDF
Cubes – ways of deployment
Stefan Urbanek
 
Dbabstraction
Bruce McPherson
 
MongoDB and Schema Design
Matias Cascallares
 
Core Data Migration
Monica Kurup
 
Cubes 1.0 Overview
Stefan Urbanek
 
Data modeling for Elasticsearch
Florian Hopf
 
Elasticsearch 101 - Cluster setup and tuning
Petar Djekic
 
Indexed db
Martin Giger
 
Lightning talk: elasticsearch at Cogenta
Yann Cluchey
 
Hadoop World 2011: Building Web Analytics Processing on Hadoop at CBS Interac...
Cloudera, Inc.
 
Google apps script database abstraction exposed version
Bruce McPherson
 
Tapping into Scientific Data with Hadoop and Flink
Michael Häusler
 
Starting with MongoDB
DoThinger
 
Sanjar Akhmedov - Joining Infinity – Windowless Stream Processing with Flink
Flink Forward
 
Analyze and visualize non-relational data with DocumentDB + Power BI
Sriram Hariharan
 
ElasticSearch - Introduction to Aggregations
enterprisesearchmeetup
 
elasticsearch - advanced features in practice
Jano Suchal
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
Azure DocumentDB for Healthcare Integration
BizTalk360
 
Data Abstraction for Large Web Applications
brandonsavage
 
Cubes – ways of deployment
Stefan Urbanek
 

Similar to Elasticsearch an overview (20)

PPTX
Elasticsearch
Ricardo Peres
 
PPTX
ElasticSearch for .NET Developers
Ben van Mol
 
PDF
Elasticsearch, a distributed search engine with real-time analytics
Tiziano Fagni
 
PPT
How ElasticSearch lives in my DevOps life
琛琳 饶
 
PDF
Lessons Learned While Scaling Elasticsearch at Vinted
Dainius Jocas
 
PPTX
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
PPTX
Elasticsearch
Anurag Srivastava
 
PPTX
Elastic search and Symfony3 - A practical approach
SymfonyMu
 
PPTX
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Pat Patterson
 
PDF
[2 d1] elasticsearch 성능 최적화
Henry Jeong
 
PDF
[2D1]Elasticsearch 성능 최적화
NAVER D2
 
ODP
Elastic Search
NexThoughts Technologies
 
PDF
Elasticsearch for Data Engineers
Duy Do
 
PPTX
About elasticsearch
Minsoo Jun
 
PDF
Introduction to Elasticsearch
Sperasoft
 
ZIP
CouchDB-Lucene
Martin Rehfeld
 
PDF
Complex realtime event analytics using BigQuery @Crunch Warmup
Márton Kodok
 
PDF
ElasticSearch in action
Codemotion
 
PDF
Using Elasticsearch for Analytics
Vaidik Kapoor
 
PPTX
Building a Scalable Inbox System with MongoDB and Java
antoinegirbal
 
Elasticsearch
Ricardo Peres
 
ElasticSearch for .NET Developers
Ben van Mol
 
Elasticsearch, a distributed search engine with real-time analytics
Tiziano Fagni
 
How ElasticSearch lives in my DevOps life
琛琳 饶
 
Lessons Learned While Scaling Elasticsearch at Vinted
Dainius Jocas
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
Elasticsearch
Anurag Srivastava
 
Elastic search and Symfony3 - A practical approach
SymfonyMu
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Pat Patterson
 
[2 d1] elasticsearch 성능 최적화
Henry Jeong
 
[2D1]Elasticsearch 성능 최적화
NAVER D2
 
Elastic Search
NexThoughts Technologies
 
Elasticsearch for Data Engineers
Duy Do
 
About elasticsearch
Minsoo Jun
 
Introduction to Elasticsearch
Sperasoft
 
CouchDB-Lucene
Martin Rehfeld
 
Complex realtime event analytics using BigQuery @Crunch Warmup
Márton Kodok
 
ElasticSearch in action
Codemotion
 
Using Elasticsearch for Analytics
Vaidik Kapoor
 
Building a Scalable Inbox System with MongoDB and Java
antoinegirbal
 
Ad

Recently uploaded (20)

PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Executive Business Intelligence Dashboards
vandeslie24
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Ad

Elasticsearch an overview

  • 1. Created by - Amit Juneja
  • 2. PART 1 - Overview and Real World Applications
  • 3. The Problem ● You are selling beer online ● You have a huge database of beers and brewreis ( Approx ~ 2 million ) ● You want simple keyword based searching ● You also want structured searching ( All beers > 7% ABV ) ● You want some real time analytics on how many beers are being viewed and bought
  • 4. Enter Elasticsearch ● Lucene Based ● Distributed ● Fast ● RESTful interface ● Document-Based with JSON ● Real Time search and analytics engine ● Open Source - Apache licence ● Platform Independent
  • 5. Why not Relational Database Management Systems (RDBMS) ? ● Full text search generally slower ● Cannot provide relevancy score for results ● Not suitable for unstructured data ● Limited partition tolerance ( cannot be distributed easily )
  • 6. Elasticsearch - Basic Terminology
  • 8. Real World Use Case 1 - Dell ● Switched to Elasticsearch to index 27 million documents which contained product information ● Dell uses two Elasticsearch cluster running on Windows server (.NET framework) ● Dell uses one cluster for searching and the other for analytics. The analytics cluster has 1 billion documents with their site and product analytics ● Dell leveraged Elasticsearch’s real time feature to create a virtual assistant which gives relevant suggestions based on partial keywords
  • 9. Real World Use Case 1 - The Guardian ● Switched to Elasticsearch for realtime insight into audience engagement ● Every user with access privileges can see realtime traffic and viewership data for stories on The Guardian which helps them modify content to attract more traffic and get more exposure during peak rates ● The guardian processes 27 million documents per day with their in house analytics system which consists of Elasticsearch at the core ● Dell leveraged Elasticsearch’s real time feature to create a virtual assistant which gives relevant suggestions based on partial keywords
  • 12. Part 2 - Indexing, Updating and Deleting
  • 13. Mapping in Elasticsearch ● Each index can have different types ● You can define the datatype of fields in a type with mapping { “sample_index” : { “mappings” : { “sample_type1” : { “properties” : { “date_a_sample_field” : { “type” : “date”, “format” : “dateOptionalTime” } } } } } }
  • 14. Data Types available in Elasticsearch Mapping ● Core Types ○ String ○ Numeric ○ Date ○ Boolean ● Arrays ● Multi-fields ● Pre-defined fields ( _timestamp, _uid, _ttle )
  • 15. Creating an Index PUT /my_index_name { "settings": { "number_of_replicas": 1, "number_of_shards": 3, "analysis": {}, "refresh_interval": "1s" }, "mappings": { "my_type_name": { "properties": { "title": { "type": "text", "analyzer": "english" } } } } }
  • 16. Update an Index Setting PUT /my_index_name/_settings { "index": { "refresh_interval": "-1", "number_of_replicas": 0 } }
  • 17. Update Index mapping by adding a Field to a Type PUT /my_index_name/_mapping/my_type_name { "my_type_name": { "properties": { "tag": { "type": "keyword" } } } }
  • 18. Get Mapping and Settings GET /my_index_name/_mapping GET /my_index_name/_settings
  • 19. Create a Document POST /my_index_name/my_type_name { "title": "Elastic is funny", "tag": [ "lucene" ] }
  • 20. Update a Document PUT /my_index_name/my_type_name/12abc <This is the Document ID> { "title": "Elastic is funny", "tag": [ "lucene" ] }
  • 21. Delete a Document DELETE /my_index_name/my_type_name/12abc Open / Close an Index to save memory/CPU POST /my_index_name/_close POST /my_index_name/_open
  • 22. Part 3 - Searching and Filtering
  • 23. Search Scopes GET /_search -d “...” ---> Entire cluster GET /index_name/_search -d “...” ----> Just the index GET /index_name/type_name/_search -d “...” ----> Just the type in the index GET /_all/type_name/_search -d “...” ----> All type with name type_name in the cluster GET /*/type_name/_search -d “...” ----> All type with name type_name in the cluster GET /index_name_1,index_name_2/type_name_1,type_name_2/_search -d “...” -----> the types in the indexes
  • 24. Basic components of a Search request ● Query : Configures the best documents to return based on a score ● Size : Amount of documents to return ● From : Used to do pagination. Can be expensive since ES orders results. Example - A value of 7 will return result from 8th result ● _source : The fields to return with the result ● Sort : Default or customized sorting for results
  • 25. URL based search requests GET /index_name/_search?from=7&size=5 GET /index_name/_search?sort=date:asc GET /index_name/_search?sort=date:asc&q=title:elasticsearch
  • 26. Components of a response from Search { "took": 1, "timed_out": false, "_shards":{ "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits":{ "total" : 1, "max_score": 1.3862944, "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "0", "_score": 1.3862944, "_source" : { "user" : "kimchy", "message": "trying out Elasticsearch", "date" : "2009-11-15T14:12:12", "likes" : 0 } } ] }
  • 27. Query DSL GET _search { "query": { "match": { "FIELD": "TEXT" } } } GET _search { "query": { "match_all": {} } }
  • 28. Filters ● Filters perform a simple YES/NO operation on the documents to form the result set
  • 29. Example of a Query with filter { "query": { "bool": { "must": { "match": { "text": "quick brown fox" } }, "filter": { "term": { "status": "published" } } }
  • 30. Simple Queries / Filters Term Query { "query": { "term" : { "user" : "Kimchy" } } } Terms Query { "query": { "term" : { "user" : ["Kimchy", “Ash”] } } } Multi Match { "query": { "multi_match" : { "query" : "lucene", "fields" : ["title","tags"], } } }
  • 31. More Queries / Filters Range Query { "query": { "range" : { "field_name" :{ "gte":"Value"} } } } Prefix query { "query": { "prefix" : { "title" : "elas"} } } Wildcard query { "query": { "wildcard" : { "title" : "ba*r?", } } }
  • 32. bool Query must Combine clauses with AND must_not Combine clauses with binary NOT should Combine clauses with binary OR
  • 33. Aliases in Elasticsearch ● Grouping multiple indexes or a single index and giving it an alias name for the purpose of querying / searching ● Aliases can be used with a filter to create multiple “views” of the same index
  • 34. Create an Alias for single Index POST /_aliases { "actions": { "add": { "index": "my_index_name", "alias": "alias_name_1", } } }
  • 35. Remove an Alias for single Index POST /_aliases { "actions": { "remove": { "index": "my_index_name", "alias": "alias_name_1", } } }
  • 36. Create an Alias for multiple Indicies POST /_aliases { "actions": { "add": { "indices": ["my_index_name","my_index_name2"] "alias": "alias_name_1", } } }
  • 37. Create an Alias for multiple Indicies with wildcard POST /_aliases { "actions": { "add": { "index": "my_index_name*" "alias": "alias_name_1", } } }
  • 38. Create an Alias with filter term and routing value POST /_aliases { "actions": { "add": { "index": "my_index_name", "alias": "bar", "filter" : { "term" : { "customer_id" : "1" } } "routing" : 1 } } } Routing values can be used To avoid unnecessary shard operations They are added to the document automaticall And will be added to the search query which is Using the alias
  • 39. Design Problem Your application has multiple users and each user has multiple subscriptions. Assume subscriptions follow the same format more or less What is the best way to design an elasticsearch cluster for this type of problem?
  • 40. Potential Designs ● Have an index per user and each user has subscription documents Advantages ● Searches are fairly easy ● In line with relational database mentality ● Controlling shards and replica of each index gives us the advantage of independent scaling Disadvantages ● Too many shards! ● Waste of space as not all shards will have documents up to their capacity ● Couple thousand customers can make elasticsearch unresponsive
  • 41. Potential Designs…(contd) ● Single Index + Aliasing Advantages ● No extra shards needed Disadvantages ● Each shard will be hit when querying making queries slower
  • 42. Best Solution Single Index + Aliasing with Routing enabled ● Create alias for each customer in the single index ● Assign a routing key to each alias which is the same as customer id ● Now each query hits only specific shards making queries really fast