Skip to main content

SitecoreAI · Tutorial

Indexing XM Cloud Content with a Sitecore Search API Crawler

Point a Sitecore Search API crawler at Experience Edge, map the results with a JS extractor, and add new attributes end to end.

GavAusWeb2 min read

Sitecore Search doesn't read your content tree directly. An API crawler asks Experience Edge for items over GraphQL, and a document extractor turns the response into searchable documents. Three pieces: a trigger, an extractor, and the attributes that hold the output.

Create the sourceLink to this section

In Sitecore Search (CEC), go to Sources › Add Source and pick API Crawler. The Source Settings left nav is where you'll spend your time: Triggers, Document Extractors, Tags Definition, Crawler Schedule and friends.

The request triggerLink to this section

Add a trigger of type Request, method POST, with the header Content-Type: application/json. The URL is your Experience Edge GraphQL endpoint:

text
https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1?sitecoreContextId=<context-id>

The body is a GraphQL query. Written out readably, it looks like this:

graphql
{
  item(path: "/sitecore/content/your-tenant/your-site/Data", language: "en") {
    children(includeTemplateIDs: ["<template-id>"]) {
      results {
        name
        id
        url { path }
        title: field(name: "Title") { value }
      }
    }
  }
}

CEC wants it pasted as an escaped JSON string, so wrap it as {"query": "..."} with the quotes and newlines escaped.

The document extractorLink to this section

Add a Document Extractor of type JS with the tagger set to content. It receives the response and returns one document per item:

js
function extract(request, response) {
  const items = response.body?.data?.item?.children?.results ?? [];
  return items.map((item) => ({
    id: item.id,
    type: 'article',
    name: item.name,
    title: item.title?.value ?? '',
    url: item.url?.path ?? '',
  }));
}

Adding a new field end to endLink to this section

  1. Step 1: Query and map it

    Add the field to the GraphQL query, then map it in the extractor.

  2. Step 2: Create the attribute

    In Administration › Domain Settings › Attributes, click Add Attribute. Set Entity to content and Data Type to String.

  3. Step 3: Return it in the API

    In the attribute’s Properties, tick Return In Api Response (and Available For Quick Look if you want it in previews), then save.

  4. Step 4: Publish and recrawl

    Publish the domain settings, re-publish the source and recrawl. Then open Content Collection › Content and check that the documents carry the new attribute.