Elasticsearch is a distributed, RESTful search and analytics engine that allows for fast searching, filtering, and analysis of large volumes of data. It is document-based and stores structured and unstructured data in JSON documents within configurable indices. Documents can be queried using a simple query string syntax or more complex queries using the domain-specific query language. Elasticsearch also supports analytics through aggregations that can perform metrics and bucketing operations on document fields.
2. The Problem
• You are building a website to find beers
• You have a huge database of beers and
breweries to sift through
• You want simple keyword-based searching
• You also want structured searching, like finding
all beers > 7% ABV
• You want to run some analytics on what beers
are in your dataset
23. DSL = Query + Filter
• Query - “How well does the document
match”
• Filter - Yes or No question on the field
24. Query DSL
• match
• Used to query across all fields for a string
• match_phrase
• Used to query an exact phrase
• match_all
• Matches all documents
• multi_match
• Runs the same match query on multiple fields
25. Filter DSL
• term
• Exact match on a field
• range
• Match numbers over a specified range
• exists / missing
• Match based on the existence of a value
for a field
26. More Complex Search
• Find beer whose styles include “Pale
Ale” that are less than 7% ABV
31. Aggregations
• Collect analytics on your documents
• 2 main types
• Bucketing
• Produce a set of buckets with documents
in them
• Metric
• Compute metrics over a set of documents
33. Metric Aggregations
• How many beers exist of each style?
• What is the average ABV of beers for
each style?
• How many beers exist that are brewed
in California?
34. What is the average ABV of beers for each style?
curl -XGET 'http://localhost:9200/_search?pretty' -d '{
"aggs" : {
"all_beers" : {
"terms" : { "field" : "style" },
"aggs" : {
"avg_abv" : {
"avg" : { "field" : "abv" }
}
}
}
}
}'
35. Mappings
• Define how ES searches
• Completely optional
• Must re-index after defining mapping
39. Flexibility
• Mixing aggregations, filters and queries
all together
• What beers have the word “night” in
the name that are between 4 and 6 %
ABV, broken down by style.