大部分涉及到index的api接口都支持同事处理多个index,使用test1,test2(或者针对所有index的_all)。同时还支持通配符如:test*,t*st甚至可以使用添加+test*或者排除-test3。
日期数据支持
索引中可以有时间的各种信息https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html
公共选择
url中添加?pretty=true返回会信息更加友好。?format=yaml会使返回以yaml方式展示,更加可读。
统计信息返回也会有一些区别。?human=false(默认为false)展示为机器可读,如果设置为true,则会使可读性更好。
时间类型(https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html)
+1h 添加一小时
-1d 减少一天
/d 舍入到最近的一天
一些基本符号
y 年
M月
w星期
d天
h小时
H小时
m分钟
s秒
一些例子:
now+1h 当前时间添加一小时,使用毫秒
now+1h+1m 当前时间添加一小时一分钟,使用毫秒
now+1h/d 当前时间添加一小时,舍入到最近的一天
2015-01-01||+1M/d 2015-01-01添加一个月,舍入到最近的一天
响应过滤
rest full api接口,接受一些参数,可以减少返回的数据。这些参数使用圆点来拆分
如:
GET /_search?q=elasticsearch&filter_path=took,hits.hits._id,hits.hits._score
返回
{ "took" : 3, "hits" : { "hits" : [ { "_id" : "0", "_score" : 1.6375021 } ] } }
同样可以使用通配符*来筛选返回的列
GET /_cluster/state?filter_path=metadata.indices.*.stat*
{ "metadata" : { "indices" : { "twitter": {"state": "open"} } } }
使用通配符**可以忽略列的路径
GET /_cluster/state?filter_path=routing_table.indices.**.state
{ "routing_table": { "indices": { "twitter": { "shards": { "0": [{"state": "STARTED"}, {"state": "UNASSIGNED"}], "1": [{"state": "STARTED"}, {"state": "UNASSIGNED"}], "2": [{"state": "STARTED"}, {"state": "UNASSIGNED"}], "3": [{"state": "STARTED"}, {"state": "UNASSIGNED"}], "4": [{"state": "STARTED"}, {"state": "UNASSIGNED"}] } } } } }
同样可以使用-来排除一些列
GET /_count?filter_path=-_shards
{ "count" : 5 }
同样可以同时使用忽略某些列和展示某些列
GET /_cluster/state?filter_path=metadata.indices.*.state,-metadata.indices.logstash-*
{ "metadata" : { "indices" : { "index-1" : {"state" : "open"}, "index-2" : {"state" : "open"}, "index-3" : {"state" : "open"} } } }
flat_settings为true会使返回的数据平铺化
GET twitter/_settings?flat_settings=true返回
{ "twitter" : { "settings": { "index.number_of_replicas": "1", "index.number_of_shards": "1", "index.creation_date": "1474389951325", "index.uuid": "n6gzFZTgS664GUfx0Xrpjw", "index.version.created": ..., "index.provided_name" : "twitter" } } }
当为false的时候(默认为false)
{ "twitter" : { "settings" : { "index" : { "number_of_replicas": "1", "number_of_shards": "1", "creation_date": "1474389951325", "uuid": "n6gzFZTgS664GUfx0Xrpjw", "version": { "created": ... }, "provided_name" : "twitter" } } } }
所有传递的参数为boolean的时候,false,0,no,off会被解析为false,其他的都为true;同样数字类型也支持将字符串转化为数字。当时间长度需要设置的时候
d | day |
h | hours |
m | minutes |
s | seconds |
ms | milliseconds |
micros | microseconds |
nanos | nanoseconds |
空间大小设置(注意此处为1024进制,如1kb=1024bytes)
b | bytes |
kb | kilobytes |
mb | megabytes |
gb | gigabytes |
tb | terabytes |
pb | petabytes |
当没有后面限制符的时候为1000进制如7k为4000
k | kilo |
m | mega |
g | giga |
t | tera |
p | peta |
长度表示(具体查看https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#distance-units)
打印异常跟踪设置error_trace为true
POST /twitter/_search?size=surprise_me&error_trace=true