Skip to content

Instantly share code, notes, and snippets.

@spinscale
Created July 9, 2014 11:26
Show Gist options
  • Save spinscale/34c9768a619bf55e15e3 to your computer and use it in GitHub Desktop.
Save spinscale/34c9768a619bf55e15e3 to your computer and use it in GitHub Desktop.
# GET ES
# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.zip
# Unzip it
# unzip elasticsearch-1.2.1.zip
# cd elasticsearch-1.2.1
# Look around
# Show structure
# Show elasticsearch.yml
# Show logging.yml
# bin/plugin -i elasticsearch/marvel/latest
# Start
# bin/elasticsearch
# Create index
DELETE /articles
PUT /articles
# show data in filesystem
PUT /articles/book/1
{
"author" : [ "Clinton Gormley" ],
"title" : "Elasticsearch - The definitive guide",
"publisher" : "Oreilly",
"meta" : {
"pages" : 213
}
}
GET /articles/book/1
DELETE /articles/book/1
# Update, different JSON, different HTTP header
PUT /articles/book/1
{
"author" : "Clinton Gormley",
"title" : "Elasticsearch - The definitive guide",
"publisher" : "O'Reilly",
"pages" : 234,
"price" : 29.99
}
PUT /articles/book/2
{
"author" : "Alexander Reelsen",
"title" : "Play Framework Cookbook",
"publisher" : "Packt Publishing",
"pages" : 416,
"price" : 29.99
}
DELETE /articles/book/2
# Mapping
GET articles/_mapping
# Versioning
GET /articles/book/1
PUT /articles/book/1?version=1
{
"author" : "Clinton Gormley",
"title" : "Elasticsearch - The definitive guide",
"publisher" : "O'Reilly",
"pages" : 234,
"price" : 29.99
}
# Updates
POST /articles/book/1/_update
{
"doc" : {
"author" : [ "Clinton Gormley", "Zachary Tong" ]
}
}
GET /articles/book/1
POST /articles/book/1/_update
{
"script" : "ctx._source.author.add(author)",
"params" : {
"author" : "Zachary Tong"
}
}
GET /articles/book/1
# Mget
GET /_mget
{
"docs" : [
{
"_index" : "articles",
"_type" : "book",
"_id" : "1"
},
{
"_index" : "articles",
"_type" : "book",
"_id" : "2"
}
]
}
GET /articles/book/_mget
{
"ids" : [ "1", "2" ]
}
# Bulk API
POST /articles/book/_bulk
{ "index" : { "_id" : "3" }}
{ "title" : "Harry Potter", "author" : "Joanne K. Rowling" }
{ "delete" : {"_id" : "2" }}
{ "index" : {"_id" : "5" }}
{ "title" : "Hillary Rodham Clinton", "author" : "Hard Choices" }
# Search, explain all field
GET /_search?q=Clinton
GET /articles/_search?q=Clinton
GET /articles/book/_search?q=Clinton
# Search for field
GET /articles/book/_search?q=author:Clinton
# Search using query DSL
GET /articles/book/_search
{
"query": {
"match": {
"author": "Clinton"
}
}
}
GET /articles/book/_search
{
"query": {
"filtered": {
"query": {
"fuzzy": {
"author": "Clintn"
}
},
"filter": {
"range": {
"price": {
"from": 20,
"to": 40
}
}
}
}
}
}
# Across indices, across types
GET /articles,news/book,teaser/_search?q=Clinton&ignore_unavailable=true
# Show marvel and shard allocation of index
# Start another node, show shard allocation (show replay)
# Make sure everyone understood index, shard, primary shard, replica shard, master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment