世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :completion的特点是什么?
答 :
问 :completion如何使用?
答 :
# completion
PUT /completion_test
{
"mappings" : {
"properties" : {
"my_suggest" : {
"type" : "completion",
"analyzer" : "standard"
}
}
}
}
# 索引
POST /completion_test/_doc
{
"my_suggest" : {
"input" : "hello",
"weight" : 10
}
}
POST /completion_test/_doc
{
"my_suggest" : {
"input" : "good",
"weight" : 10
}
}
POST /completion_test/_doc
{
"my_suggest" : {
"input" : "heme",
"weight" : 10
}
}
POST /completion_test/_doc
{
"my_suggest" : {
"input" : "heck",
"weight" : 30
}
}
# suggest
GET /completion_test/_search?pretty
{
"suggest" : {
"my_suggest_realtime" : {
"prefix" : "he",
"completion" : {
"field" : "my_suggest",
"size" : 2
}
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"suggest" : {
"my_suggest_realtime" : [
{
"text" : "he",
"offset" : 0,
"length" : 2,
"options" : [
{
"text" : "heck",
"_index" : "completion_test",
"_type" : "_doc",
"_id" : "OaYfQ3gBgXknW_r_aXUB",
"_score" : 30.0,
"_source" : {
"my_suggest" : {
"input" : "heck",
"weight" : 30
}
}
},
{
"text" : "hello",
"_index" : "completion_test",
"_type" : "_doc",
"_id" : "NqYfQ3gBgXknW_r_RnVP",
"_score" : 10.0,
"_source" : {
"my_suggest" : {
"input" : "hello",
"weight" : 10
}
}
}
]
}
]
}
}