Searching through a dataset can provide quite interesting challenges, especially when natural languages are involved. Elasticsearch is a very powerful yet also at times quite complex solution.
In this talk I'll give an intro on using Elasticsearch from within Ruby/Rails, discussing some of the general principles, starting with a simple example and then expanding into more complex topics such as multi-language search, search on data from multiple different objects, integration testing and production use.
32. Match Query
Multi Match Query
Bool Query
Boosting Query
Common Terms Query
Constant Score Query
Dis Max Query
Filtered Query
Fuzzy Like This Query
Fuzzy Like This Field Query
Function Score Query
Fuzzy Query
GeoShape Query
Has Child Query
Has Parent Query
Ids Query
Indices Query
Match All Query
More Like This Query
Nested Query
Prefix Query
Query String Query
Simple Query String Query
Range Query
Regexp Query
Span First Query
Span Multi Term Query
Span Near Query
Span Not Query
Span Or Query
Span Term Query
Term Query
Terms Query
Top Children Query
Wildcard Query
Minimum Should Match
Multi Term Query Rewrite
Template Query
33. And Filter
Bool Filter
Exists Filter
Geo Bounding Box Filter
Geo Distance Filter
Geo Distance Range Filter
Geo Polygon Filter
GeoShape Filter
Geohash Cell Filter
Has Child Filter
Has Parent Filter
Ids Filter
Indices Filter
Limit Filter
Match All Filter
Missing Filter
Nested Filter
Not Filter
Or Filter
Prefix Filter
Query Filter
Range Filter
Regexp Filter
Script Filter
Term Filter
Terms Filter
Type Filter
42. class Event < ActiveRecord::Base
include Elasticsearch::Model
index_name "drkpr_#{Rails.env}_events"
Index names with
environment
43. Test helpers
• everything is asynchronous!
• Helpers:
wait_for_elasticsearch
wait_for_elasticsearch_removal
clear_elasticsearch!
➜ https://gist.github.com/mreinsch/094dc9cf63362314cef4
• specs: Tag tests which require elasticsearch
44. Production ready?
• use elastic.co/found or AWS ES
• use two clustered instances for redundancy
• Elasticsearch could go away
• keep impact at a minimum!
• update Elasticsearch from background worker
45. Questions?
Resources:
Elastic Docs
https://www.elastic.co/guide/index.html
Ruby Gem Docs
https://github.com/elastic/elasticsearch-rails
Elasticsearch rspec helpers
https://gist.github.com/mreinsch/094dc9cf63362314cef4
Elasticsearch indexer job example
https://gist.github.com/mreinsch/acb2f6c58891e5cd4f13
or ask me later:
michael@movingfast.io
@mreinsch