世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :field的对象和关系类型有哪些?
答 :object flattened nested join
问 : object 如何使用?
答 :
# object
# 配置项 :
# 1. dynamic : properties是否可以动态添加,默认true,选项 : true false strict
# 2. enabled : 是否分析和索引,默认true
# 3. properties : 指定对象的内部field
PUT /object_test
{
"mappings" : {
"properties" : {
"area" : {"type" : "keyword"},
"user" : {
"properties" : {
"age" : {"type" : "integer"},
"name" : {
"properties" : {
"first" : {"type" : "keyword"},
"last" : {"type" : "keyword"}
}
}
}
}
}
}
}
GET /object_test/_mapping
# 结果
{
"object_test" : {
"mappings" : {
"properties" : {
"area" : {
"type" : "keyword"
},
"user" : {
"properties" : {
"age" : {
"type" : "integer"
},
"name" : {
"properties" : {
"first" : {
"type" : "keyword"
},
"last" : {
"type" : "keyword"
}
}
}
}
}
}
}
}
}
POST /object_test/_doc
{
"area" : "China",
"user" : {
"age" : 13,
"name" : {
"first" : "hello",
"last" : "good"
}
}
}
GET /object_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" : "object_test",
"_type" : "_doc",
"_id" : "4Gvw23cBnJvha9PM8oxL",
"_score" : 1.0,
"_source" : {
"area" : "China",
"user" : {
"age" : 13,
"name" : {
"first" : "hello",
"last" : "good"
}
}
}
}
]
}
}