您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch父子文档查询-所有文档与父文档
发布时间:2021-08-28 21:50:31编辑:雪饮阅读()
上篇了解到了elasticSearch父子关系索引中最后一环子文档的索引,那么接下来就是父子关系索引中文档的查询了。
首先看看当前父子关系索引中的所有文档
请求:
请求体:none
响应体:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "question1",
"_score": 1.0,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2200,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.3",
"my_join_field": {
"name": "question"
}
}
},
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "answer1",
"_score": 1.0,
"_routing": "question1",
"_source": {
"comment": "I am learning ELK",
"username": "Jack",
"my_join_field": {
"name": "answer",
"parent": "question1"
}
}
},
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "answer2",
"_score": 1.0,
"_routing": "question1",
"_source": {
"comment": "I am learning ELK",
"username": "Jack",
"my_join_field": {
"name": "answer",
"parent": "question1"
}
}
}
]
}
}
这里我后来又追加了一个answer2的子文档,那么从这个请求上面来看和普通的索引查询其所有文档是一样的(如:http://localhost:9200/schools/_search get 请求体:none)。这里my-index-000001就是索引名,就是前面我们创建的拥有父子级关系的索引的索引名。
那么接下来再来看看只看某个父文档
请求:
请求体:none
响应体:
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "question1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2200,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.3",
"my_join_field": {
"name": "question"
}
}
}
这里请求url中question1,就是之前创建的父文档的文档id了。其实这个看起来也是和前面查看普通文档的请求是一样的,如:
请求体:none
关键字词:elasticSearch,父子,所有文档,父文档