首页
/ Wonderdog 技术文档

Wonderdog 技术文档

2024-12-20 09:04:54作者:咎岭娴Homer

1. 安装指南

要使用Wonderdog,您需要在项目中的pom.xml文件中声明对Wonderdog的依赖:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.infochimps</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    ...
  </dependencies>
  ...
</project>

这样,在构建代码时,就会包含所需的Wonderdog InputFormat和OutputFormat类。

2. 项目的使用说明

Wonderdog提供了多种功能,包括:

  • Java InputFormat和OutputFormat类,可用于Hadoop MapReduce任务。
  • Wukong插件,使得InputFormat和OutputFormat类易于在Wukong中使用。
  • Pig的Java函数,用于从ElasticSearch加载数据和存储数据。
  • 一些与ElasticSearch交互的命令行工具。

Hadoop MapReduce

Wonderdog提供了可用于自定义Hadoop MapReduce任务的InputFormat和OutputFormat类:

  • com.infochimps.elasticsearch.ElasticSearchInputFormat
  • com.infochimps.elasticsearch.ElasticSearchOutputFormat
  • com.infochimps.elasticsearch.ElasticSearchStreamingInputFormat
  • com.infochimps.elasticsearch.ElasticSearchStreamingOutputFormat

这些类包括适用于旧mapred API的streaming版本和适用于新mapreduce API的非streaming版本。

Wukong

使用Wukong时,确保在项目的Gemfile中包含Wonderdog:

# in Gemfile
gem 'wonderdog', git: 'https://github.com/infochimps-labs/wonderdog'

在作业顶部要求Wonderdog:

# in my_elasticsearch_job.rb
require 'wukong'
require 'wonderdog'

Wukong.dataflow(:mapper) do
  ...
end

Wukong.dataflow(:reducer) do
  ...
end

如果使用Wukong部署包,可以在部署包的顶层创建一个初始化程序来要求Wonderdog:

# in config/initializers/plugins.rb
require 'wonderdog'

3. 项目API使用文档

以下是使用Wonderdog与ElasticSearch交互的一些示例。

写入ElasticSearch

以下示例将所有输出数据写入twitter索引的tweet类型:

$ wu hadoop my_job.rb --input=/some/hdfs/input/path --output=es://twitter/tweet

输出数据的格式和路由:

  • _id:如果存在,用作在ElasticSearch中创建记录的文档ID。
  • _mapping:如果存在,用于指定文档的类型。
  • _index:如果存在,用于指定文档的索引。

读取ElasticSearch

以下示例将从twitter索引的tweet类型中读取所有输入数据:

$ wu hadoop my_job.rb --input=es://twitter/tweet --output=/some/hdfs/output/path

可以使用--es_query选项提供ElasticSearch JSON查询,以自定义输入数据。

优化

在执行Hadoop作业之前,对ElasticSearch索引进行预处理可以提高性能。以下是一些优化措施:

  • index.number_of_replicas设置为0,以减少需要更新的分片数量。
  • index.refresh_interval设置为-1,以确保ElasticSearch不将资源用于搜索数据刷新。

4. 项目安装方式

除了在pom.xml中添加依赖外,使用Wonderdog还需要在Wukong项目中添加相应的gem依赖,并在作业中要求对应的库。

确保在Ruby项目的Gemfile中包含以下内容:

gem 'wonderdog', git: 'https://github.com/infochimps-labs/wonderdog'

然后,在作业脚本中要求所需的库:

require 'wukong'
require 'wonderdog'

这样,就可以开始使用Wonderdog提供的功能了。

登录后查看全文
热门项目推荐