Skip to content

Instantly share code, notes, and snippets.

Last active October 3, 2022 13:30
Show Gist options
  • Save xrstf/b48a970098a8e76943b9 to your computer and use it in GitHub Desktop.
Save xrstf/b48a970098a8e76943b9 to your computer and use it in GitHub Desktop.
Nutch 2.3 + ElasticSearch 1.4 + HBase 0.94 Setup


This guide sets up a non-clustered Nutch crawler, which stores its data via HBase. We will not learn how to setup Hadoop et al., but just the bare minimum to crawl and index websites on a single machine.


  • Nutch - the crawler (fetches and parses websites)
  • HBase - filesystem storage for Nutch (Hadoop component, basically)
  • Gora - filesystem abstraction, used by Nutch (HBase is one of the possible implementations)
  • ElasticSearch - index/search engine, searching on data created by Nutch (does not use HBase, but its down data structure and storage)


Install OpenJDK, ant and ElasticSearch via your repository manager of choice (ES can be installed by using the .deb linked above, if you need).

Extract Nutch and HBase somewhere. From now on, we will refer to the Nutch root directory by $NUTCH_ROOT and the HBase root by $HBASE_ROOT.

Setting up HBase

  1. edit $HBASE_ROOT/conf/hbase-site.xml and add
  1. edit $HBASE_ROOT/conf/ and enable JAVA_HOME and set it to the proper path:
-# export JAVA_HOME=/usr/java/jdk1.6.0/
+export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

This step might seem redundant, but even with JAVA_HOME being set in my shell, HBase just didn't recognize it.

  1. kick off HBase:

Setting up Nutch

  1. enable the HBase dependency in $NUTCH_ROOT/ivy/ivy.xml by uncommenting the line
<dependency org="org.apache.gora" name="gora-hbase" rev="0.5" conf="*->default" />
  1. configure the HBase adapter by editing the $NUTCH_ROOT/conf/
  1. build Nutch
$ ant clean
$ ant runtime

This can take a while and creates $NUTCH_ROOT/runtime/local.

  1. configure Nutch by editing $NUTCH_ROOT/runtime/local/conf/nutch-site.xml:
    <value>mycrawlername</value> <!-- this can be changed to something more sane if you like -->
    <value>mycrawlername</value> <!-- this is the robot name we're looking for in robots.txt files -->
    <!-- do **NOT** enable the parse-html plugin, if you want proper HTML parsing. Use something like parse-tika! -->
    <value>true</value> <!-- do not leave the seeded domains (optional) -->
    <value>localhost</value> <!-- where is ElasticSearch listening -->
  1. configure HBase integration by editing $NUTCH_ROOT/runtime/local/conf/hbase-site.xml:
    <value>file:///full/path/to/where/the/data/should/be/stored</value> <!-- same path as you've given for HBase above -->

That's it. Everything is now setup to crawl websites.

Adding new Domains to crawl with Nutch

  1. create an empty directory. Add a textfile containing a list of seed URLs.
$ mkdir seed
$ echo "" >> seed/urls.txt
$ echo "" >> seed/urls.txt
$ echo "" >> seed/urls.txt
  1. inject them into Nutch by giving a file URL (!)
$ $NUTCH_ROOT/runtime/local/bin/nutch inject file:///path/to/seed/

Actual Crawling Procedure

  1. Generate a new set of URLs to fetch. This is is based on both the injected URLs as well as outdated URLs in the Nutch crawl db.
$ $NUTCH_ROOT/runtime/local/bin/nutch generate -topN 10

The above command will create job batches for 10 URLs.

  1. Fetch the URLs. We are not clustering, so we can simply fetch all batches:
$ $NUTCH_ROOT/runtime/local/bin/nutch fetch -all
  1. Now we parse all fetched pages:
$ $NUTCH_ROOT/runtime/local/bin/nutch parse -all
  1. Last step: Update Nutch's internal database:
$ $NUTCH_ROOT/runtime/local/bin/nutch updatedb -all

On the first run, this will only crawl the injected URLs. The procedure above is supposed to be repeated regulargy to keep the index up to date.

Putting Documents into ElasticSearch

Easy peasy:

$ $NUTCH_ROOT/runtime/local/bin/nutch index -all

Query for Documents

The usual ElasticSearch way:

$ curl -X GET "http://localhost:9200/_search?query=my%20term"
Copy link

ghost commented Jan 6, 2016

This is a fantastic tutorial!

How can we remove domains/urls?

Copy link

dgrene commented Jan 11, 2016

Hi can you please help me, iam using elastic search 2.x, its not working in that case

Copy link

guys I am also tried hard on Elasticsearch with 2,1,1 but no luck with apache nutch 2.3.

Copy link

ghost commented Apr 10, 2016

Anyone slove the problem that can't find the data in elasticsearch?I use elasticsearch 1.4.1 and 1.4.4,but both of them can't find data.
And I try es2.3.1,it give me lots of error.
Any help will be much appreciate

Copy link

