Elasticsearch
@Affiliate Window
Richard He
Team Falcon
A transaction report used by tens of thousands of
users every day that took too long to load
Our problem
Near real-time latency
Really fast aggregations
Accessible individual transaction records
Flexible
Scalable
What we wanted
The solution - Producing
The solution -Consuming
When shit hits the fan
Next steps
A good architect maximises the number of
decisions NOT made
by Uncle Bob Martin
New data fields can be added with almost no work
Average response time is <200ms
Easy to scale by just adding nodes
REST API
Why Elasticsearch
Things that are good to know…
Transaction Log - Refresh - Flush
1.x – fsync every 5 seconds
2.x – on request (default) / fsync every 5 seconds
Transaction log durability
"refresh_interval" : "-1”
"refresh_interval" : ”1s”
"refresh_interval" : ”15s"
Refresh interval
A refresh makes data searchable and a refresh interval decides how often
that happens
Filters vsQueries (v 1.7)
A filter askes yes / no questions, a query ask how well does this document
match
76ms 1385ms
Filters vsQueries
Disable analysed field if not needed
Use a filter if a query is not required
DocValues
Set a smaller heap size (4-16G on a 64G machine)
More RAM is now available for File System Cache
Enabled by default in version 2
Does not work with analysed field
On-disk data structure that allows fast aggregation without JVM Heap
overhead
Aggregations are approximate
Wrong!
The solution
Size = 0
The cost
Split Brain
M
4
52
1
1
2
3
4 5
M
2
M
4 5
M
2
M
4 5
1
2
M
4
5
Doc values
https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html
https://www.elastic.co/guide/en/elasticsearch/guide/current/_deep_dive_on_doc_values.html
Aggregation
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
Update Index settings
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
Important config changes
https://www.elastic.co/guide/en/elasticsearch/guide/1.x/_important_configuration_changes.html
https://www.elastic.co/guide/en/elasticsearch/guide/current/translog.htmlhttps://github.com/elastic/elasticsearch/issues/11287
Transaction log
https://www.elastic.co/guide/en/elasticsearch/guide/current/translog.html
https://github.com/elastic/elasticsearch/issues/11287
Resources
Questions

Elasticsearch at AffiliateWindow