#1创建测试索引
DELETE http://192.168.208.32:9200/domo
POST http://192.168.208.32:9200/domo
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"users": {
"properties": {
"userId": {
"type": "string",
"index": "not_analyzed"
},
"createdTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"infos": {
"_parent": {
"type": "users"
},
"properties": {
"age": {
"type": "integer",
"index": "not_analyzed"
},
"nickname": {
"type": "string"
}
}
}
}
}
#3插入数据
POST http://192.168.208.32:9200/domo/users/_bulk
{ "index": { "_id": "1" }}
{ "userId": "user1", "createdTime": 1465381643502}
{ "index": { "_id": "2" }}
{ "userId": "user2", "createdTime": 1465381643502}
{ "index": { "_id": "3" }}
{ "userId": "user3", "createdTime": 1465381643502}
POST http://192.168.208.32:9200/domo/infos/_bulk
{ "index": { "parent": "1"}}
{ "age": 23, "nickname": "易小凡"}
{ "index": { "parent": "2" }}
{ "age": 24, "nickname": "Jimmy"}
{ "index": { "parent": "3" }}
{ "age": 24, "nickname": "Elastic"}
#4进行查询验证: 根据child查parent
GET http://192.168.208.32:9200/domo/infos/_search
{
"query": {
"has_parent": {
"type": "users",
"query": {
"match": {
"userId": "user1"
}
}
}
},
"aggs": {
"ageAgg": {
"histogram": {
"field": "age",
"interval": 1
}
}
}
}
#5进行查询验证: 根据parent查child
GET http://192.168.208.32:9200/domo/users/_search
{
"query": {
"has_child": {
"type": "infos",
"query": {
"match": {
"age": 24
}
}
}
},
"aggs": {
"createdAgg": {
"date_histogram": {
"field": "createdTime",
"interval": "month"
}
}
}
}
转载于:https://my.oschina.net/jimmywa/blog/689803