世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :copy_to有什么特点?
答 :
问 :copy_to如何使用?
答 :
# copy_to
PUT /copy_to_test
{
"mappings" : {
"properties" : {
"first_name" : {
"type" : "text",
"copy_to" : "full_name"
},
"last_name" : {
"type" : "text",
"copy_to" : ["full_name", "extra_name"]
},
"full_name" : {
"type" : "text"
},
"extra_name" : {
"type" : "text"
}
}
}
}
# 索引
POST /copy_to_test/_doc/1
{
"first_name" : "hello",
"last_name" : "good"
}
# 搜索
GET /copy_to_test/_search
{
"query" : {
"match" : {
"full_name" : {
"query" : "hello good",
"operator" : "and"
}
}
}
}
# 结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.5753642,
"hits" : [
{
"_index" : "copy_to_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.5753642,
"_source" : {
"first_name" : "hello",
"last_name" : "good"
}
}
]
}
}
# 搜索
GET /copy_to_test/_search
{
"query" : {
"match" : {
"extra_name" : "good"
}
}
}
# 结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "copy_to_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"first_name" : "hello",
"last_name" : "good"
}
}
]
}
}