ElsaticSearch Curl

Basic Concepts

  • Cluster 集群
  • Node 节点
  • Index 索引(全部小写)
  • Type 索引类型
  • Document 文档
  • shards & Replics
  • cluster
GET /_cat/health?v
GET /_cat/nodes?v
GET /_cat/indices?v

index

curl -X PUT "localhost:9200/customer"
curl -X PUT "localhost:9200/customer/_doc/1" -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
'
curl -X GET "localhost:9200/customer/_doc/1"
curl -X DELETE "localhost:9200/customer"
curl -X DELETE "localhost:9200/customer/_doc/2?pretty"
curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"name": "John Doe12" }
{"index":{"_id":"2"}}
{"name": "Jane Doe22" , "age": 33}
{"index":{"_id":"3"}}
{"name": "Jane Doe22" , "age": 44}
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@accounts.json"

curl "localhost:9200/_cat/indices?v"

Search

curl -X GET "localhost:9200/bank/_search?q=*&sort=account_number:asc&pretty"
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": { "match_all": {} }, "sort": [{ "account_number": "asc" }]}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": { "match_all": {} },"from": 10,"size": 10}'
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": { "match_all": {} },"_source": ["account_number", "balance"]}'
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": { "match": { "account_number": 20 } }}'
# match mill or lane
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{"query": { "match": { "address": "mill lane" } }}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": { "match_phrase": { "address": "mill lane" } }}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": {"bool": {"must": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }]}}}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": {"bool": {"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }]}}}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": {"bool": {"must_not": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }]}}}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"query": {"bool":{
"must": { "match_all": {} },
"filter": {"range": {"balance": {"gte": 20000,"lte": 30000}}}
}}}'

Aggregation

curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"size": 0,"aggs": {
"group_by_state": {"terms": {"field": "state.keyword"
}}}}'
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{"size": 0,"aggs": {
"group_by_state": {"terms": {"field": "state.keyword"},
"aggs": {"average_balance": {"avg": {"field": "balance"
}}}}}}'
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{"size": 0,"aggs": {
"group_by_state": {"terms": {
"field": "state.keyword",
"order": {"average_balance": "desc"}},
"aggs": {"average_balance": {"avg": {"field": "balance"
}}}}}}'
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{"size": 0,"aggs": {
"group_by_age": {"range": {"field": "age","ranges": [{"from": 20,"to": 30},{"from": 30,"to": 40},{"from": 40,"to": 50}]},
"aggs": {"group_by_gender": {"terms": {"field": "gender.keyword"},
"aggs": {"average_balance": {"avg": {"field": "balance"
}}}}}}}}'

你可能感兴趣的:(ElsaticSearch Curl)