This repository contains code for the Elastic Open Web Crawler. Open Crawler enables users to easily ingest web content into Elasticsearch.
[!IMPORTANT] The Open Crawler is currently in beta. Beta features are subject to change and are not covered by the support SLA of generally available (GA) features. Elastic plans to promote this feature to GA in a future release.
Open Crawler v0.2
is confirmed to be compatible with Elasticsearch v8.13.0
and above.
Indexing web content with the Open Crawler requires:
Crawler runs crawl jobs on command, based on config files in the config
directory.
Each URL endpoint found during the crawl will result in one document to be indexed into Elasticsearch.
Crawler performs crawl jobs in a multithreaded environment, where one thread will be used to visit one URL endpoint.
Crawls are performed in two stages:
Beginning with URLs included as seed_urls
, the Crawler begins crawling web content.
While crawling, each link it encounters will be added to the crawl queue, unless the link should be ignored due to crawl rules or crawler directives.
The crawl results from visiting these webpages are added to a pool of results.
These are indexed into Elasticsearch using the _bulk
API once the pool reaches the configured threshold.
After a primary crawl is completed, Crawler will then fetch every doc from the associated index that was not encountered during the primary crawl.
It does this through comparing the last_crawled_at
date on the doc to the primary crawl's start time.
If last_crawled_at
is earlier than the start time, that means the webpage was not updated during the primary crawl and should be added to the purge crawl.
Crawler then re-crawls all of these webpages. If a webpage is still accessible, Crawler will update its Elasticsearch doc. A webpage can be inaccessible due to any of the following reasons:
200
response from the webserverAt the end of the purge crawl, all docs in the index that were not updated during either the primary crawl or the purge crawl are deleted.
A running instance of Elasticsearch is required to index documents into. If you don't have this set up yet, you can sign up for an Elastic Cloud free trial or check out the quickstart guide for Elasticsearch.
Open Crawler will attempt to use the _bulk
API to index crawl results into Elasticsearch.
To facilitate this connection, Open Crawler needs to have either an API key or a username/password configured to access the Elasticsearch instance.
If using an API key, ensure that the API key has read and write permissions to access the index configured in output_index
.
[!IMPORTANT] Do not trigger multiple crawl jobs that reference the same index simultaneously. A single crawl execution can be thought of as a single crawler. Even if two crawl executions share a configuration file, the two crawl processes will not communicate with each other. Two crawlers simultaneously interacting with a single index can lead to data loss.
docker run -i -d \
--name crawler \
docker.elastic.co/integrations/crawler:0.2.0
-i
allows the container to stay alive so CLI commands can be executed inside it-d
allows the container to run "detached" so you don't have to dedicate a terminal window to it--network
flag when running both containers, e.g. --network elastic
docker exec -it crawler bin/crawler version
[!TIP] We recommend running from source only if you are actively developing Open Crawler.
Crawler has template configuration files that contain every configuration available.
To use these files, make a copy locally without the .example
suffix.
Then remove the #
comment-out characters from the configurations that you need.
You can then copy the file into your running Docker image.
$ docker cp config/my-crawler.yml crawler:app/config/my-crawler.yml
Crawler can be configured using two config files, a Crawler configuration and an Elasticsearch configuration. The Elasticsearch configuration file is optional. It exists to allow users with multiple crawlers to only need a single Elasticsearch configuration. See CONFIG.md for more details on these files.
Once everything is configured, you can run a crawl job using the CLI:
$ docker exec -it crawler bin/crawler crawl path/to/my-crawler.yml
Crawl jobs can also be scheduled to recur. Scheduled crawl jobs run until terminated by the user.
These schedules are defined through a cron expression. This expression needs to be included in the Crawler config file. You can use the tool https://crontab.guru to test different cron expressions. Crawler supports all standard cron expressions.
See an example below for a crawl schedule that will execute once every 30 minutes.
domains:
- url: "https://elastic.co"
schedule:
- pattern: "*/30 * * * *" # run every 30th minute
Then, use the CLI to then begin the crawl job schedule:
docker exec -it crawler bin/crawler schedule path/to/my-crawler.yml
Scheduled crawl jobs from a single execution will not overlap. Scheduled jobs will also not wait for existing jobs to complete. If a crawl job is already in progress when another schedule is triggered, the job will be dropped. For example, if you have a schedule that triggers at every hour, but your crawl job takes 1.5 hours to complete, the crawl schedule will effectively trigger on every 2nd hour.
Executing multiple crawl schedules can cause overlap. Be wary of executing multiple schedules against the same index. As with ad-hoc triggered crawl jobs, two crawlers simultaneously interacting with a single index can lead to data loss.
See DOCUMENT_SCHEMA.md for information regarding the Elasticsearch document schema and mappings.
Open Crawler does not have a graphical user interface. All interactions with Open Crawler take place through the CLI. When given a command, Open Crawler will run until the process is finished. OpenCrawler is not kept alive in any way between commands.
See CLI.md for a full list of CLI commands available for Crawler.