Index API
Create an index (you can also just start indexing documents)
PUT /blog
{
"settings" :
{
"number_of_shards" : 3,
"number_of_replicas" : 1
},
"mappings" : ...
}
Get the mapping
GET /blog/_mapping/post
Send the mapping
PUT /blog
{
"mappings": {
"post" : {
"properties" : {
"title" : {
"type" : "string",
"analyzer": "english",
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"tag" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
Open and close index to update settings
POST /blog/_close
POST /blog/_open
Test analyzer token output by field
GET /blog/_analyze?field=title&text=powerful
Test analyzer token output by analyzer
GET /_analyze?analyzer=english&text=powerful
Index and update a document
PUT /blog/post/1
{
"title": "John smith is a very common name",
"body": "...",
"user": "foobar",
"tag": [
"awesome",
"smith"
]
}
Get a document
GET /blog/post/1
Delete a document
DELETE /blog/post/1
Add the foo alias on the blog index
PUT /blog/_alias/foo
List all indexes with alias foo
GET /*/_alias/foo
List all alias on index blog
GET /blog/_alias/*
Switch an alias in one command
POST /_aliases
{
"actions": [
{ "remove":
{ "index": "blog", "alias": "foo" }
},
{ "add":
{ "index": "blog_v2", "alias": "foo" }
}
]
}
Debug API
Get a detailed view of what a query do
GET /blog/post/_validate/query?explain
{
"query": {
"match": {
"title": "Smith"
}
}
}
Get explanation about a document match or not
GET /blog/post/1/_explain
{
"query": {
"match": {
"title": "Smith"
}
}
}
Get explanations about documents _score
GET /blog/post/_search?explain&pretty
{
"query": {
"match": {
"title": "Smith"
}
}
}
Search API
Simple query
GET /blog/post/_search
{
"query": {
"match": {
"title": "smith"
}
}
}
Complete search
Here is an example of very complex search with aggregation, highlight, filters, pagination, sort, source... All you can do!
GET /blog/post/_search
{
"highlight": {
"pre_tags" : [""],
"post_tags" : [""],
"fields": {
"body" : {},
"title": {}
}
},
"size": 20,
"from": 100,
"_source": ["title", "id"],
"sort": {
{ "post_date" : {"order" : "desc"}},
}
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match": {
"title": "smith"
}
}
],
"must_not": [
{
"match_phrase": {
"title": "granny smith"
}
}
]
}
},
"filter": {
"bool": {
"must_not": [
{
"missing": {
"field": "title"
}
}
]
}
}
}
},
"aggs": {
"my_agg": {
"terms": {
"field": "user",
"size": 10
}
}
}
}
Plugins
On debian the script is here: /usr/share/elasticsearch/bin/plugin
.
Install various plugins
./bin/plugin --install mobz/elasticsearch-head
./bin/plugin --install lmenezes/elasticsearch-kopf/1.2
./bin/plugin --install elasticsearch/marvel/latest
Remove a plugin
./bin/plugin --remove
List installed plugins
./bin/plugin --list
GET /_nodes?plugin=true