Elasticsearch涉及的RESTful API
2021-06-17 00:05
标签:plugins signed 命令 状态 搜索 number sig start count 被 标记的部件含义: PROTOCOL HOST PORT PATH QUERY_STRING BODY 往本地ES中写入一条数据,索引名称为"test_log-2018-10-24",类型名称为"test_log": 从本地ES中获取一条数据,索引名称为"test_log-2018-10-24",类型名称为"test_log",id名称为"AWalLVzvZ_iZW0h4u8UH": 删除刚才插入的数据: 注意:删除数据,不但针对单条数据,还可以使用通配符删除整个type乃至整个索引 局部更新 全文搜索 querystring语法(上例中,?q=后面写的就是querystring语法): 获取集群健康状态 获取节点状态 获取主节点状态 显示集群的详细信息 查看主节点 查看所有索引 查看单节点健康状态 查看分片信息 查看插件信息 Elasticsearch涉及的RESTful API 标签:plugins signed 命令 状态 搜索 number sig start count 原文地址:http://blog.51cto.com/fengjicheng/2348019一、格式
curl -X
VERB
适当的 HTTP 方法 或 谓词 : GET、 POST、 PUT、 HEAD 或者 DELETE。
http 或者 https(如果你在 Elasticsearch 前面有一个 https 代理)
Elasticsearch 集群中任意节点的主机名,或者用 localhost 代表本地机器上的节点。
运行 Elasticsearch HTTP 服务的端口号,默认是 9200 。
API 的终端路径(例如 _count 将返回集群中文档数量)。Path 可能包含多个组件,例如:_cluster/stats 和 _nodes/stats/jvm 。
任意可选的查询字符串参数 (例如 ?pretty 将格式化地输出 JSON 返回值,使其更容易阅读)
一个 JSON 格式的请求体 (如果请求需要的话)二、API类型
1.数据写入(POST)
curl -XPOST http://127.0.0.1:9200/test_log-2018-10-24/test_log -d ‘{
"date":"1540369436",
"user":"test",
"mesg":"this is a test message"
}‘
#返回:
{"_index":"test_log-2018-10-24","_type":"test_log","_id":"AWalLVzvZ_iZW0h4u8UH","_version":1,"result":"created","_shards":{"total":1,"successful":1,"failed":0},"created":true}
2.数据获取(GET)
curl -XGET http://127.0.0.1:9200/test_log-2018-10-24/test_log/AWalLVzvZ_iZW0h4u8UH
#返回
{"_index":"test_log-2018-10-24","_type":"test_log","_id":"AWalLVzvZ_iZW0h4u8UH","_version":1, "found":true,"_source":{
"date":"1540369436",
"user":"test",
"mesg":"this is a test message"
}}
3.数据删除(DELETE)
curl -XDELETE http://127.0.0.1:9200/test_log-2018-10-24/test_log/AWalLVzvZ_iZW0h4u8UH
#返回
{"found":true,"_index":"test_log-2018-10-24","_type":"test_log","_id":"AWalLVzvZ_iZW0h4u8UH","_version":2,"result":"deleted","_shards":{"total":1,"successful":1,"failed":0}}
例如:curl -XDELETE ‘http://127.0.0.1:9200/*-${DATA}‘
三、常用API
1._update
curl -XPOST ‘http://127.0.0.1:9200/test_log-2018-10-24/test_log/AWalXZ4cZ_iZW0h4vlQj/_update‘ -d ‘{
"doc":{
"user":"fjc"
}
}‘
#返回
{"_index":"test_log-2018-10-24","_type":"test_log","_id":"AWalXZ4cZ_iZW0h4vlQj","_version":2,"result":"updated","_shards":{"total":1,"successful":1,"failed":0}}
2._search
curl -XGET http://127.0.0.1:9200/test_log-2018-10-24/test_log/_search?q=test
curl -XGET http://127.0.0.1:9200/test_log-2018-10-24/test_log/_search?q=mesg:test
全文检索:直接写搜索的单词,例如加上例中的test
单字段的全文检索:在搜索单词前加上字段名和冒号,比如,如果知道单词test肯定出现在mesg字段,可以写作mesg:test
单字段的精确检索:在搜索单词前后加上双引号,比如user:"fjc"
多个检索条件的组合:可以使用NOT、AND和OR来组合检索,注意必须是大写
字段是否存在:exists:user表示要求user字段存在,missing:user表示要求user字段不存在
通配符:用?表示单字母,*表示任意个字母
近似搜索:用~表示搜索单词可能有一两个字母写得不对,请Elasticsearch按照相似度返回结果。比如test~
范围搜索:对数值和时间,Elasticsearch都可以使用范围搜索,比如:rtt>300、date:["now-6h" TO "now"}等。其中,[]表示端点数值包含在范围内,{}表示端点数值不包含在范围内3._cluster
curl -XGET ‘http://127.0.0.1:9200/_cluster/health?pretty‘
Enter host password for user ‘logview‘:
{
"cluster_name" : "idca-elk",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 141,
"active_shards" : 277,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
curl -XGET ‘http://127.0.0.1:9200/_cluster/state/nodes?pretty‘
Enter host password for user ‘logview‘:
{
"cluster_name" : "idca-elk",
"nodes" : {
"xSTX8HulT7eLrHtx8dpVbg" : {
"name" : "elk02",
"ephemeral_id" : "iql7vwvBSWSyx7PrsUMAGg",
"transport_address" : "172.16.1.26:9300",
"attributes" : { }
},
"gvlGkHa9QcyIsz31PjyZaw" : {
"name" : "elk03",
"ephemeral_id" : "9Gxyu9XrSSGNIPWKDAsfpw",
"transport_address" : "172.16.1.27:9300",
"attributes" : { }
},
"GVf_Yo-9RBW9_oUrqIPOZw" : {
"name" : "elk01",
"ephemeral_id" : "ZjAUQHGYS0KUMT1iiGS4Jg",
"transport_address" : "172.16.1.25:9300",
"attributes" : { }
}
}
}
Enter host password for user ‘logview‘:
{
"cluster_name" : "idca-elk",
"master_node" : "GVf_Yo-9RBW9_oUrqIPOZw"
}
curl -XGET ‘http://127.0.0.1:9200/_cluster/stats?human&pretty‘
4._cat
curl -XGET ‘http://127.0.0.1:9200/_cat/master?pretty&v‘
Enter host password for user ‘logview‘:
id host ip node
GVf_Yo-9RBW9_oUrqIPOZw 172.16.1.25 172.16.1.25 elk01
curl -XGET ‘http://127.0.0.1:9200/_cat/indices?v‘
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open apache-2018-10-26 bksy7QOCQQyHcBazjB5TEg 5 1 443452 0 259.4mb 129.7mb
green open user_audit-2018-10-26 41PM-4WpRJ6Evhar0dREsA 5 1 95 0 575.2kb 287.6kb
green open domain_log-2018-10-24 d8zG7XL3RtyvyqAIJp7GvQ 5 1 11307735 0 11.4gb 5.7gb
curl -XGET ‘http://127.0.0.1:9200/_cat/health?v‘
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1540530477 13:07:57 idca-elk green 3 3 277 141 0 0 0 0 - 100.0%
curl -XGET ‘http://127.0.0.1:9200/_cat/shards?v‘
index shard prirep state docs store ip node
domain_log-2018-10-22 3 r STARTED 1975611 1gb 172.16.1.27 elk03
domain_log-2018-10-22 3 p STARTED 1975611 1gb 172.16.1.25 elk01
domain_log-2018-10-22 2 p STARTED 1979052 1gb 172.16.1.26 elk02
curl -XGET ‘http://127.0.0.1:9200/_cat/plugins?v
文章标题:Elasticsearch涉及的RESTful API
文章链接:http://soscw.com/index.php/essay/94799.html