Book Image

Scaling Big Data with Hadoop and Solr

By : Hrishikesh Vijay Karambelkar
Book Image

Scaling Big Data with Hadoop and Solr

By: Hrishikesh Vijay Karambelkar

Overview of this book

<p>As data grows exponentially day-by-day, extracting information becomes a tedious activity in itself. Technologies like Hadoop are trying to address some of the concerns, while Solr provides high-speed faceted search. Bringing these two technologies together is helping organizations resolve the problem of information extraction from Big Data by providing excellent distributed faceted search capabilities.</p> <p>Scaling Big Data with Hadoop and Solr is a step-by-step guide that helps you build high performance enterprise search engines while scaling data. Starting with the basics of Apache Hadoop and Solr, this book then dives into advanced topics of optimizing search with some interesting real-world use cases and sample Java code.</p> <p>Scaling Big Data with Hadoop and Solr starts by teaching you the basics of Big Data technologies including Hadoop and its ecosystem and Apache Solr. It explains the different approaches of scaling Big Data with Hadoop and Solr, with discussion regarding the applicability, benefits, and drawbacks of each approach. It then walks readers through how sharding and indexing can be performed on Big Data followed by the performance optimization of Big Data search. Finally, it covers some real-world use cases for Big Data scaling.</p> <p>With this book, you will learn everything you need to know to build a distributed enterprise search platform as well as how to optimize this search to a greater extent resulting in maximum utilization of available resources.</p>
Table of Contents (15 chapters)
Scaling Big Data with Hadoop and Solr
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The Solr-1301 patch – reduce-side indexing


The patch provides RecordWriter to generate Solr index. It also provides OutputFormat for outputting your indexes. With Solr-1301 patch, we only need to implement the reducer since this patch is based on reducer.

You can follow the given steps to achieve reduce-side indexing using Solr-1301:

  1. Get solrconfig.xml, schema.xml and other configurations in the conf folder, and also get all the Solr libraries in the lib folder.

  2. Implement SolrDocumentConverter that takes the <key, value> pair and returns SolrInputDocument. This converts output records to Solr documents.

    public class HadoopDocumentConverter extends SolrDocumentConverter<Text, Text> {
      @Override
      public Collection<SolrInputDocument> convert(Text key, Text value) {
        ArrayList<SolrInputDocument> list = new ArrayList<SolrInputDocument>();
        SolrInputDocument document = new SolrInputDocument();
        document.addField("key", key);
        document.addField("value", value);
        list.add(document);
        return list;
      }
    }
  3. Create a simple reducer as follows:

    public static class IndexReducer {
      protected void setup(Context context) throws IOException, InterruptedException {
        super.setup(context);
        SolrRecordWriter.addReducerContext(context);
      }
    }
  4. Now configure the Hadoop reducer and configure the job. Depending upon the batch configuration (that is, solr.record.writer.batch.size), the documents are buffered before updating the index.

    SolrDocumentConverter.setSolrDocumentConverter(HadoopDocumentConverter.class, job.getConfiguration());
    job.setReducerClass(SolrBatchIndexerReducer.class);
    job.setOutputFormatClass(SolrOutputFormat.class);
    File solrHome = new File("/user/hrishikes/solr");
    SolrOutputFormat.setupSolrHomeCache(solrHome, job.getConfiguration());

The solrHome is the patch where solr.zip is stored. Each task initiates the EmbeddedServer instance for performing the task.