[toc]
1. API 通用可选参数
1.1. 好看、格式化后果数据
- ?pretty=true 格式化为 json
- ?format=yaml 后果展现为 yml
- ?human=false 敞开 1h/1kb 等人性化转换
1.2 响应过滤:filter_path
1.2.1 响应过滤用法
原来申请:
GET /bank/_doc/1
原响应:
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 1001,
"_primary_term" : 1,
"found" : true,
"_source" : {
"account_number" : 1,
"balance" : 39225,
"firstname" : "Amber",
"lastname" : "Duke",
"age" : 32,
"gender" : "M",
"address" : "880 Holmes Lane",
"employer" : "Pyrami",
"email" : "amberduke@pyrami.com",
"city" : "Brogan",
"state" : "IL"
}
}
加上响应过滤:采纳 逗号分隔的过滤器列表
GET /bank/_doc/1?filter_path=_version,_source.firstname,_source.age,_source.balance
加上后的响应:
{
"_version" : 3,
"_source" : {
"balance" : 39225,
"firstname" : "Amber",
"age" : 32
}
}
1.2.2 响应过滤反对通配符 “*”
申请:
# 响应过滤
GET /bank/_doc/1?filter_path=_version,_source.*name,_source.age,_source.*e
响应:
{
"_version" : 3,
"_source" : {
"balance" : 39225,
"firstname" : "Amber",
"lastname" : "Duke",
"age" : 32,
"state" : "IL"
}
}
原响应参考上边 1.2.1 所列;
1.2.3 响应过滤: 排除字段 “-“
申请:
GET /bank/_doc/1?filter_path=-_type,-_source
过滤后响应:
{
"_index" : "bank",
"_id" : "1",
"_version" : 3,
"_seq_no" : 1001,
"_primary_term" : 1,
"found" : true
}
可见,_type
字段和 _source
节点,都被排除掉了;
1.2.4 响应过滤:*- 混用时, 先排除, 再过滤
例 1:
GET /bank/_doc/1?filter_path=_version,_source.*name,_source.age,_source.*e,-_source
后果:
{"_version" : 3}
例 2:
GET /bank/_doc/1?filter_path=_version,_source.*name,_source.age,_source.*e,-_source.lastname
后果:
{
"_version" : 3,
"_source" : {
"balance" : 39225,
"firstname" : "Amber",
"age" : 32,
"state" : "IL"
}
}
1.3 工夫单位
2d
for 2 days
d |
Days |
---|---|
h |
Hours |
m |
Minutes |
s |
Seconds |
ms |
Milliseconds |
micros |
Microseconds |
nanos |
Nanoseconds |
1.4 字节单位
b |
Bytes |
---|---|
kb |
Kilobytes |
mb |
Megabytes |
gb |
Gigabytes |
tb |
Terabytes |
pb |
Petabytes |
1.5 打印谬误堆栈形迹:error_trace=true
看上面 3 个输入
GET /library/_search?size=1&filter_path=hits.hits._source
{
"hits" : {
"hits" : [
{
"_source" : {
"title" : "Book #1",
"rating" : 200.1
}
}
]
}
}
这个是正确时的输入.
咱们传个谬误参数 size=Y
GET /library/_search?size=Y&filter_path=hits.hits._source
输入:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Failed to parse int parameter [size] with value [Y]"
}
],
"type": "illegal_argument_exception",
"reason": "Failed to parse int parameter [size] with value [Y]",
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: \"Y\""
}
},
"status": 400
}
上面再看个残缺堆栈信息的形式: error_trace
GET /library/_search?size=Y&filter_path=hits.hits._source&error_trace=true
outpu:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Failed to parse int parameter [size] with value [Y]",
"stack_trace": "[Failed to parse int parameter [size] with value [Y]]; nested: IllegalArgumentException[Failed to parse int parameter [size] with value [Y]]; nested: NumberFormatException.........."
}
],
"type": "illegal_argument_exception",
"reason": "Failed to parse int parameter [size] with value [Y]",
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: \"Y\"","stack_trace":"java.lang.NumberFormatException: For input string: \"Y\"\n\tat java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)................"},"status": 400
}
…….. 省去了很多输入信息!