世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:filter有什么特点?
答:
问:filter如何使用?
答:
# 删除
DELETE /filter_test
# 映射
PUT /filter_test
{
"mappings": {
"properties": {
"name": {"type": "keyword"},
"type": {"type": "keyword"}
}
}
}
# 索引
POST /filter_test/_bulk?routing=1&refresh
{"index": {"_id": 1}}
{"name": "hello", "type": "t_1"}
{"index": {"_id": 2}}
{"name": "good", "type": "t_1"}
{"index": {"_id": 3}}
{"name": "me", "type": "t_1"}
{"index": {"_id": 4}}
{"name": "hello", "type": "t_1"}
{"index": {"_id": 5}}
{"name": "good", "type": "t_2"}
# 搜索
GET /filter_test/_search?size=0
{
"aggs": {
"filter_aggs": {
"filter": {
"term": {
"type": "t_1"
}
},
"aggs": {
"name_aggs": {
"terms": {
"field": "name"
}
}
}
}
}
}
# 结果
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"filter_aggs" : {
"doc_count" : 4,
"name_aggs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "hello",
"doc_count" : 2
},
{
"key" : "good",
"doc_count" : 1
},
{
"key" : "me",
"doc_count" : 1
}
]
}
}
}
}



