ELK环境搭建及es使用sql to dsl 插件

依赖

  • 关于java JDK 依赖 最好使用1.8JDK
  • jar :mysql-connector-java-5.1.43-bin.jar

配置文件 xxxx.conf

input {
  jdbc {
    jdbc_driver_library => "D:/wll-soft/ELK/logstash-5.5.2/mysql-connector-java-5.1.43-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://xxxxxx:3306/xxxx"
    jdbc_validate_connection => true
    jdbc_paging_enabled => true
    jdbc_page_size => 500
    jdbc_user => "root"
    jdbc_password => "root"
    statement => "select * from table  WHERE id > :sql_last_value"
  }
}

output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "indexName"
    }
    stdout { codec => rubydebug }
}

启动报错(win)

  • Cannot locate Java installation, specified by JAVA_HOME:
 set JAVA_HOME=/XXX/XXX
  • Your application used more memory than the safety cap of 1G.
    手动修改配置文件logstash/bin/setup.*
  set LS_HEAP_SIZE=3g

sql To DSL

    logstash.bat -f xxxxx.conf
  • 使用插件
elasticsearch-plugin.bat install es-sql-5.5.0.zip  
  • PHP demo

  • 下载curl扩展

composer require culr/curl

composer require elasticsearch/elasticsearch

test.php

<?php
require_once 'vendor/autoload.php';
require_once 'Elasticsearch.php';

$es = new Elasticsearch();

$curl = $es->getCURL();

$baseUri = $es->getURI();

$baseSQL = 'select * from news_info_shadow limit 1';

$sql = isset($argv[1]) ? $argv[1] : $baseSQL;

if (is_string($sql) && '' != $sql) {
    $result = $curl->get($baseUri . urlencode($sql));
    print_r(json_decode($result->response, 1)['hits']['hits']);
}

Elasticsearch.php

<?php

/**
 * Created by PhpStorm.
 * User: wang.liangliang
 * Date: 2017/9/1
 * Time: 15:58
 */
class Elasticsearch
{
    private $curl;

    private $uri;

    private $version;

    private $sql;


    public function __construct()
    {
        $this->uri = 'http://localhost:9200/_sql?sql=';
        $this->curl = new \Curl\Curl();
        $this->version = '1.0';
    }

    public function getCURL()
    {
        return $this->curl;
    }

    public function getURI()
    {
        return $this->uri;
    }

    public function setSQL($sql)
    {
        $this->sql = $sql;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值