ES 常用 API 整理
文章目录
check if server is up:
1
curl 'http://localhost:9200/?pretty'
count the number of documents in the cluster:
1
curl -XGET 'http://localhost:9200/_count?pretty' $Payload
Index a document & put data:
1
curl -XPUT http://localhost:9200/megacorp/employee/1 -d '{"first_name":"Douglas","last_name":"Fir","age":35,"about":"I like to build cabinets","interests":["forestry"]}
retrieving a document:
1
curl http://localhost:9200/megacorp/employee/1
get all docs:
1
curl http://localhost:9200/megacorp/employee/_search
search query:
1
curl http://localhost:9200/megacorp/employee/_search\?q\=last_name:Smith
search with Query DSL:
1 2 3 4 5 6 7
{ "query": { "match": { "last_name": "Smith" } } }
highlight Searches with DSL:
1
curl -H "Content-Type: application/json" http://localhost:9200/megacorp/employee/_search -d '{"query":{"match_phrase":{"about":"rock climbing"}},"highlight":{"fields":{"about":{}}}}'
query with aggregations:
1
curl -H "Content-Type: application/json" http://localhost:9200/megacorp/employee/_search -d {"aggs":{"all_interests":{"terms":{"field":"interests"},"aggs":{"avg_age":{"avg":{"field":"age"}}}}}}
create a document, and not overwriting an existing one:
_create
get mapping info:
1
http://localhost:9200/megacorp/_mapping