PHP Script for generate the data.
<?php
$mappings = '{
"mappings": {
"_doc": {
"properties": {
"id": {"type": "integer"},
"pipeline_id": {"type": "integer"},
"object_type": {"type": "text"},
"object_id": {"type": "integer"},
"phase_id": { "type": "integer" },
"contact_id": { "type": "integer" },
"org_id": { "type": "integer" },
"experience": { "type": "integer" },
"status": {"type": "integer"},
"created_at": {"type": "date"},
"updated_at": { "type": "date" },
"deleted_at": { "type": "date", "null_value": "NULL" }
}
}
}
}';
$indexs = ["contact_pipeline_histories_2019_09","contact_pipeline_histories_2019_10","contact_pipeline_histories_2019_11"];
foreach ($indexs as $index) {
//request($index,"DELETE", []);
request($index,"PUT", $mappings);
generate($index);
}
function generate($index)
{
$datas = [
'{"pipeline_id": 1,"object_id": 1,"object_type": "recruits","phase_id": 1,"contact_id": 1001,"status": 1,"created_at": "2019-03-15T05:00:00"}'
,
'{"pipeline_id": 1,"object_id": 1,"object_type": "recruits","phase_id": 1,"contact_id": 1001,"status": 2,"created_at": "2019-03-15T05:10:00"}'
,
'{"pipeline_id": 1,"object_id": 1,"object_type": "recruits","phase_id": 2,"contact_id": 1001,"status": 1,"created_at": "2019-03-15T05:10:00"}'
,
'{"pipeline_id": 1,"object_id": 2,"object_type": "recruits","phase_id": 4,"contact_id": 1002,"status": 1,"created_at": "2019-03-15T05:00:00"}'
,
'{"pipeline_id": 1,"object_id": 3,"object_type": "recruits","phase_id": 4,"contact_id": 1003,"status": 1,"created_at": "2019-03-15T05:00:00"}'
,
'{"pipeline_id": 1,"object_id": 3,"object_type": "recruits","phase_id": 4,"contact_id": 1003,"status": 1,"created_at": "2019-03-15T05:10:00"}'
,
'{"pipeline_id": 1,"object_id": 3,"object_type": "recruits","phase_id": 5,"contact_id": 1003,"status": 1,"created_at": "2019-03-15T05:10:00"}',
'{"pipeline_id": 1,"object_id": 3,"object_type": "recruits","phase_id": 7,"contact_id": 1003,"status": 1,"created_at": "2019-03-15T05:10:00"}'
];
$i = 0;
foreach ($datas as $data) {
$data = json_decode($data, true);
$data['id'] = $i++;
$data['org_id'] = 5663;
$data['experience'] = rand(1,2);
request("$index/_doc", "POST", $data);
}
}
function randomDate($sStartDate, $sEndDate, $sFormat = 'c') {
$fMin = strtotime($sStartDate);
$fMax = strtotime($sEndDate);
$fVal = mt_rand($fMin, $fMax);
return date($sFormat, $fVal);
}
function request($path, $method, $data)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "9200",
CURLOPT_URL => "http://localhost:9200/" . $path,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response . "\n";
}
}