Please propose a better way to import selected MySQL tables to Elasticsearch using Logstash or similar latest way with examples.
I already did the same successfully using my Own PHP script directly without more issue. My sample methods are following,
public function createIndex($index){
$params = [
'index' => $index,
'body' => [
'settings' => [
'max_result_window' =>2147483647
]
]
];
$client= $this->getClient();
if(!$this->exists($index)){
$client->indices()->create($params);
}
}
function getDataType($type){
$temp=array();
switch($type){
case 'int':{
$temp['type']= 'integer';
break;
}
case 'bigint':{
$temp['type']= 'long';
break;
}
case 'varchar':{
$temp['type']= 'string';
$temp['analyzer']= 'standard';
break;
}
case 'double':{
$temp['type']= 'double';
break;
}
case 'datetime':{
$temp['type']= 'date';
$temp['format']= 'yyyy-MM-dd HH:mm:ss';
break;
}
case 'timestamp':{
$temp['type']= 'date';
$temp['format']= 'yyyy-MM-dd HH:mm:ss';
break;
}
case 'time':{
$temp['type']= 'date';
$temp['format']= 'HH:mm:ss';
break;
}
case 'date':{
$temp['type']= 'date';
$temp['format']= 'yyyy-MM-dd';
break;
}
default :{
$temp['type']= 'string';
$temp['analyzer']= 'standard';
break;
}
}
return $temp;
}
function sinzTable($index,$table){
$reuarray=$this->moData->descTable($table);
$myField1=array();
$tempField=array();
foreach ($reuarray as $key=>$val){
$tempField=$this->getDataType(strtok($val['Type'],'('));
$myField1[$val['Field']]=$tempField;
}
$this->createType($index, $table, $myField1);
}
function sinzData($index,$table){
$client= $this->getClient();
$data=$this->moData->selectAll($table);
foreach($data as $row){
$client->index([
'index'=>$index,
'type'=>$table,
'body'=>$row
]);
}
}