1. 前言

profile API 是 Elasticsearch 5.x 的一个新接口。通过这个功能,可以看到一个搜索聚合请求,是如何拆分成底层的 Lucene 请求,并且显示每部分的耗时情况。

2. profile API 使用

可以通过在 query 部分上方提供 “profile: true” 来启用Profile API

GET /ljjtest/book/_search
{
"profile":"true",
"query":{
"match":{
"author":"鲁迅"
}
}
}

3. profile API响应说明

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.3728157,
"hits": [ ... ]
},
"profile": {
"shards": [
{
"id": "[0mFoaNASRaGO050a_a28gA][ljjtest][0]",
"searches": [
{
"query": [
{
"type": "BooleanQuery",
"description": "author:鲁 author:迅",
"time": "0.5203070000ms",
"time_in_nanos": 520307,
"breakdown": {
"score": 18400,
"build_scorer_count": 1,
"match_count": 0,
"create_weight": 213200,
"next_doc": 28200,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 3,
"score_count": 2,
"build_scorer": 260500,
"advance": 0,
"advance_count": 0
},
"children": [
{
"type": "TermQuery",
"description": "author:鲁",
"time": "0.3040070000ms",
"time_in_nanos": 304007,
"breakdown": {
"score": 9100,
"build_scorer_count": 1,
"match_count": 0,
"create_weight": 118200,
"next_doc": 14500,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 3,
"score_count": 2,
"build_scorer": 162200,
"advance": 0,
"advance_count": 0
}
},
{
"type": "TermQuery",
"description": "author:迅",
"time": "0.1005070000ms",
"time_in_nanos": 100507,
"breakdown": {
"score": 2600,
"build_scorer_count": 1,
"match_count": 0,
"create_weight": 63500,
"next_doc": 2200,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 3,
"score_count": 2,
"build_scorer": 32200,
"advance": 0,
"advance_count": 0
}
}
]
}
],
"rewrite_time": 327100,
"collector": [
{
"name": "CancellableCollector",
"reason": "search_cancelled",
"time": "0.04830000000ms",
"time_in_nanos": 48300,
"children": [
{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time": "0.03680000000ms",
"time_in_nanos": 36800
}
]
}
]
}
],
"aggregations": []
}
]
}
}

Profile API响应说明:

上面的响应显示的是单个分片。每个分片都被分配一个唯一的ID,ID的格式是[nodeID][indexName][shardID]。现在在"shards"数组里还有另外三个元素,它们是:

  • query
  • rewrrite_time
  • collector

Query

Query 段由构成Query的元素以及它们的时间信息组成。Profile API结果中Query 部分的基本组成是:

  • type —— 它向我们显示了哪种类型的查询被触发。此处是布尔值。因为多个关键字匹配查询被分成两个布尔查询。
  • description —— 该字段显示启动查询的lucene方法。这里是 "author:鲁 author:迅"
  • time —— lucene 执行此查询所用的时间。单位是毫秒。
  • time_in_nanos —— lucene 执行此查询所用的时间。单位是微秒。
  • breakdown —— 有关查询的更详细的细节,主要与lucene参数有关。
  • children —— 具有多个关键字的查询被拆分成相应术语的布尔查询,每个查询都作为单独的查询来执行。每个子查询的详细信息将填充到Profile API输出的子段中。在上面的章节中,可以看到第一个子元素查询是"鲁",下面给出查询时间和其他breakdown参数等详细信息。同样,对于第二个关键字,有一个名为"迅"的子元素具有与其兄弟相同的信息。从查询中的子段中,我们可以得到关于哪个搜索项在总体搜索中造成最大延迟的信息。

Rewrite Time

由于多个关键字会分解以创建个别查询,所以在这个过程中肯定会花费一些时间。将查询重写一个或多个组合查询的时间被称为“重写时间”。(以纳秒为单位)。

Collectors

在Lucene中,收集器是负责收集原始结果,收集和组合结果,执行结果排序等的过程。例如,在上面的执行的查询中,当查询语句中给出size:0时,使用的收集器是"totalHitCountCollector"。这只返回搜索结果的数量(search_count),不返回文档。此外,收集者所用的时间也一起给出了。


参考:https://it.baiked.com/elasticsearch/1795.html
        </div>

最新文章

  1. spring maven pom.xml设置
  2. GIT和SVN之间的五个基本区别
  3. asp.net MVC动态路由
  4. 【活动】不用买书,不用花钱,可以免费看HTML5入门连载了
  5. Netlog 的数据库及 LAMP 架构
  6. Mac环境下装node.js,npm,express
  7. 指针强转和void*
  8. firefly笔记一之http模块
  9. WampServer修改MySQL密码
  10. 3_Guess Fingers
  11. PyQt5安装目录中找不到designer.exe与pyrcc5.exe
  12. 什么是MVC ?
  13. 工作中EF遇到的问题
  14. spark之JDBC开发(连接数据库测试)
  15. MachineLN博客目录
  16. web项目部署以及放到ROOT目录下
  17. How to do conditional auto-wiring in Spring?
  18. SpringBoot(十二):springboot2.0.2写测试用例
  19. Go语言标准库之JSON编解码
  20. python day 06 作业

热门文章

  1. bzoj5130: [Lydsy1712月赛]字符串的周期
  2. TP5.x——聊天列表查询
  3. [LnOI2019]长脖子鹿省选模拟赛 东京夏日相会
  4. 5.13会话技术Cookie---Session
  5. Javascrpt核心概念(2)--操作符
  6. 前端Canvas思维导图笔记
  7. 如何写出高性能SQL语句(文章摘自web开发者)
  8. Assembly之example
  9. Glitch-free clock switch
  10. (转)OpenLayers3基础教程——OL3基本概念