你不会是程序猿吧?

percolator接口里的agg怎么用?

Elasticsearch | 作者 三斗室 | 发布于2016年03月11日 | 阅读数:4809

看文档看不懂。percolator接口不是一个一个文档的过query看是否match么?为啥又说也可以有aggs参数?对单条文档做aggs统计?
已邀请:

medcl - 今晚打老虎。

赞同来自: 三斗室

agg和highlight等操作都是作用于『percolator』存储的JSON,除了query,你还可以自己定义其他字段,所以和正常的agg操作一样,你可以对percolator的对象进行统计和高亮之类
PUT /medcl/.percolator/1
{
"query" : {
"match" : {
"message" : "bonsai tree"
}
},
"tag":"bonsai_tree"
}
PUT /medcl/.percolator/bonsai
{
"query" : {
"match" : {
"message" : "bonsai"
}
},"tag":"bonsai"
}

GET /medcl/type/_percolate
{
"doc" : {
"message" : "bonsai tree"
},
"aggs": {
"query" : {
"terms" : { "field" : "tag" }
}
}
,"highlight" : {
"pre_tags" : ["<pre>"],
"post_tags" : ["</pre>"],
"fields" : {
"message" : {}
}
},"size":10
}
{
"took": 44,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"total": 2,
"matches": [
{
"_index": "medcl",
"_id": "bonsai",
"highlight": {
"message": [
"<pre>bonsai</pre> tree"
]
}
},
{
"_index": "medcl",
"_id": "1",
"highlight": {
"message": [
"<pre>bonsai</pre> <pre>tree</pre>"
]
}
}
],
"aggregations": {
"query": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "bonsai",
"doc_count": 1
},
{
"key": "bonsai_tree",
"doc_count": 1
}
]
}
}
}

要回复问题请先登录注册