ES 常用 API 整理
文章目录
check if server is up:
1curl 'http://localhost:9200/?pretty'count the number of documents in the cluster:
1curl -XGET 'http://localhost:9200/_count?pretty' $PayloadIndex a document & put data:
1curl -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:
1curl http://localhost:9200/megacorp/employee/1get all docs:
1curl http://localhost:9200/megacorp/employee/_searchsearch query:
1curl http://localhost:9200/megacorp/employee/_search\?q\=last_name:Smithsearch with Query DSL:
1 2 3 4 5 6 7{ "query": { "match": { "last_name": "Smith" } } }highlight Searches with DSL:
1curl -H "Content-Type: application/json" http://localhost:9200/megacorp/employee/_search -d '{"query":{"match_phrase":{"about":"rock climbing"}},"highlight":{"fields":{"about":{}}}}'query with aggregations:
1curl -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:
_createget mapping info:
1http://localhost:9200/megacorp/_mapping
