1. ElasticSearch安装

直接使用brew install elasticsearch 安装最新版本的es,基本没有障碍。

2.Laravel5 框架添加elasticsearch支持

在composer.json文件中添加elasticsearch-php依赖:

执行composer命令更新es代码加载到当前laravel框架中

  composer update

  laravel控制器中使用es

  use Elasticsearch\ClientBuilder;//引入
  $client = ClientBuilder::create()->build();//初始化
  $params = [
  'index' => 'my_index',
  'type' => 'my_type',
  'id' => 'my_id',
  'body' => ['testField' => 'abc']
  ];

  $response = $client->index($params);//添加索引
  print_r($response);

  $params = [
  'index' => 'my_index',
  'type' => 'my_type',
  'id' => 'my_id'
  ];

  $response = $client->get($params);//获取my_id对应的数据
  print_r($response);
实例:

  

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Elasticsearch\ClientBuilder;

class VideoController extends Controller
{
private $client;

public function __construct()
{
$this->client = ClientBuilder::create()->build();
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
for ($i=0;$i<5000;$i++) {
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id' . $i,
'body' => ['testField' => $i . '、Kitty,今天气很好!!!']
];
$response = $this->client->index($params);
}

dd($response);
}

/**
* Display the specified resource.
*
* @param string $str
* @return \Illuminate\Http\Response
*/
public function show($str='abc')
{
// $params = [
// 'index' => 'my_index',
// 'type' => 'my_type',
// 'id' => $id
// ];
$params = [
'index' => 'my_index',
'type' => 'my_type',
//"scroll" => "3s",
"from" => 0,
"size" => 100,
'body' => [
'query' => [
'match' => [
'testField' => $str,
]
]
]
];

$response = $this->client->search($params);
dd($response);
}

}

3. 实时导入插件go-mysql-elasticsearch

安装go环境,设置环境变量

  brew install go
  vi ~/.bash_profile 添加以下PATH和GOPATH,并在命令行中执行这两条命令
  export PATH=$PATH:/usr/local/Cellar/go/1.7.4_2/bin/
  export GOPATH=/Users/User/go

获取go-mysql-elasticsearch

  go get github.com/siddontang/go-mysql-elasticsearch

编译go-mysql-elasticsearch

  cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
  make

配置elasticsearch的etc目录下的river.toml

# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "192.168.0.1:3306"#mysql地址
my_user = "test"#用户名
my_pass = "test123"#密码

# Elasticsearch address
es_addr = "127.0.0.1:9200"#es安装地址

# Path to store data, like master.info, and dump MySQL data
data_dir = "./var"

# Inner Http status address
stat_addr = "127.0.0.1:12800"

# pseudo server id like a slave
server_id = 1001

# mysql or mariadb
flavor = "mysql"#mysql数据库

# mysqldump execution path
# if not set or empty, ignore mysqldump.
mysqldump = "mysqldump"

# MySQL data source
[[source]]
schema = "dev_cms"#数据库名称

# Only below tables will be synced into Elasticsearch.
# "test_river_[0-9]{4}" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023
# I don't think it is necessary to sync all tables in a database.
tables = ["test_content"]#数据表名称,可以多个

# Below is for special rule mapping
#[[rule]]
#schema = "test"
#table = "test_river"
#index = "river"
#type = "river"
# only MySQL field in filter will be synced
#filter=["title","tags"]
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
#[rule.field]
# This will map column title to elastic search my_title
#title="es_title"
# This will map column tags to elastic search my_tags and use array type
#tags="my_tags,list"
# This will map column keywords to elastic search keywords and use array type
#keywords=",list"

# wildcard table rule, the wildcard table must be in source tables
[[rule]]
schema = "dev_cms"#数据库名称
table = "test_content"#数据表名称
index = "es_dev_cms"#生成es数据索引名称,对应schema
type = "es_test_content"#生成es数据类型,对应table

# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
[[rule.fields]]
mysql = "title"
elastic = "es_title"

执行命令,导入数据

cd $GOPATH/src/github.com/siddontang/go-mysql-elasticsearch
./bin/go-mysql-elasticsearch -config=./etc/river.toml &

可以在谷歌浏览器安装sense插件查看es数据

有需要交流的小伙伴可以点击这里加本人QQ:luke

