既然有了elasticsearch为什么还要用hadoop快速入门和spark

后使用快捷导航没有帐号?
查看: 1378|回复: 8
大家工作中都用什么技术,我用的是elasticsearch,hadoop,spark,impala,来聊聊吧
新手上路, 积分 33, 距离下一级还需 17 积分
论坛徽章:3
推荐一下:elasticsearch,一款基于lucene的分布式搜索服务器,不过这款软件,可以作为分布式的索引数据库,性能相当棒,每天承受亿级别的数据,普通查询相应时间也是毫秒级的。
注册会员, 积分 59, 距离下一级还需 141 积分
论坛徽章:4
你好,我对elasticsearch很感兴趣啊,我们现在用的是vertica数据库,分布式列存储数据库,也想试试用elasticsearch来实现,毕竟vertica是商业的,要收费
注册会员, 积分 59, 距离下一级还需 141 积分
论坛徽章:4
有机会交流交流,你们的数据库中存的什么数据呢?可以存结构化的数据吗?
新手上路, 积分 33, 距离下一级还需 17 积分
论坛徽章:3
有机会交流交流,你们的数据库中存的什么数据呢?可以存结构化的数据吗?
恩,可以的,我们公司使用elasticsearch,就是用来存放结构化的数据
新手上路, 积分 33, 距离下一级还需 17 积分
论坛徽章:3
有机会交流交流,你们的数据库中存的什么数据呢?可以存结构化的数据吗?
http://www.jianshu.com/p/2c7b0c76fa04& &这是一篇比较elasticsearch,mongodb,hadoop的文章,希望对你有帮助
新手上路, 积分 33, 距离下一级还需 17 积分
论坛徽章:3
有机会交流交流,你们的数据库中存的什么数据呢?可以存结构化的数据吗?
http://www.jianshu.com/p/2c7b0c76fa04&&这是一篇比较elasticsearch,mongodb,hadoop的文章,希望对你有帮助
注册会员, 积分 99, 距离下一级还需 101 积分
论坛徽章:5
我们也用elasticsearch 看来es用的还挺广
新手上路, 积分 20, 距离下一级还需 30 积分
论坛徽章:1
Mechine Learing &R & python
金牌会员, 积分 2291, 距离下一级还需 709 积分
论坛徽章:8
不错的主题 也挺想知道的&&
dataguru.cn All Right Reserved.用 Spark 处理数据导入 Elasticsearch - 为程序员服务
用 Spark 处理数据导入 Elasticsearch
Logstash 说了这么多。其实运用 Kibana 和 Elasticsearch 不一定需要 logstash,其他各种工具导入的数据都可以。今天就演示一个特别的~用 Spark 来处理导入数据。
首先分别下载 spark 和 elasticsearch-hadoop 的软件包。注意 elasticsearch-hadoop 从最新的 2.1 版开始才带有 spark 支持,所以要下新版:
wget http://d3kbcqa49mib13.cloudfront.net/spark-1.0.2-bin-cdh4.tgz
wget http://download.elasticsearch.org/hadoop/elasticsearch-hadoop-2.1.0.Beta1.zip
分别解压开后,运行 spark 交互命令行 ADD_JARS=../elasticsearch-hadoop-2.1.0.Beta1/dist/elasticsearch-spark_2.10-2.1.0.Beta1.jar ./bin/spark-shell 就可以逐行输入 scala 语句测试了。
注意 elasticsearch 不支持 1.6 版本的 java,所以在 MacBook 上还设置了一下 JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" 启用自己从 Oracle 下载安装的 1.7 版本的 Java。
首先来个最简单的测试,可以展示写入 ES 的用法:
import org.apache.spark.SparkConf
import org.elasticsearch.spark._
// 更多 ES 设置,见&http://www.elasticsearch.org/guide/en/elasticsearch/hadoop/2.1.Beta/configuration.html&
val conf = new SparkConf()
conf.set(&es.index.auto.create&, &true&)
conf.set(&es.nodes&, &127.0.0.1&)
// 在spark-shell下默认已建立
// import org.apache.spark.SparkContext
// import org.apache.spark.SparkContext._
// val sc = new SparkContext(conf)
val numbers = Map(&one& -& 1, &two& -& 2, &three& -& 3)
val airports = Map(&OTP& -& &Otopeni&, &SFO& -& &San Fran&)
sc.makeRDD(Seq(numbers, airports)).saveToEs(&spark/docs&)
这就 OK 了。尝试访问一下:
$ curl '127.0.0.1:9200/spark/docs/_search?q=*'
返回结果如下:
{&took&:66,&timed_out&:false,&_shards&:{&total&:5,&successful&:5,&failed&:0},&hits&:{&total&:2,&max_score&:1.0,&hits&:[{&_index&:&spark&,&_type&:&docs&,&_id&:&BwNJi8l2TmSRTp42GhDmww&,&_score&:1.0, &_source& : {&one&:1,&two&:2,&three&:3}},{&_index&:&spark&,&_type&:&docs&,&_id&:&7f7ar-9kSb6WEiLS8ROUCg&,&_score&:1.0, &_source& : {&OTP&:&Otopeni&,&SFO&:&San Fran&}}]}}
下一步,我们看如何读取文件和截取字段。scala 也提供了正则和捕获的方法:
var text = sc.textFile(&/var/log/system.log&)
var Pattern = &&&(\w{3}\s+\d{1,2} \d{2}:\d{2}:\d{2}) (\S+) (\S+)\[(\d+)\]: (.+)&&&.r
var entries = text.map {
case Pattern(timestamp, host, program, pid, message) =& Map(&timestamp& -& timestamp, &host& -& host, &program& -& program, &pid& -& pid, &message& -& message)
case (line) =& Map(&message& -& line)
entries.saveToEs(&spark/docs&)
这里示例写了两个 case ,因为 Mac 上的 &system.log& 不知道用的什么 syslog 协议,有些在 [pid] 后面居然还有一个 (***) 才是 :。正好就可以用这个来示例如果匹配失败的情况如何处理。不加这个默认 case 的话,匹配失败的就直接报错不会存进 entries 对象了。
注意:.textFile 不是 scala 标准的读取文件函数,而是 sparkContext 对象的方法,返回的是 RDD 对象(包括后面的 .map 返回的也是新的 RDD 对象)。所以后面就不用再 .makeRDD 了。
Spark 还有 Spark streaming 子项目,用于从其他网络协议读取数据,比如 flume,kafka,zeromq 等。官网上有一个配合 nc -l 命令的示例程序。
import org.apache.spark.streaming._
val ssc = new StreamingContext(sc, Seconds(1))
val lines = ssc.socketTextStream(&localhost&, 9999)
ssc.start()
ssc.awaitTermination()
有时间我会继续尝试 Spark 其他功能。
Logstash 说了这么多。其实运用 Kibana 和 Elasticsearch 不一定需要 logstash,其他各种工具导入的数据都可以。今天就演示一个特别的~用 Spark 来处理导入数据。
首先分别下载 spark 和 elasticsearch-hadoop 的软件包。注意 elasticsearch-hadoop 从最新的 2.1 版开始才带有 spark 支持,所以要下新版:
wget http://d3kbcqa49mib13.cloudfront.net/spark-1.0.2-bin-cdh4.tgz
wget http://download.elasticsearch.org/hadoop/elasticsearch-hadoop-2.1.0.Beta1.zip
分别解压开后,运行 spark 交互命令行 ADD_JARS=../elasticsearch-hadoop-2.1.0.Beta1/dist/elasticsearch-spark_2.10-2.1.0.Beta1.jar ./bin/spark-shell 就可以逐行输入 scala 语句测试了。
注意 elasticsearch 不支持 1.6 版本的 java,所以在 MacBook 上还设置了一下 JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" 启用自己从 Oracle 下载安装的 1.7 版本的 Java。
首先来个最简单的测试,可以展示写入 ES 的用法:
import org.apache.spark.SparkConf
import org.elasticsearch.spark._
// 更多 ES 设置,见&http://www.elasticsearch.org/guide/en/elasticsearch/hadoop/2.1.Beta/configuration.html&
val conf = new SparkConf()
conf.set(&es.index.auto.create&, &true&)
conf.set(&es.nodes&, &127.0.0.1&)
// 在spark-shell下默认已建立
// import org.apache.spark.SparkContext
// import org.apache.spark.SparkContext._
// val sc = new SparkContext(conf)
val numbers = Map(&one& -& 1, &two& -& 2, &three& -& 3)
val airports = Map(&OTP& -& &Otopeni&, &SFO& -& &San Fran&)
sc.makeRDD(Seq(numbers, airports)).saveToEs(&spark/docs&)
这就 OK 了。尝试访问一下:
$ curl '127.0.0.1:9200/spark/docs/_search?q=*'
返回结果如下:
{&took&:66,&timed_out&:false,&_shards&:{&total&:5,&successful&:5,&failed&:0},&hits&:{&total&:2,&max_score&:1.0,&hits&:[{&_index&:&spark&,&_type&:&docs&,&_id&:&BwNJi8l2TmSRTp42GhDmww&,&_score&:1.0, &_source& : {&one&:1,&two&:2,&three&:3}},{&_index&:&spark&,&_type&:&docs&,&_id&:&7f7ar-9kSb6WEiLS8ROUCg&,&_score&:1.0, &_source& : {&OTP&:&Otopeni&,&SFO&:&San Fran&}}]}}
下一步,我们看如何读取文件和截取字段。scala 也提供了正则和捕获的方法:
var text = sc.textFile(&/var/log/system.log&)
var Pattern = &&&(\w{3}\s+\d{1,2} \d{2}:\d{2}:\d{2}) (\S+) (\S+)\[(\d+)\]: (.+)&&&.r
var entries = text.map {
case Pattern(timestamp, host, program, pid, message) =& Map(&timestamp& -& timestamp, &host& -& host, &program& -& program, &pid& -& pid, &message& -& message)
case (line) =& Map(&message& -& line)
entries.saveToEs(&spark/docs&)
这里示例写了两个 case ,因为 Mac 上的 &system.log& 不知道用的什么 syslog 协议,有些在 [pid] 后面居然还有一个 (***) 才是 :。正好就可以用这个来示例如果匹配失败的情况如何处理。不加这个默认 case 的话,匹配失败的就直接报错不会存进 entries 对象了。
注意:.textFile 不是 scala 标准的读取文件函数,而是 sparkContext 对象的方法,返回的是 RDD 对象(包括后面的 .map 返回的也是新的 RDD 对象)。所以后面就不用再 .makeRDD 了。
Spark 还有 Spark streaming 子项目,用于从其他网络协议读取数据,比如 flume,kafka,zeromq 等。官网上有一个配合 nc -l 命令的示例程序。
import org.apache.spark.streaming._
val ssc = new StreamingContext(sc, Seconds(1))
val lines = ssc.socketTextStream(&localhost&, 9999)
ssc.start()
ssc.awaitTermination()
有时间我会继续尝试 Spark 其他功能。
三斗室技术博客
原文地址:, 感谢原作者分享。
您可能感兴趣的代码快乐源于简单
在elasticsearch-hadoop的具体使用中碰到了几个问题,有必要记录一下,避免下次遇到时又要重新研究。
利用spark读取es数据源的简单示例
import org.elasticsearch.spark.sql._
val esOptions = Map(&es.nodes&-&&192.168.1.2,192.168.1.3&, &es.scroll.size&-&&1000&, &es.field.read.as.array.include&-&&SampleField&)
val esDF = sqlContext.read.format(&org.elasticsearch.spark.sql&).options(esOptions).load(&sampleindex/es-spark&)
esDF.registerTempTable(&esdemotbl&)
es.scroll.size 一次性读入的记录数,默认是10, 如果不设置为大一点的值,要从es中读取1亿条数据,那将是一个漫长的过程
es.field.read.as.array.include 有的字段在es中是以string类型存储,但其中包含逗号(,), spark默认认为这是数组类型,如果读取这种字段的话,就会报错,怎么办,那就用es.field.read.as.array.include来显式指明
spark读取es中数据的时候,partition数目取决于es中指定index的shard数目,为了获得比较高的并发读取性能,建议适当设置shard数目,为什么是适当,因为具体取决于集群规模等多种因素。
字段名的大小写问题
在hive中,字段名是_大小写不敏感_的, 但在ES中是大小写敏感的
你说,这又怎么样。 呵呵, 这意味着不做特殊处理,永远无法读出es中大写字段名的内容,你看到的将是满屏的_NULL_
这该怎么破,很简单,指定 es.mapping.names
比如在es中,字段名为DemoField, 要读出其中的内容,hive表的字义就该这样写
create external table es_demo_tbl(
demofield string)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes'='192.168.1.2,192.168.1.3', 'es.resource'='demoindex/sample',
'es.mapping.names'='demofield:DemoField')
注意是先hive中的字段名,然后是es中的字段名
阅读(...) 评论()&>&Elasticsearch for Hadoop
Elasticsearch for Hadoop
上传大小:3.57MB
The Hadoop ecosystem is a de-facto standard for processing terra-bytes and peta-bytes of data. Lucene-enabled Elasticsearch is becoming an industry standard for its full-text search and aggregation capabilities. Elasticsearch-Hadoop serves as a perfect tool to bridge the worlds of Elasticsearch and Hadoop ecosystem to get best out of both the worlds. Powered with Kibana, this stack makes it a cakewalk to get surprising insights out of your massive amount of Hadoop ecosystem in a flash.
In this book, you'll learn to use Elastics
earch, Kibana and Elasticsearch-Hadoop effectively to analyze and understand your HDFS and streaming data.
You begin with an in-depth understanding of the Hadoop, Elasticsearch, Marvel, and Kibana setup. Right after this, you will learn to successfully import Hadoop data into Elasticsearch by writing MapReduce job in a real-world example. This is then followed by a comprehensive look at Elasticsearch essentials, such as full-text search analysis, queries, filt after which you gain an understanding of creating various visualizations and interactive dashboard using Kibana. Classifying your real-world streaming data and identifying trends in it using Storm and Elasticsearch are some of the other topics that we'll cover. You will also gain an insight about key concepts of Elasticsearch and Elasticsearch-hadoop in distributed mode, advanced configurations along with some common configuration presets you may need for your production deployments. You will have “Go production checklist” and high-level view for cluster administration for post-production. Towards the end, you will learn to integrate Elasticsearch with other Hadoop eco-system tools, such as Pig, Hive and Spark.
...展开收缩
综合评分:5
12积分/C币
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有2条
非常感谢分享,很不错的版本。
PDF版很清晰,谢谢。
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
Elasticsearch for Hadoop
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
terencecpp
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*投诉人姓名:
*投诉人联系方式:
*版权证明:
*详细原因:
Elasticsearch for Hadoop

我要回帖

更多关于 学习elasticsearch 的文章

 

随机推荐