世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :fielddata有什么特点?
答 :
问 :fielddata如何使用?
答 :
# fielddata
PUT /fielddata_test
{
"mappings" : {
"properties" : {
"content" : {
"type" : "text",
"fielddata" : true
}
}
}
}
# 索引
POST /fielddata_test/_doc/1
{
"content" : "hello good"
}
# 搜索 - 聚合
GET /fielddata_test/_search
{
"aggs" : {
"content_aggs" : {
"terms": {
"field" : "content",
"size" : 10
}
}
}
}
# 结果
{
"took" : 195,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "fielddata_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"content" : "hello good"
}
}
]
},
"aggregations" : {
"content_aggs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "good",
"doc_count" : 1
},
{
"key" : "hello",
"doc_count" : 1
}
]
}
}
}