http://localhost:5601/app/kibana#/dev_tools/console?_g=()
user:pwd elastic/changeme
PUT /customer?pretty
GET /_cat/indices?v
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
GET /customer/external/1?pretty
PUT /customer
PUT /customer/external/1
{
"name": "John Doe"
}
GET /customer/external/1
DELETE /customer
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
PUT /customer/external/2?pretty
{
"name": "Sam Stint"
}
CURL Hit
curl -X POST "http://<$ES_HOST>/INDEX_NAME/OPERATION?conflicts=proceed&wait_for_completion=false" -H 'Content-Type: application/json' -d'
{
ES_QUERY
}'
POST /customer/external/1/_update?pretty
{
"doc": { "name": "Jane Doe" }
}
POST /customer/external/1/_update?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
POST /customer/external/2/_update?pretty
{
"doc": { "name": "Jane Doe2", "age": 20 }
}
POST /customer/external/1/_update?pretty
{
"script" : "ctx._source.age += 5"
}
DELETE /customer/external/2?pretty
#batch operation
POST /customer/external/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
POST /customer/external/_bulk?pretty
{"update":{"_id":"1"}}
{"doc":{"name":"John Doe becomes Jane Doe"}}
{"delete":{"_id":"2"}}
#Bank sample
accounts.json
{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880
Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
curl --user elastic:changeme -H
"Content-Type: application/json" -XPOST
'localhost:9200/bank/account/_bulk?pretty&refresh' --data-binary
"@accounts.json"
curl 'localhost:9200/_cat/indices?v' --user
elastic:changeme
GET /bank/_search?q=*&sort=account_number:asc&pretty
GET /bank/_search
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
GET /bank/_search
{
"query": { "match_all": {} },
"size": 2
}
GET /bank/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
GET /bank/_search
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"]
}
GET /bank/_search
{
"query": { "match": { "address": "mill lane" } }
}
GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
GET /bank/_search
{
"query": {
"bool": {
"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
GET /bank/_search
{
"query": {
"bool": {
"must_not": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}
Term query based search:
GET employee/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"name": {
"value": "John"
}
}
},
{
"term": {
"department": {
"value": "Sales"
}
}
}
]
}
}
}
GET /bank/_search
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": {
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
}
}
}
}
Find distinct values
GET /cars/transactions/_search?search_type=count
{
"aggs": {
"distinct_colors": {
"terms": {
"field": "color",
"size": 1000
}
}
}
}
More: https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_filters.html