世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
# search_as_you_type
PUT /search_as_you_type_test
{
"mappings" : {
"properties" : {
"my_search_as_you_type" : {
"type" : "search_as_you_type"
}
}
}
}
# 索引
POST /search_as_you_type_test/_doc?refresh
{
"my_search_as_you_type" : "hello good me"
}
# 搜索
GET /search_as_you_type_test/_search
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "search_as_you_type_test",
"_type" : "_doc",
"_id" : "QGedXHgBVbS9eSDZx-50",
"_score" : 1.0,
"_source" : {
"my_search_as_you_type" : "hello good me"
}
}
]
}
}
# 搜索 multi_match
GET /search_as_you_type_test/_search
{
"query" : {
"multi_match" : {
"query" : "go",
"type" : "bool_prefix",
"fields" : [
"my_search_as_you_type",
"my_search_as_you_type._2gram",
"my_search_as_you_type._3gram"
]
}
}
}
# 结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "search_as_you_type_test",
"_type" : "_doc",
"_id" : "QGedXHgBVbS9eSDZx-50",
"_score" : 1.0,
"_source" : {
"my_search_as_you_type" : "hello good me"
}
}
]
}
}
# 搜索 match_phrase_prefix
GET /search_as_you_type_test/_search
{
"query": {
"match_phrase_prefix" : {
"my_search_as_you_type" : "go"
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "search_as_you_type_test",
"_type" : "_doc",
"_id" : "QGedXHgBVbS9eSDZx-50",
"_score" : 0.2876821,
"_source" : {
"my_search_as_you_type" : "hello good me"
}
}
]
}
}