The injector goes forever and getting the below error in $NUTCH_ROOT/runtime/local/logs/hadoop.log file Connection refused
at Method)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(
at org.apache.zookeeper.ClientCnxn$
2016-05-10 12:42:15,239 WARN zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

Copy link

pranipat commented May 11, 2016

after doing runtime/local/bin/nutch index elasticsearch -all

and to check if we got indices on elastic
curl 'localhost:9200/_cat/indices?v'
gives the below result Which simply means we have no indexes yet in the cluster.

Copy link

result of runtime/local/bin/nutch index -all or runtime/local/bin/nutch index elasticsearch -all

IndexingJob: starting
Active IndexWriters :
elastic.cluster : elastic prefix cluster : hostname
elastic.port : port (default 9300)
elastic.index : elastic index command : elastic bulk index doc counts. (default 250)
elastic.max.bulk.size : elastic bulk index length. (default 2500500 ~2.5MB)

But nothing in elastic . Can anyone plz let me know how to solve this?

Copy link

idda commented May 18, 2016

great tutorial.

@pranipat , I meet same problem as you. For me, it is because I used "bin/nutch index elasticsearch -all -crawlId 100". I found if I add elasticsearch parameter, it will create a default 'webpage' and index from this table,so nothing will put into elasticsearch. In log:
Processing remaining requests [docs= 0 , length = 0, total docs = 0]
in hbase shell > list:
"100_webpage", "web_page"
The "web_page" was created by index command.

I do following commands, it is ok:
bin/nutch inject conf/urls -crawlId 100
bin/nutch generate -crawlId 100
bin/nutch fetch -all -carwlId 100
bin/nutch parse -all -crawlId 100
bin/nutch updatedb -all -crawlId 100
bin/nutch index -all -crawlId 100

curl 'localhost:9200/_cat/indices?v'
... pri rep ...
... 5 1 ...

hope it is useful for you.

Copy link

narendrakadari commented May 27, 2016

Hi everyone Could any one help me out of this error ?
how to slove this error .
Iam using solr 4.10.3 , hbase0.98.19.hadoop and nutch 2.3.1
here Iam getting data in to hbase but when iam doing indexing ,am getting this error in nutch logs

IndexingJob: starting SolrIndexerJob: java.lang.RuntimeException: job failed: name=
[TestCrawl5]Indexer, jobid=job_local112769475_0001
at org.apache.nutch.util.NutchJob.waitForCompletion(
at org.apache.nutch.indexer.IndexingJob.index(
at org.apache.nutch.indexer.IndexingJob.main(

Error running:
/usr/local/apache-nutch-2.3.1/runtime/local/bin/nutch index -D mapred.reduce.tasks=2 -D -D mapred.reduce.tasks.speculative.execution=false -D -D -D solr.server.url=http://localhost:8983/solr/#/collection1 -all -crawlId TestCrawl5
Failed with exit value 255.

Copy link

I am getting the following error, Any ideas ??

InjectorJob: starting at 2016-07-04 14:53:20
InjectorJob: Injecting urlDir: /home/ubuntu/seed/urls.txt
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at org.apache.nutch.crawl.InjectorJob.inject(
at org.apache.nutch.crawl.InjectorJob.main(
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 10 more

Copy link

Try with HBASE 9.8
Look at this

Copy link

Nice article,
I am using Nutch 2.3.1 and have many urls in seed.txt file, e.g., etc.. and want to index all URL in ES under single index e.g. foodindex and each url as separate type e.g foodindex/foodurl1, foodindex/foodurl2. So i can search each url individually based on type. Is there any out of the box way to pass type in in ES indexer plugin(by default its using "doc" type).
public void write(NutchDocument doc) throws IOException {
String id = (String) doc.getFieldValue("id");
String type = doc.getDocumentMeta().get("type");
if (type == null)
type = "doc";
IndexRequestBuilder request = client.prepareIndex(defaultIndex, type, id);

or any other suggestion to achieve this.

Thanks in advance, Mra

Copy link

hbase-0.94 didn't work well on my server , nutch will throw some exceptions like

so as the suggestion on nutch wiki
HBase 0.98.8-hadoop2 works well on my server(centOS 6)`

Copy link

This is a good tutorial.
But I have a problem when inject the url file.
$ bin/nutch inject seed/urls.txt

At that time the following error was occurs.
bash nutch command not found

Could you please help me how to solve.

Copy link


Can any one know how to integrate tika with Nutch -2.3+Hbase-0.98.80+Solr-4.1.0

Copy link

PammyS commented Jun 12, 2017

Everything works fine apart from indexing this output comes and there in nothing in elastic search

Elastic Version: 1.7.2
Nutch 1.13

Indexer: starting at 2017-06-12 13:42:24
Indexer: deleting gone documents: false
Indexer: URL filtering: false
Indexer: URL normalizing: false
Active IndexWriters :
elastic.cluster : elastic prefix cluster : hostname
elastic.port : port
elastic.index : elastic index command : elastic bulk index doc counts. (default 250)
elastic.max.bulk.size : elastic bulk index length in bytes. (default 2500500)
elastic.exponential.backoff.millis : elastic bulk exponential backoff initial delay in milliseconds. (default 100)
elastic.exponential.backoff.retries : elastic bulk exponential backoff max retries. (default 10)
elastic.bulk.close.timeout : elastic timeout for the last bulk in seconds. (default 600)

Indexer: number of documents indexed, deleted, or skipped:
Indexer: finished at 2017-06-12 13:42:41, elapsed: 00:00:17

Copy link

I followed the Nutch 2.x Official tutorial - got so far as Inject URL's in Nutch - but that hangs forever .

Have documented own errors and process here - have read lots on SO and other blogs nothing seems to resolve issue - kindly suggest what changes required ??

Copy link

kikekr commented Oct 12, 2017

I'm trying to deploy this, but when I start the url injection the process takes forever.. I describe it in this post. Anyone can help me?

Copy link

Thank You

Copy link

I'm looking for a solution that will work with Nutch 2.3 and Elastic 5.x. Everything works fine but the indexer to elastic. I tried this one:
But it doesn't work either, and the documentation is clearly wrong.

Has anyone got this combination working?

Copy link

carlnc commented Dec 14, 2017

Spidering websites, converting pages and documents into JSON, and pushing JSON to Elasticsearch ... should not be this hard.

I'm yet to come across an ant/maven project that isn't a nightmare to setup and use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment