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. RT-Thread的位图调度算法分析(最新版)

    RT-Thread的内核调度算法 rt-thread的调度算法为基于优先级调度和基于时间片轮转调度共存的策略.rt-thread内核中存在多个线程优先级,并且支持多个线程具有同样的线程优先级.线程级别 ...

  2. 5分钟搞清楚Synchronized和Lock的概念与区别

    前言 并发编程中,锁是经常需要用到的,今天我们一起来看下Java中的锁机制:synchronized和lock. Synchronized 和 Lock的概念 Synchronized 是Java 并 ...

  3. hexo + next 搭建博客时Cannot GET /tags/问题处理

    原来是要修改新建的index.md文件,不仔细. 此外,愈发觉得百度和谷歌搜索同一问题的差距,谷歌更适合程序员! https://www.zhihu.com/question/29017171 这个可 ...

  4. Instrument API介绍

    1. Instrumentation介绍  JVMTI(JVM Tool Interface)是 Java 虚拟机所提供的 native 编程接口,是 JVMPI(Java Virtual Machi ...

  5. 小米开源数据库<pegasus>简介

    数据模型 组合键:Table + HashKey + SortKey Table实现业务数据的隔离 HashKey决定数据在那个分片 SortKey决定数据在分片内的排序 一致性协议 使用Pacifi ...

  6. MyBatis进阶讲解+ssm集成

    1.sql映射器Mapper MyBatis基于动态代理机制,让我们无需再编写Dao的实现. 传统Dao接口,现在名称统一以Mapper结尾,还有我们映射器配置文件要和映射器在同一个包. 1.1使用映 ...

  7. [Windows] 智慧职教刷课软件(职教雨滴1.9更新完成)

    (智慧职教刷课软件-职教雨滴)支持职教云(云课堂)的课程 2019年10月17日 16:19:57 增加支持资料库,MOOC 点击链接加入群聊[职教雨滴反馈群]:https://jq.qq.com/? ...

  8. js的cookies及html5的localStorage、sessionStorage

    1.首先,理解什么是cookies? cookies:存储在客户端,数据量小的,会过期的数据,以字符串形式存储 cookie操作代码示例: <script> window.onload = ...

  9. webpack入门——构建简易版vue-cli

          前言:(面试让介绍webpack,你可以这么答)简单地说,Webpack其最核心的功能就是 解决模板之间的依赖,把各个模块按照特定的规则和顺序组织在一起,最终合并成一个JS文件(比如bun ...

  10. python语言的鸭子类型和强类型语言的多态

    python语言的鸭子类型和强类型语言的多态 前面讲接口类的时候举过一个有关支付方式的例子,支付方式可以有几种,微信支付,支付宝支付,苹果支付等,这几个不同的支付都统一于支付,像这样几个类都统一于 某 ...