基于Thinkphp3导入数据mysql数据到Elasticsearch中

  1. 准备mysql数据

    基于Thinkphp3导入数据mysql数据到Elasticsearch中_第1张图片

  2导入数据代码

use Elasticsearch\ClientBuilder;
class ElasticsearchController extends Controller
{    private $client;
    // 构造函数
    public function __construct()
    {
        $params = array('127.0.0.1:9200');
        $this->client = ClientBuilder::create()->setHosts($params)->build();
        return $this->client;
    }
    // 创建索引
    public function create_index($index_name = 'haodanku')
    { // 只能创建一次
        $indexParams['index']  = $index_name;
        //$indexParams['type']  = "items";
        $indexParams['body']['settings']['number_of_shards']   = 3;
        $indexParams['body']['settings']['number_of_replicas'] = 2;
        $myTypeMapping = array(
            '_source' => array(

你可能感兴趣的:(基于Thinkphp3导入数据mysql数据到Elasticsearch中)