[英]In ElasticSearch ver_6.2.4, how large can scroll_size be?
[英]how to search child documents with the same parent id in Elasticsearch on ver_6.2.4?
从Elasticsearch 6.x开始,将父/子作为单独类型存储已替换为join
数据类型 。 这从根本上不会改变索引和查询这些文档的方式,但是会稍微改变语法。
注意:这组更改是为完全删除type
而准备的,这在7.x中发生
除了指定不同的类型,我们将创建一个join
指定字段branch_join
的所有文件。 relations
配置指定了父级->子级关系,键( branch
)为父级,值( employee
)为子级。
注意:为了示例,我使用名为organization
的索引
PUT _template/org_template
{
"index_patterns": ["organization"],
"settings": {
"number_of_shards": 2
},
"mappings": {
"_doc": {
"properties": {
"branch_join": {
"type": "join",
"relations": {
"branch": "employee"
}
}
}
}
}
}
索引父文档是相似的,但是我们需要通过在branch_join
字段中指定branch
来指定每个文档位于关系的哪一侧。
POST /organization/_doc/_bulk
{"index": {"_id": "london"}}
{"name": "London Westminster", "city": "London", "country": "UK", "branch_join": {"name":"branch"}}
{"index": {"_id": "liverpool"}}
{"name": "Liverpool Central", "city": "Liverpool", "country": "UK", "branch_join": {"name":"branch"}}
{"index": {"_id": "paris"}}
{"name": "Champs Élysées", "city": "Paris", "country": "France", "branch_join": {"name":"branch"}}
要为子级建立索引,我们需要做两件事:1.我们需要再次指定branch_join
字段,不仅要指定连接的哪一侧是( employee
),还需要指定父级的_id
要加入的文件。 2.为了确保子代与父代在同一分片上建立索引,我们将routing
参数设置为等于父代文档的_id
。
POST /organization/_doc/_bulk
{"index": { "_id": 1, "routing": "london"}}
{"name": "Alice Smith", "dob": "1970-10-24", "hobby": "hiking", "branch_join": {"name":"employee", "parent": "london"}}
{"index": { "_id": 2, "routing": "london"}}
{"name": "Mark Thomas", "dob": "1982-05-16", "hobby": "diving", "branch_join": {"name":"employee", "parent": "london"}}
{"index": { "_id": 3, "routing": "liverpool"}}
{"name": "Barry Smith", "dob": "1979-04-01", "hobby": "hiking", "branch_join": {"name":"employee", "parent": "liverpool"}}
{"index": { "_id": 4, "routing": "paris"}}
{"name": "Adrien Grand", "dob": "1987-05-11", "hobby": "horses", "branch_join": {"name":"employee", "parent": "paris"}}
该查询几乎是相同的,只是type
已更名为parent_type
以便更明确:
POST /organization/_search
{
"query": {
"has_parent": {
"parent_type": "branch",
"query": {
"ids": {
"values" : ["london"]
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.