世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :doc_values有什么特点?
答 :
问 :doc_values如何使用?
答 :
# doc_values
PUT /doc_values_test
{
"mappings" : {
"properties" : {
"name1" : {"type" : "keyword"},
"name2" : {
"type" : "keyword",
"doc_values" : false
}
}
}
}
# 索引
POST /doc_values_test/_doc/1
{
"name1" : "hello",
"name2" : "good"
}
# 索引
POST /doc_values_test/_doc/2
{
"name1" : "good",
"name2" : "hello"
}
# 搜索
GET /doc_values_test/_search
{
"sort": [
{
"name1" : {
"order" : "desc"
}
}
],
"aggs": {
"agg_name1" : {
"terms": {
"field": "name1"
}
}
}
}
# 结果
{
"took" : 56,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "doc_values_test",
"_type" : "_doc",
"_id" : "1",
"_score" : null,
"_source" : {
"name1" : "hello",
"name2" : "good"
},
"sort" : [
"hello"
]
},
{
"_index" : "doc_values_test",
"_type" : "_doc",
"_id" : "2",
"_score" : null,
"_source" : {
"name1" : "good",
"name2" : "hello"
},
"sort" : [
"good"
]
}
]
},
"aggregations" : {
"agg_name1" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "good",
"doc_count" : 1
},
{
"key" : "hello",
"doc_count" : 1
}
]
}
}
}