【发布时间】:2018-05-07 17:20:11
【问题描述】:
我想创建具有父子关系的文档。
我有如下数据,
parent_id = null 的父文档数据
{
"id": 1,
"workflow_name": "Diwali",
"list_name": "number",
"list_id": "798",
"msgType": "Promotional - National",
"sender_id": "MANISH",
"submit_date": "2017-11-06 14:09:56",
"dlrdatetime": "2017-11-06 14:10:06",
"split_count": 1,
"error_code": "Waiting",
"error_text": "-",
"currency_used": "0.2000",
"text_type": "text",
"error_code_status": null,
"origin_type": "1",
"api_response_id": 1,
"response": null,
"parent_id": null,
"is_test": 0,
"link": null,
"type": 2,
"message_text": "Hi This is text message",
"status": null,
"winner_branch": null,
"instance_id": "724e540394481746",
"created_at": "2017-11-06 14:10:06",
"updated_at": "2017-11-06 14:10:06",
"branch_id": 0
}
parent_id = 1 的子文档数据
{
"id": 1,
"workflow_name": "Diwali",
"list_name": "number",
"list_id": "798",
"msgType": "Promotional - National",
"sender_id": "MANISH",
"submit_date": "2017-11-06 14:09:56",
"dlrdatetime": "2017-11-06 14:10:06",
"split_count": 1,
"error_code": "Waiting",
"error_text": "-",
"currency_used": "0.2000",
"text_type": "text",
"error_code_status": null,
"origin_type": "1",
"api_response_id": 1,
"response": null,
"parent_id": 1,
"is_test": 0,
"link": null,
"type": 2,
"message_text": "Hi This is text message",
"status": null,
"winner_branch": null,
"instance_id": "724e540394481746",
"created_at": "2017-11-06 14:10:06",
"updated_at": "2017-11-06 14:10:06",
"branch_id": 0
}
所以我有一对多的关系,一个父母有很多孩子。
批量映射的示例代码sn-p:
$mapping['index'] = 'response_packets_index_v5';
$mapping['body'] = array(
'mappings' => array(
'response_packets_v5' => array(
'properties' => [
'id' => [
'type' => 'integer'
],
'workflow_id' => [
'type' => 'integer'
],
'parent_id' => [
'type' => 'integer',
],
'instance_id' => [
'type' => 'text'
],
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'branch_id' => [
'type' => 'integer'
]
]
)
)
);
$client->indices()->create($mapping);
批量索引的代码 sn-p:
for ($i = 0; $i <= $count; $i++) {
$params['body'][] = [
'index' => [
'_index' => 'response_packets_index_v5',
'_type' => response_packets_v5',
'routing' => 'company',
]
];
$params['body'][] = $documentData[$i];
}
return $client->bulk($params);
我已经阅读了这篇文章,但对我没有帮助:https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html
任何人都可以帮助我解决这个问题,非常感谢。
系统详情:
操作系统ubuntu 16.04,
PHP 7.1 版,
ES-PHP客户端6.0版
【问题讨论】:
-
Github 问题,same exact question 供参考。
标签: php elasticsearch