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. 【CSS】378- [译]44个 CSS 精选知识点

    写在前面 一个周五的晚上,闲来无事整理下自己的 github(经常做收藏党),今天打算都过一遍,发现一个 star很高的项目,里面有大量的 CSS 片段,而且标题很诱人,然后又花了将近1个小时从头到尾 ...

  2. 聊聊JS的二进制家族:Blob、ArrayBuffer和Buffer

    事实上,前端很少涉及对二进制数据的处理,但即便如此,我们偶尔总能在角落里看见它们的身影. 今天我们就来聊一聊前端的二进制家族:Blob.ArrayBuffer和Buffer 概述 Blob: 前端的一 ...

  3. Asp.Net WebApi一个简单的Token验证

    1.前言: WebAPI主要开放数据给手机APP,Pad,其他需要得知数据的系统,或者软件应用.Web 用户的身份验证,及页面操作权限验证是B/S系统的基础功能.我上次写的<Asp.Net MV ...

  4. OCR (光学字符识别技术)安装

    一.安装homebrew 1)打开终端直接输入安装命令:     /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.c ...

  5. [ASP.NET Core 3框架揭秘] 配置[5]:配置数据与数据源的实时同步

    在<配置模型总体设计>介绍配置模型核心对象的时候,我们刻意回避了与配置同步相关的API,现在我们利用一个独立文章来专门讨论这个话题.配置的同步涉及到两个方面:第一,对原始的配置源实施监控并 ...

  6. Elasticsearch 语法指南(全)

    所有的语句默认都是没有用户名和密码,如果你的 es 集群做了安全认证的话,请在每一个 crul 后面加上 -u username:password 例如: curl -u admin:123456 - ...

  7. Docker+DokcerFile 简单命令和简单镜像配置----Tomcat+jdk+centos7

    宿主机描述:docker info (自身的描述)docker --helpdocker images(查看所有镜像)docker images -adocker images -q(显示镜像ID)d ...

  8. NLP(十八)利用ALBERT提升模型预测速度的一次尝试

    前沿   在文章NLP(十七)利用tensorflow-serving部署kashgari模型中,笔者介绍了如何利用tensorflow-serving部署来部署深度模型模型,在那篇文章中,笔者利用k ...

  9. ASP.NET+d3.js实现Sqlserver数据库的可视化展示

    效果: 数据库端: 前端展示: 实现原理: 1.在数据段建立两个存储过程 queryUserAnsawer(id) 根据用户ID返回每一题的得分,主要是bcp exe时不能直接在sqlserver中执 ...

  10. 基于vue+leaflet+echart的足迹分享评论平台

    (其实题目是随便取的,目的只是用来证明Vue+leaflet+springboot技术栈的可行性) 效果 小专栏不支持上传视频?想看的话可以去我的知乎看最新的文章,那个应该可以.在这里 主要功能描述 ...