世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :index_prefixes有什么特点?
答 :
问 :index_prefixes如何使用?
答 :
# index_prefixes
PUT /index_prefixes_test
{
"mappings" : {
"properties" : {
"name" : {
"type" : "text",
"index_prefixes" : {
"min_chars" : 1,
"max_chars" : 10
},
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
}
}
}
}
# 索引
POST /index_prefixes_test/_doc/1
{
"name" : "hello good"
}
# 索引
POST /index_prefixes_test/_doc/2
{
"name" : "hello"
}
# 搜索
GET /index_prefixes_test/_search
{
"query" : {
"prefix" : {
"name" : {
"value" : "goo"
}
}
}
}
# 结果
{
"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" : "index_prefixes_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "hello good"
}
}
]
}
}
# 搜索,keyword没有index_prefixes配置,但是可以使用prefix查询
GET /index_prefixes_test/_search
{
"query" : {
"prefix" : {
"name.keyword": {
"value" : "hello "
}
}
}
}
# 结果
{
"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" : "index_prefixes_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "hello good"
}
}
]
}
}