ELK,萌萌哒

ES5.6.4中数值类型的term查询类型应该是TermQuery还是PointRangeQuery

Elasticsearch | 作者 zhangg7723 | 发布于2018年12月14日 | 阅读数:3988

      最近拜读吴大神之前的一篇文章number?keyword?傻傻分不清楚,文章详细解析了数值类型在Lucene6.0中的查询和存储,包括term查询和range查询。其中有一节分析数值类型term查询慢的原因,提到数值型字段的TermQuery被转换为了PointRangeQuery。我在自己的环境做了一个简单的测试并远程DEBUG,发现没有出现PointRangeQuery类型的查询。不知道是我理解错误还是测试用例有问题。
测试用例:
{
"from": 0,
"size": 10,
"profile": true,
"query": {
"bool": {
"filter": [
{
"terms": {
"rowKey": [
"201803023990375518829f2c15a01214647835"
]
, "boost": 1.0
}
}, {
"terms": {
"msg_type": [
2,
3
]
, "boost": 1.0
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
}
 
 其中rowKey为String类型,  msg_type为integer类型。
 
 
profile查询结果:
{
"id": "[ZBP_rofAShe6QkHoxIO0ow][hik_mac_index_info-2018030100-2018030200][0]",
"searches": [{
"query": [{
"type": "BooleanQuery",
"description": "#ConstantScore(rowKey:201803023990375518829f2c15a01214647835) #msg_type:{1 3}",
"time": "26.50874300ms",
"time_in_nanos": 26508743,
"breakdown": {
"score": 115,
"build_scorer_count": 2,
"match_count": 0,
"create_weight": 55373,
"next_doc": 3294,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 2,
"score_count": 1,
"build_scorer": 26449955,
"advance": 0,
"advance_count": 0
},
"children": [{
"type": "ConstantScoreQuery",
"description": "ConstantScore(rowKey:201803023990375518829f2c15a01214647835)",
"time": "0.2549140000ms",
"time_in_nanos": 254914,
"breakdown": {
"score": 0,
"build_scorer_count": 4,
"match_count": 0,
"create_weight": 27506,
"next_doc": 1703,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 2,
"score_count": 0,
"build_scorer": 225698,
"advance": 0,
"advance_count": 0
},
"children": [{
"type": "TermQuery",
"description": "rowKey:201803023990375518829f2c15a01214647835",
"time": "0.1888600000ms",
"time_in_nanos": 188860,
"breakdown": {
"score": 0,
"build_scorer_count": 4,
"match_count": 0,
"create_weight": 16734,
"next_doc": 1200,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 2,
"score_count": 0,
"build_scorer": 170919,
"advance": 0,
"advance_count": 0
}
}]
},
{
"type": "",
"description": "msg_type:{1 3}",
"time": "26.11104000ms",
"time_in_nanos": 26111040,
"breakdown": {
"score": 0,
"build_scorer_count": 4,
"match_count": 0,
"create_weight": 2930,
"next_doc": 0,
"match": 0,
"create_weight_count": 1,
"next_doc_count": 0,
"score_count": 0,
"build_scorer": 26107594,
"advance": 509,
"advance_count": 2
}
}]
}],
"rewrite_time": 121798,
"collector": [{
"name": "CancellableCollector",
"reason": "search_cancelled",
"time": "0.02026900000ms",
"time_in_nanos": 20269,
"children": [{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time": "0.01027800000ms",
"time_in_nanos": 10278
}]
}]
}],
"aggregations": []
}

可以看到rowKey字段的查询类型是TermQuery,但是msg_type并没有说明是什么类型,而且通过DEBUG并没有走PointRangeQuery的相关代码,只走了TermQuery。所以感到疑惑,而且msg_type字段的build_scorer的时间确实比较长。
希望大神们能给指点一下。
已邀请:

要回复问题请先登录注册