我是靠谱客的博主 开朗季节,最近开发中收集的这篇文章主要介绍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

  • github
  • 导入数据
    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 CurlCurl();
        $this->version = '1.0';
    }

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

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

    public function setSQL($sql)
    {
        $this->sql = $sql;
    }
}

最后

以上就是开朗季节为你收集整理的ELK环境搭建及es使用sql to dsl 插件的全部内容,希望文章能够帮你解决ELK环境搭建及es使用sql to dsl 插件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部