您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch人类可读输出
发布时间:2021-08-25 23:08:56编辑:雪饮阅读()
在elasticSearch的api中,对于api输出其实是有分人类可读和机器可读的,这受制于human参数决定,若human=true则是人类可读。human=false则是机器可读。
下面这个是上次我们的profile性能测试api请求结果中的profile性能报告
"profile": {
"shards": [{
"id": "[qyWfA-ewRZe_ZLeMwNimGw][accountdetail-2021.08][0]",
"searches": [{
"query": [{
"type": "MatchAllDocsQuery",
"description": "*:*",
"time_in_nanos": 35300,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 1400,
"match": 0,
"next_doc_count": 1,
"score_count": 1,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 1700,
"advance_count": 1,
"score": 800,
"build_scorer_count": 2,
"create_weight": 2200,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 29200
}
}],
"rewrite_time": 1800,
"collector": [{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time_in_nanos": 8200
}]
}],
"aggregations": []
}]
}
我们可以看到这里有一个time_in_nanos,这个大概就是纳秒。
那么我们如果在请求上加上human=true如:
http://localhost:9200/<accountdetail-{now{YYYY.MM|+12:00}}>/_search?human=true get
请求体:
{
"profile": true
}
响应体:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "accountdetail-2021.08",
"_type": "type1",
"_id": "6",
"_score": 1.0,
"_source": {
"AccountID": "2021.08",
"bbq": "上次货币质入金额",
"PreFundMortgageOut": "上次货币质出金额",
"PreMargin": "上次占用的保证金",
"PreMortgage": "上次质押金额"
}
}
]
},
"profile": {
"shards": [
{
"id": "[qyWfA-ewRZe_ZLeMwNimGw][accountdetail-2021.08][0]",
"searches": [
{
"query": [
{
"type": "MatchAllDocsQuery",
"description": "*:*",
"time": "68.5micros",
"time_in_nanos": 68500,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 3100,
"match": 0,
"next_doc_count": 1,
"score_count": 1,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 6300,
"advance_count": 1,
"score": 3700,
"build_scorer_count": 2,
"create_weight": 13000,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 42400
}
}
],
"rewrite_time": 3900,
"collector": [
{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time": "44.1micros",
"time_in_nanos": 44100
}
]
}
],
"aggregations": []
}
]
}
}
这次你会发现在time_in_nanos之前又出一个字段"time": "68.5micros",这里就很明显了说是用了68.6毫秒,相对于纳秒,那样长的一串数字,人类一般不是很敏感,但是对于毫秒这种数据比较小,一眼过去,在片刻之间就能记住,类似这种就是人类可读输出。
类似的还有例如,如果human = true那么distance_kilometer = 20KM,如果human = false那么distance_meter = 20000,则是响应需要被另一个计算机程序使用。
所以具体可读输出的呈现方式根据不同的api有所不同,不过共同的就是让你看起来更通俗易懂点。
关键字词:elasticSearch,人类可读,human