我有一个需求,我必须索引HDFS文件(包括TXT, PDF, DOCX,其他富文档)到Solr。
目前,我正在使用LucidWorks连接器的DirectoryIngestMapper
来实现相同的功能。https://github.com/lucidworks/hadoop-solr
但是我不能这样做,因为它有一定的限制(主要是你不能指定要考虑的文件类型)。
所以现在我正在研究使用MapReduceIndexerTool
的可能性。但它没有很多初学者(我的意思是绝对基本的!)级别的例子。
有人可以张贴一些链接的例子开始与MapReduceIndexerTool?是否有其他更好或更简单的方法来索引HDFS中的文件?
在Cloudera上,我认为您有这些选项:
- MapReduceIndexerTool
- CrunchIndexerTool
- 自定义spark或map reduce任务,例如使用spark-solr
关于MapReduceIndexerTool这里有一个快速指南:
使用MapReduceIndexerTool将csv索引到SolR
本指南向您展示如何使用MapReduceIndexerTool索引/上传.csv
文件到SolR。这个过程将从HDFS读取csv文件,并直接在HDFS中写入索引。
参见https://www.cloudera.com/documentation/enterprise/latest/topics/search_mapreduceindexertool.html。
假设你有:
- 一个有效的cloudera安装(参见
THIS_IS_YOUR_CLOUDERA_HOST
,如果使用Docker快速启动,它应该是quickstart.cloudera
) - 存储在HDFS中的csv文件(参见
THIS_IS_YOUR_INPUT_CSV_FILE
,和/your-hdfs-dir/your-csv.csv
一样) - 一个有效的目标SolR集合,其中已经配置了预期的字段(参见
THIS_IS_YOUR_DESTINATION_COLLECTION
)- 输出目录将是SolR配置的
instanceDir
(参见THIS_IS_YOUR_CORE_INSTANCEDIR
),并且应该是HDFS的路径
- 输出目录将是SolR配置的
在本例中,我们将处理一个包含uid
、firstName
和lastName
列的TAB分隔文件。第一行包含标题。Morphlines配置文件将跳过第一行,因此实际的列名并不重要,列应该按照这个顺序。在SolR中,我们应该用类似的方式配置字段:
<field name="_version_" type="long" indexed="true" stored="true" />
<field name="uid" type="string" indexed="true" stored="true" required="true" />
<field name="firstName" type="text_general" indexed="true" stored="true" />
<field name="lastName" type="text_general" indexed="true" stored="true" />
<field name="text" type="text_general" indexed="true" multiValued="true" />
然后,您应该使用以下代码创建一个Morphlines配置文件(csv-to-solr-morphline.conf
):
# Specify server locations in a SOLR_LOCATOR variable; used later in
# variable substitutions:
SOLR_LOCATOR : {
# Name of solr collection
collection : THIS_IS_YOUR_DESTINATION_COLLECTION
# ZooKeeper ensemble
zkHost : "THIS_IS_YOUR_CLOUDERA_HOST:2181/solr"
}
# Specify an array of one or more morphlines, each of which defines an ETL
# transformation chain. A morphline consists of one or more potentially
# nested commands. A morphline is a way to consume records such as Flume events,
# HDFS files or blocks, turn them into a stream of records, and pipe the stream
# of records through a set of easily configurable transformations on the way to
# a target application such as Solr.
morphlines : [
{
id : morphline1
importCommands : ["org.kitesdk.**"]
commands : [
{
readCSV {
separator : "t"
# This columns should map the one configured in SolR and are expected in this position inside CSV
columns : [uid,lastName,firstName]
ignoreFirstLine : true
quoteChar : ""
commentPrefix : ""
trim : true
charset : UTF-8
}
}
# Consume the output record of the previous command and pipe another
# record downstream.
#
# This command deletes record fields that are unknown to Solr
# schema.xml.
#
# Recall that Solr throws an exception on any attempt to load a document
# that contains a field that is not specified in schema.xml.
{
sanitizeUnknownSolrFields {
# Location from which to fetch Solr schema
solrLocator : ${SOLR_LOCATOR}
}
}
# log the record at DEBUG level to SLF4J
{ logDebug { format : "output record: {}", args : ["@{}"] } }
# load the record into a Solr server or MapReduce Reducer
{
loadSolr {
solrLocator : ${SOLR_LOCATOR}
}
}
]
}
]
导入在集群内执行以下命令:
hadoop jar /usr/lib/solr/contrib/mr/search-mr-*-job.jar
org.apache.solr.hadoop.MapReduceIndexerTool
--output-dir hdfs://quickstart.cloudera/THIS_IS_YOUR_CORE_INSTANCEDIR/
--morphline-file ./csv-to-solr-morphline.conf
--zk-host quickstart.cloudera:2181/solr
--solr-home-dir /THIS_IS_YOUR_CORE_INSTANCEDIR
--collection THIS_IS_YOUR_DESTINATION_COLLECTION
--go-live
hdfs://THIS_IS_YOUR_CLOUDERA_HOST/THIS_IS_YOUR_INPUT_CSV_FILE
一些注意事项:
- 您可以使用
sudo -u hdfs
来运行上述命令,因为您不应该有在HDFS输出目录中写入的权限。 - 默认情况下,Cloudera快速入门具有非常小的内存和堆内存配置。如果您收到内存不足异常或堆异常,我建议使用Cloudera Manager->Yarn->Configurations (http://THIS_IS_YOUR_CLOUDERA_HOST:7180/cmf/services/11/config#filterdisplayGroup=Resource+Management)增加它)对于map和reduce作业,我使用了1 GB的内存和500MB的堆。也考虑在
/etc/hadoop/conf/map-red-sites.xml
中更改
yarn.app.mapreduce.am.command-opts
, mapreduce.map.java.opts
, mapreduce.map.memory.mb
和mapreduce.map.memory.mb
。其他资源:
- http://kitesdk.org/docs/1.1.0/morphlines/morphlines-reference-guide.html readCSV
- https://github.com/kite-sdk/kite/blob/master/kite-morphlines/kite-morphlines-core/src/test/resources/test-morphlines/readCSV.conf
- https://www.cloudera.com/documentation/enterprise/latest/topics/search_flume_nrt_index_ref.html csug_topic_7
- https://community.cloudera.com/t5/Cloudera-Search-Apache-SolrCloud/Solr-indexing-on-hive-table/td-p/46809/page/2
但是我不能这样做,因为它有一定的限制(主要是你不能指定要考虑的文件类型)。
对于https://github.com/lucidworks/hadoop-solr,输入是路径。
因此,您可以通过文件名指定。
-i /path/*.pdf
可以添加add.subdirectories
参数。但是*.pdf
不是递归设置的gitsource
-Dadd.subdirectories=true