curl -X<VERB> ‘<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>‘ -d ‘<BODY>‘
被 < > 标记的部件:
VERB | 适当的 HTTP 方法 或 谓词 : GET`、 `POST`、 `PUT`、 `HEAD 或者 `DELETE`。 |
PROTOCOL | http 或者 https`(如果你在 Elasticsearch 前面有一个 `https 代理) |
HOST | Elasticsearch 集群中任意节点的主机名,或者用 localhost 代表本地机器上的节点。 |
PORT | 运行 Elasticsearch HTTP 服务的端口号,默认是 9200 。 |
PATH | API 的终端路径(例如 _count 将返回集群中文档数量)。Path 可能包含多个组件,例如:_cluster/stats 和 _nodes/stats/jvm 。 |
QUERY_STRING | 任意可选的查询字符串参数 (例如 ?pretty 将格式化地输出 JSON 返回值,使其更容易阅读) |
BODY | 一个 JSON 格式的请求体 (如果请求需要的话) |
curl -XGET ‘http://localhost:9200/_count?pretty‘ -d ‘ { "query": { "match_all": {} } } ‘
缩写格式显示:
GET /_count { "query": { "match_all": {} } }
创建雇员1:megacorp为索引名称(相当于database),employee为类型名称(相当于table)
PUT /megacorp/employee/1 { "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] }
搜索雇员1的详细信息:
GET /megacorp/employee/1
获取所有雇员:
GET /megacorp/employee/_search
获取姓氏为Smith的雇员:
GET /megacorp/employee/_search?q=last_name:Smith
用查询表达式,获取姓氏为Smith的雇员:
GET /megacorp/employee/_search { "query" : { "match" : { "last_name" : "Smith" } } }
GET /megacorp/employee/_search { "query" : { "bool": { "must": { "match" : { "last_name" : "smith" } }, "filter": { "range" : { "age" : { "gt" : 30 } } } } } }
GET /megacorp/employee/_search { "query" : { "match" : { "about" : "rock climbing" } } }
高亮搜索:
GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } }, "highlight": { "fields" : { "about" : {} } } }
聚合搜索:
GET /megacorp/employee/_search { "aggs": { "all_interests": { "terms": { "field": "interests" } } } }
参考文献:ElasticSearch权威指南
原文:https://www.cnblogs.com/parent-absent-son/p/10104230.html