Index a website from its sitemap
A sitemap source keeps an index in step with your website. You give Relevan the URL of your sitemap. Relevan fetches each page that the sitemap lists, writes the page to your index, and syncs again about once a day. You do not write a crawler or map fields.
The steps:
- Claim and verify your domain with a DNS TXT record.
- Add the sitemap to an index.
- Watch the first sync, then search.
You can do each step in the console or with the API. In the console, create the index with the Website from a sitemap mapping (see the fields). Then open the index and go to the Sources section.
1. Claim and verify your domain
Relevan fetches pages only from a domain that you control. To prove control, you add a DNS TXT record.
In the console, paste the sitemap URL into Sitemap URL and click Add sitemap. When your organization has not claimed the domain of the sitemap, the console claims it and shows the TXT record, with a copy button for the name and the value.
With the API, claim the domain:
curl -X POST "https://api.relevan.dev/v1/{orgId}/domains" \
-H "Authorization: Bearer $RELEVAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"domain": "example.com"}'The response holds the record to add:
{
"domain": "example.com",
"status": "pending",
"record": {
"name": "_relevan-verify.example.com",
"type": "TXT",
"value": "relevan-verify=2f0cQx..."
}
}Add a TXT record with this name and value at your DNS provider. Then click Verify in the console, or call the check:
curl -X POST "https://api.relevan.dev/v1/{orgId}/domains/example.com/verify" \
-H "Authorization: Bearer $RELEVAN_API_KEY"When the check passes, status is verified. When it fails, lastError gives the reason:
- No TXT record was found at the name. A DNS change can take some minutes to reach every resolver. Wait, then check again.
- The record holds a different value. Set it to the value that Relevan gave.
- The DNS lookup failed. Try again later.
A verified domain covers the domain and each subdomain. A claim of example.com covers docs.example.com and www.example.com.
Keep the record in your DNS. Relevan checks it again before each sync. When the record is gone, the sync stops with the outcome unverified and fetches nothing. Add the record again and verify to resume the syncs.
2. Add the sitemap
In the console, the source shows up after Add sitemap. With the API:
curl -X POST "https://api.relevan.dev/v1/{orgId}/indexes/{indexName}/sources" \
-H "Authorization: Bearer $RELEVAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"sitemap": "https://example.com/sitemap.xml"}'The sitemap can be a sitemap or a sitemap index with child sitemaps, as XML or gzip. Each child sitemap must be on the verified domain. You can add a source before the domain is verified, but no sync runs until the check passes.
Use a new index for a sitemap source. In the console, the Create Index form always sets a mapping, so choose Website from a sitemap under Mapping. With the API, create the index with no mapping. It gets the sitemap mapping when you add the source. An index whose mapping does not map each field below cannot take a sitemap source, and the request returns 409.
The fields of each document
| Field | What it holds |
|---|---|
title | The page title. |
url | The URL of the page. Use it as the link of a search result. |
description | The meta description of the page. |
body | The main text of the page, with no navigation, header, footer, or scripts. |
section | The article:section meta tag, or else the first segment of the URL path, such as blog. |
lang | The primary language tag of <html lang>, such as en. |
lastmod | The lastmod of the page in the sitemap, or null. |
The document id is a hash of the URL, so the id of a page stays the same from sync to sync. Two forms of one URL, such as a host in capitals or a URL with a fragment, give one document. A page URL longer than 2,048 characters, the limit of the sitemap protocol, is not fetched and counts as failed.
3. Watch the sync
The Sources section shows the state of each source and refreshes while a sync runs. The GET of a source gives the same data:
curl "https://api.relevan.dev/v1/{orgId}/indexes/{indexName}/sources/{sourceId}" \
-H "Authorization: Bearer $RELEVAN_API_KEY"status:idle,queued(a sync waits to start), orsyncing.lastOutcome: how the last sync ended (see Outcomes).lastSyncFinishedAtandnextSyncAt: the time of the last sync and of the next scheduled sync.pages: the counts of the last sync.foundURLs in the sitemap,indexedpages fetched and written,skippedpages that did not change,failedpages that could not be fetched or read, anddeletedpages that left the sitemap.
The sync schedule
Relevan syncs each source about 24 hours after its last sync finished. The first sync of a new source starts within 15 minutes after its domain is verified. A manual sync moves the time of the next scheduled sync. A sync:
- fetches the pages that are new in the sitemap,
- fetches a page again when its
lastmodchanged, - skips a page when its
lastmoddid not change, - sends a conditional request for a page with no
lastmod, at most once every 7 days, and - deletes the document of each page that left the sitemap.
A page that fails is tried again at the next sync. After 5 failures in a row, Relevan stops trying until the lastmod of the page changes.
The crawler is RelevanBot. It obeys robots.txt and Crawl-delay, and sends at most 2 concurrent requests to a host. See RelevanBot.
Sync now
To publish a change at once, click Sync now in the console, or call:
curl -X POST "https://api.relevan.dev/v1/{orgId}/indexes/{indexName}/sources/{sourceId}/sync" \
-H "Authorization: Bearer $RELEVAN_API_KEY"202: the sync is queued.409: a sync of this source is queued or running. Wait for it to finish.429: you started a manual sync of this source less than 10 minutes ago.retryAfterSecondstells you how long to wait.
A manual sync uses the same page quota as a scheduled sync.
Quotas
Two limits of your plan apply to sitemap sources. GET /v1/{orgId}/usage returns both, and the Sources section shows them.
- Pages per month (
scrapedPages): the pages that Relevan fetches for your organization in a calendar month (UTC). A page that did not change costs nothing.resetAtgives the time of the next reset. - URLs per sitemap (
urlsPerSitemap): the most URLs that one source can hold. When a sitemap lists more, Relevan keeps the first URLs in sitemap order.
Documents from a sitemap also count toward the storage limit of your organization, as uploaded documents do.
Outcomes
lastOutcome | What it means and what to do |
|---|---|
completed | Each page in the sitemap is up to date. |
quota_exceeded | The monthly page quota or the storage limit ran out. The pages that were not fetched wait. The next sync after the quota resets continues with them. lastError says which limit it was. |
url_cap_reached | The sitemap lists more URLs than your plan allows for one source. Relevan indexed the first URLs in sitemap order. Split the sitemap into more sources, or contact us for a higher limit. |
unverified | The TXT record was not found, so the sync fetched nothing. Add the record again, then verify the domain. |
failed | The sync stopped on an error. lastError gives the reason, such as a sitemap that could not be read. The next sync tries again. |
Remove a source
Delete the source in the console, or call DELETE /v1/{orgId}/indexes/{indexName}/sources/{sourceId}. The syncs stop, and Relevan deletes the documents of the pages that the source indexed. The delete runs in the background, so a page can show in search results for a short time. The domain stays claimed.
The API reference lists each route of the Domains and Sources tags
with its request and response.