laravel5+ElasticSearch+go-mysql-elasticsearch MySQL数据实时导入(mac)的更多相关文章

  1. MySQL 到 ES 数据实时同步技术架构

    MySQL 到 ES 数据实时同步技术架构 我们已经讨论了数据去规范化的几种实现方式.MySQL 到 ES 数据同步本质上是数据去规范化多种实现方式中的一种,即通过"数据迁移同步" ...

  2. MySQL数据实时增量同步到Kafka - Flume

    转载自:https://www.cnblogs.com/yucy/p/7845105.html MySQL数据实时增量同步到Kafka - Flume   写在前面的话 需求,将MySQL里的数据实时 ...

  3. mysql数据实时同步到Elasticsearch

    业务需要把mysql的数据实时同步到ES,实现低延迟的检索到ES中的数据或者进行其它数据分析处理.本文给出以同步mysql binlog的方式实时同步数据到ES的思路, 实践并验证该方式的可行性,以供 ...

  4. elasticsearch+logstash_jdbc 实现mysql数据实时同步至es

    jdk安装1.8版本,es.ls.ik.kibana版本一致我这里使用的6.6.2版本 安装es tar xf elasticsearch-6.6.2.tar.gz mv elasticsearch- ...

  5. Mysql数据实时同步

    企业运维的数据库最常见的是 mysql;但是 mysql 有个缺陷:当数据量达到千万条的时候,mysql 的相关操作会变的非常迟缓; 如果这个时候有需求需要实时展示数据;对于 mysql 来说是一种灾 ...

  6. 基于netcore实现mongodb和ElasticSearch之间的数据实时同步的工具(Mongo2Es)

    基于netcore实现mongodb和ElasticSearch之间的数据实时同步的工具 支持一对一,一对多,多对一和多对多的数据传输方式. 一对一 - 一个mongodb的collection对应一 ...

  7. 基于Spark Streaming + Canal + Kafka对Mysql增量数据实时进行监测分析

    Spark Streaming可以用于实时流项目的开发,实时流项目的数据源除了可以来源于日志.文件.网络端口等,常常也有这种需求,那就是实时分析处理MySQL中的增量数据.面对这种需求当然我们可以通过 ...

  8. MySQL 实现将一个库表里面的数据实时更新到另一个库表里面

    MySQL 实现将一个库表里面的数据实时更新到另一个库表里面 需求描述:MySQL 里面有很多的数据库,这些数据库里面都有同一种表结构的表 (tb_warn_log),这张表的数据是实时更新的,现在需 ...

  9. Mysql 到 Hbase 数据如何实时同步,强大的 Streamsets 告诉你

    很多情况大数据集群需要获取业务数据,用于分析.通常有两种方式: 业务直接或间接写入的方式 业务的关系型数据库同步到大数据集群的方式 第一种可以是在业务中编写代码,将觉得需要发送的数据发送到消息队列,最 ...

随机推荐

  1. JS基础-事件队列

    为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事.那么,为什么JavaScript不能有多个线程呢?这样能提高效率啊. JavaSc ...

  2. JS基础-原型链和继承

    创建对象的方法 字面量创建 构造函数创建 Object.create() var o1 = {name: 'value'}; var o2 = new Object({name: 'value'}); ...

  3. 业级PPTP服务器搭建企

    搭建企业级PPTP服务器   分类: Linux服务篇 undefined 本文收录在企业项目实战系列 一.VPN 介绍 1.介绍 虚拟私人网络(英语:Virtual Private Network, ...

  4. xshell6和xftp6运行提示缺少mfc110u.dll文件的解决办法

    xshell6和xftp6运行提示缺少mfc110u.dll文件的解决办法 下载地址 http://www.microsoft.com/zh-CN/download/details.aspx?id=3 ...

  5. centos7制作U盘启动盘

    一.准备相关软件 1.8G以上U盘 2.UltraISO虚拟光驱(试用版即可)最新版 下载地址:https://cn.ultraiso.net/xiazai.html  点击下载试用 3.CentOS ...

  6. 简单学习【1】——使用webpack

    使用webpack webpack命令 webpack配置 第三方脚手架 1.webpack命令 webpack - h (webpack 所有的选项) webpack -v (查看webpack的版 ...

  7. 《Java基础知识》Java集合(Map)

    Java集合主要由2大体系构成,分别是Collection体系和Map体系,其中Collection和Map分别是2大体系中的顶层接口. 今天主要讲:Map主要有二个子接口,分别为HashMap.Tr ...

  8. Spring cloud ——EurekaServer

    Eureka作为服务注册与发现的组件,Eureka2.0已经闭源了,但是本教程还是以Eureka为核心进行展开. 1.三个模块 Spring Cloud Eureka是Spring Cloud Net ...

  9. C# ODP.NET 调用Oracle函数返回值时报错的一个解决方案

    有人在社区问到:C#调用Oracle中自定义函数的返回值时,无法正常调用.但在PL/SQL中正常调用返回. 于是动手一试: 1.准备函数(Oralce 11g.2.0.0.4) CREATE OR R ...

  10. 编译安装基于 fastcgi 模式的多虚拟主机的wordpress和discuz的LAMP架构

    目录 实现CentOS 7 编译安装基于 fastcgi 模式的多虚拟主机的wordpress和discuz的LAMP架构 准备环境: 准备软件版本: 主机名修改用以区分 数据库服务器 实现数据库二进 ...