2. Introduction
NoSQL database for indexing JSON contents
Documents are indexed as they are added (< 1s)
Schema-less (kind of…)
Distributed
High performance
REST semantics
Graph capabilities
Based on Lucene
Part of the ELK stack
Open source!
3. Cluster
A collection of servers (nodes) running
Elasticsearch
Single master
Multicast based discovery (can be explicit)
4. Shards
Indexes are distributed by shards – default is 5
shards and 1 replica (cluster)
Defined at index creation time
Transparent to the user
It is possible to define a hashing function
15. Query and Filter Context
Queries: scoring of the results
Filters determine what appears in the results
Are cached
16. Querying
Search API
Uses the URL
Starting with <index> and <type>
is optional
/<index>/<type>/_search?q=som
ething
/<index>/<type1>,<type2>/_sear
ch?q=something
_search?q=something
_search?q:field:value
_search?q=+firstname(john
mary)&-surname:smith
Query DSL
Query and filter context
simple_query_string,
query_string, match, term,
terms, range, multi_match,
match_phrase, missing,
exists, regexp, fuzzy, prefix,
ids
bool, dis_max
more_like_this, script,
template
17. Pagination, Sorting and Projection
size, from
sort
fields
POST website/post/_search
{
“size”: 10,
“from”: 0,
“sort”: {
“timestamp”: {
“order”: “desc”
}
},
“fields”: [ “title”, “_id” ]
}
18. Percolator
Search in reverse: first define the
query, then add documents to it
Querying a document gives all
percolator queries that it matches
19. Relations
No joins, but some alternatives
Parent/child: has_child, has_parent
Nested objects
Terms filter lookup: terms with type and id
22. Index Aliases
Used to refer to one or more indexes, one or more types, possibly with a filter
Useful for "moving indexes" (month, year, country, etc)
POST /_aliases
{
"actions" : [ {
"add" : {
"indices" : [ "social-2015", "social-2016" ],
"alias" : "social-testing",
"filter" : {
"term" : {
"tag" : "testing"
}
}
}
} ]
}
23. Alias Templates
Creates an alias when a type is created
POST /_template/social
{
"order": 0,
"template": "social-*",
"settings": {
"index": {
"refresh_interval": "5s"
}
},
"mappings": {},
"aliases": {
"social": {}
}
}