Overview

The Algolia Search service is responsible for managing the published product data so that users can access it in a quick and easy way.

This service uses Algolia for data indexation. To use Algolia, users need to configure the Algolia credentials and activate it. For more information, see the Algolia website.

Once everything is properly configured, the public products from the Product service are automatically indexed. The following product attributes given in the English language are used for indexing:

  • Name
  • Description
  • Product attributes defined in mixins

The public products indexed in Algolia can store the information about the categories to which these products belong. This information comes from the Category service, and the Algolia Search service relays this data to the Algolia. As a result, it is possible to create facets based on the product categories. Algolia uses category names for creating these facets that considerably narrow the search results that are returned to the user.

To query the indexed data, you should query the Algolia service directly. For details, see Query Product Index.


API Reference

/{tenant}/project/configuration

/{tenant}/project/configuration

get

Get Algolia configuration for project. If user doesn't have hybris.search-algolia_read scope then only not restricted data is returned. The restricted properties are: credentials.writeKey and credentials.backofficeSearchKey

Supported scopes:

  • hybris.search-algolia_read

/{tenant}/project/configuration/activation

put

activation endpoint is deprecated. If indexing configuration (/{tenant}/project/configuration/indexing) is not set, the indexation of published product is activated based on activation value.

Required scopes:

  • hybris.search-algolia_manage
get

activation endpoint is deprecated. Please use /{tenant}/project/configuration/indexing instead. Get algolia activation status.

delete

activation endpoint is deprecated. Please use /{tenant}/project/configuration/indexing instead. Deactivate algolia integration.

Required scopes:

  • hybris.search-algolia_manage

/{tenant}/project/configuration/indexing

get

Get Algolia indexing configuration.

put

Save Algolia index configuration. Based on the provided indexing configuration only specified types of products will be indexed in Algolia. Required scopes:

  • hybris.search-algolia_manage
delete

Remove indexing configuration for Algolia.

Required scopes:

  • hybris.search-algolia_manage

/{tenant}/project/configuration/credentials

put

Save Algolia index credentials. Required scopes:

  • hybris.search-algolia_manage
get

Get Algolia index credentials. If user doesn't have hybris.search-algolia_read scope then only not restricted data are returned. The restricted properties are: writeKey and backofficeSearchKey Supported scopes:

  • hybris.search-algolia_read
delete

Delete credentials.

Required scopes:

  • hybris.search-algolia_manage

/{tenant}/project/configuration/validation/searchkey

put

Returns information if search key is valid for provided application and index. Required scopes:

  • hybris.search-algolia_manage

/{tenant}/indexing/jobs

/{tenant}/indexing/jobs

post

Create job for indexing. Required scopes:

  • hybris.search-algolia_index
get

Get all jobs. Required scopes:

  • hybris.search-algolia_read


Scopes in the Algolia Search Service

Scopes enable you to specify exactly what type of access you need for resources and operations in the Algolia Search service.

The following table presents all the scopes supported by the Algolia Search service.

ScopeDescription
hybris.search-algolia_manageUse this scope to manage index mixin configuration, which involves create, change, and delete operations.
hybris.search-algolia_readUse this scope to get read-only access to the index mixin configuration and Algolia index information.
hybris.search-algolia_indexUse this scope to run the Algolia indexing process.

For more information about the authorization and authentication used in SAP Hybris services, as well as about scopes in general, see:


Indexed Attributes

There are several product attributes given in the English language that are used for indexing:

  • name: The product name.
  • code: User-defined unique identifier of a product.
  • sku: Same as code, kept alive for the purpose of backward compatibility
  • description: Descriptive information about the product.
  • prices: The originalAmount from the price stored in the Price service. This works for all currencies.
  • image: The first image of the product taken from the Product service.
  • popularity: Product popularity. The calculation is based on the number of completed orders.
  • categories: Information about category which the product belongs to. Includes full category path for a product. This information is taken from the Category service.
  • category_levels: Categories grouped by the tree level. This is taken from the Category service.
  • mixins: Custom product attributes defined in the product mixins.
Currently, only English translations of the localized name and description product attributes are indexed.


Activate Algolia

You can activate Algolia to enable customer products to be indexed in Algolia. You can disable the indexing feature by deactivating Algolia.

Algolia activation is tenant-specific, which means you enable the search for all customers who use that tenant. To activate or deactivate Algolia, you must use the hybris.search-algolia_manage scope.

You need to configure Algolia credentials for the products to be correctly indexed in the Algolia index.

Indexing status check

You can check if Algolia indexing configuration is enabled or not with help of the /{tenant}/project/configuration/indexing endpoint. Use GET method to get Algolia information whether indexing configuration is enabled or not.

Such request can be responded in two ways:

  • Response status code 200: Indexing configuration has been successfully retrieved. Note that the response payload contains information about which products are indexed and which are not. For example, index configuration checked here states that published products are indexed while non-published products are not indexed. Note that both can be false, and it still means the indexing configuration exists and the code will be 200.
    {
    "activePublishedProductIndexing":true,
    "activeNonPublishedProductIndexing":false
    }
    
  • Response status code 404: Indexing configuration is not set.

Now, if the status code of the response is 404, then the indexing configuration does not exist, and the fallback mechanism comes into action. The service uses GET method on the /{tenant}/project/configuration/activation to do the checking. If the GET on /activation returns 404 - indexing of public products is disabled), nothing is indexed. If GET on /activation returns 200 OK, then only public products will be indexed.

Switch on the indexing

You enable indexing of your items in Algolia with help of the following:

  • Method: PUT
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/indexing
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

Together with a request, you send a payload that is used to set the following flags, responsible for indexing of published and/or unpublished products. For example, let's enable indexing of published products, while the non-published products will not be indexed.

{
  "activePublishedProductIndexing":true,
  "activeNonPublishedProductIndexing":false
}
These settings are valid for every new product or any product that have been updated. However, if no action occurs in existing products, they remain unchanged until next reindexing with the new or modified configuration is triggered.

Switch off the indexing

You disable indexing of your items in Algolia by requesting PUT /{tenant}/project/configuration/indexing together with the following payload:

{
  "activePublishedProductIndexing":false,
  "activeNonPublishedProductIndexing":false
}

After this request either published nor unpublished product will be indexed.

The other option to disable indexing in Algolia is:

  • Method: DELETE
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/indexing
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

The DELETE method removes index configuration for Algolia.

If indexing configuration is removed, the service makes fallback to the deprecated /activation endpoint methods, more specifically it performs GET on /{tenant}/project/configuration/activation. The outcome of this fallback can be:

  • If GET on /{tenant}/project/configuration/activation returns 200, it means the indexing of public products only is on
  • If GET on /{tenant}/project/configuration/activation returns 404, it means the indexing is off, and nothing is indexed

Deprecated endpoints

If you use the new indexing configuration, there is no need for you to use the old endpoints presented below in the next sections. From now one they are deprecated, and may be removed at the very next service version. Briefly speaking, if you have new indexing configuration, those endpoints shown below are not used.

However, if you do not have the new indexing configuration, then you are still able to use these old and deprecated endpoints for as long as they remain available.

Retrieve Indexing Activation Status
  • Method: GET
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/activation
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

Response includes status codes:

  • 200: Indexing of public products is on.
  • 404: Indexing is off.
Activate Algolia Integration
  • Method: PUT
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/activation
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.
Deactivate Algolia Integration
  • Method: DELETE
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/configurations/algolia/activation
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.


Manage Algolia Credentials

Create Algolia credentials

You must configure the Algolia index by creating appropriate credentials. To create Algolia credentials, you need the hybris.search-algolia_manage scope and the following:

  • Method: PUT
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/credentials
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

The request body should contain the following attributes:

{
    "applicationId": "MY-APPLICATION-ID",
    "searchKey": "SEARCH-KEY",
    "writeKey": "SECRET-WRITE-KEY",
    "indexName": "MY-INDEX-IN-ALGOLIA",
    "backofficeSearchKey": "BACK-OFFICE_KEY"
}
  • applicationId: Public. One user can have multiple applications under one Algolia account. This field indicates under which application products should be indexed.
  • indexName: Public. Index is an entity within Algolia where the products are imported, so that users can search for them.
  • searchKey: Public. This is the public search key to use in the front-end code, such as in the JavaScript in your website. This key is read-only and allows you to retrieve only the published products.
  • writeKey: Non-public. This is not a public key and as such should be kept secret. It is used by the back-end application to execute write operations on your index. Only users with the hybris.search-algolia_read scope can see this key.
  • backofficeSearchKey: This read-only key - while used for search - returns only those products that have the _tags attribute defined. This attribute must have one of the following values per product: published or unpublished. The key requires appropriate scope to be visible for a user. Only users with the hybris.search-algolia_read scope can see this key.
The backofficeSearchKey is generated for all _tags values: both published and unpublished, while the searchKey is generated only for _tags having the published value.
The _tags attribute is added to each and every product in Algolia index. The _tags attribute can have two values: published or unpublished. The value is based on the product boolean attribute published, which accepts one of two values: true or false. The _tags property originates in Algolia, and is used for search. Only those products that have _tags as part of their index are searchable. Searching by _tags attribute is the feature provided by Algolia and depends on the Algolia search mechanisms.

For more information about creating Algolia credentials, see the Algolia website.

Delete Algolia credentials

The hybris.search-algolia_manage scope is required to delete Algolia credentials.

  • Method: DELETE
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/credentials
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

Retrieve Algolia credentials

The front-end application can make a GET request to collect credentials for a particular tenant.

  • Method: GET
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/credentials
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

The hybris.search-algolia_read scope scope is required by any application that needs to read non-public Algolia credentials, while the public credentials are available even if no scope is provided.

  • hybris.search-algolia_read: You can obtain all Algolia index credentials, including writeKey and backofficeSearchKey
  • other scopes: You can only get the three public credentials, but you cannot get the writeKey nor backofficeSearchKey


Validate Algolia Credentials

Currently, you can only validate the searchKey attribute.

Validate Algolia searchKey

You can validate the searchKey attribute for a specific application and index name. The hybris.search-algolia_manage scope is required for this operation.

  • Method: PUT
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/validation/searchkey
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

The request body should contain the following attributes:

{
    "applicationId": "MY-APPLICATION-ID",
    "searchKey": "SEARCH-KEY",
    "indexName": "MY-EXISTING-INDEX-IN-ALGOLIA"
}
  • applicationId: Public. One user can have multiple applications under one Algolia account. This field indicates under which application the products should be indexed.
  • indexName: Public. The index is an entity within Algolia where the products are imported, so that users can search for them.
  • searchKey: Public. This is the public search key to use in the front-end code, such as in the JavaScript in your website. This key is read-only and can only be used for search queries.

Response

A successful response includes a status code of 200, which indicates that the Algolia credentials have been successfully validated without making any changes in the Algolia configuration.

Because the https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/project/configuration/validation/searchkey endpoint does not make any change, the response body is empty.

Validation with errors

If the validation fails, the service provides a feedback message. Following is an example of the response definition:

{
  "status": 400,
  "type": "business_error",
  "message": "Index validation failed.",
  "details": [
      {
        "type": <type>,
        "message": <message>
      },
        ...
  ]
}

In addition to the status code and type attribute referring to the original request, the response contains the details attribute that includes a more descriptive explanation of the error:

Following are the possible type values from details that may be returned if the validation fails:

  • invalid_api_key - searchKey is invalid or searchKey does not grant access to index
  • unknown_application_id - Invalid application ID
  • invalid_index - Index with specified name does not exist


Update Product Index

The Algolia index must be filled with product details before the products can be found in Algolia.

If Algolia is properly configured and activated, the index gets updated based on the actions taken in the Product service:

  • If the updated product is published, then the product data is created/updated in the product index.
  • If the product is unpublished, it is removed from the product index.
  • If a product is removed from the Product service, it is also removed from the product index.

It can take some time for the changes in the index configuration to be applied. The results of full text and faceted searching are not influenced instantaneously, but rather over time.

Public products are only indexed if Algolia integration is activated. See Activate Algolia.


Reindex products in Algolia

There are situations when the index state is not synchronized with the product details data. For example:

  • Algolia is properly configured and activated after new products have been created.
  • Algolia credentials provided in the configuration became invalid and product update events could not be handled properly.
  • Algolia was deactivated by a user.

To synchronize the Algolia index with product details, the indexing process must be triggered.

Full product (re)indexing

Users can trigger the indexing process, which will clear the index content and refill it with the public product details.

  • Full Indexation process can take some time. Users can check if the operation still runs or it has been completed.
  • It is recommended that users do not update the products, categories, prices while the indexing operation is running.

Create a full indexing job for the Algolia index

To index all products in Algolia, you need:

  • Method: POST
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/indexing/jobs
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.

The successful response includes the status code 201 CREATED. It informs the user that the request is accepted for execution. The user can check the status of the indexing job to verify whether the operation has finished.

Retrieve all indexing jobs

To retrieve all indexing jobs, you need:

  • Method: GET
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/indexing/jobs
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.
  • URL Path Parameter:
    • {tenant}: A tenants's name.
  • Query Parameter:
    • q: Users can use the query to make their search results more specific. For example:
      • If a string value does not have any special characters or spaces, you can omit the quotation marks. For example: ?q=status:COMPLETED
      • To search for more than one value at a time, put the string values in parentheses () and separate them with commas. For example: ?q=createdBy:("john.smith@hybris.com","mary.smith@hybris.com","zenon.skoczylas@hybris.com")

The successful response includes the status code 200 OK, and the payload is similar to the following example:

[
  {
    "id": "545b4e3dfaee4c10def3db24",
    "tenant": "MyTenant",
    "status":"COMPLETED",
    "createdBy":"mary.smith@hybris.com"
  },
  {
    "id": "545b4e3dfaee4c10def3db24",
    "tenant": "MyTenant",
    "status":"PROCESSING",
    "createdBy":"john.smith@hybris.com"
  },
  {
    "id": "454c2f5fdsrr7b43ghj5bd42",
    "tenant": "MyTenant",
    "status":"COMPLETED",
    "createdBy":"zenon.skoczylas@hybris.com"
  }
]

Retrieve a single indexing job

To retrieve one particular indexing job, you need:

  • Method: GET
  • Request URL: https://api.beta.yaas.io/hybris/search-algolia/v1/{tenant}/indexing/jobs/{jobId}
  • Headers:
    • Authorization: You must provide a proper scope that enables users to perform these operations. The scopes should be granted in an access token from OAuth 2.0 service. For more information about the authorization and authentication used in hybris services, see Authorization. For more information about the scopes in the Algolia Search service, see Scopes in the Algolia Search Service.
  • URL Path Parameter:
    • {tenant}: A tenants's name.
    • {jobId}; The unique identifier of the indexing job.

The successful response includes the status code 200 OK, and the payload is similar to the following:

{
  "id": "545b4e3dfaee4c10def3db24",
  "tenant": "MyTenant",
  "status":"PROCESSING",
  "createdBy":"john.smith@hybris.com"
}


Import Product Index

Currently, the Algolia Search service does not provide a way to import data if no indexation event has been handled.


Query Product Index

To query a product index, you must know your algolia_key, which is automatically generated when you activate Algolia integration.

Get an Algolia Key

You can retrieve the value of the algolia_key from the Configuration service.

  • Method: GET
  • Request URL: https://api.beta.yaas.io/hybris/configuration/v1/{tenant}/configurations/algolia_key

This is a sample response from the Configuration service:

{
    "key": "algolia_key",
    "value": "7954666ef7253aae07f78e7b71ae586c"
}

Query Algolia

After retrieving the key, you can start querying Algolia for the results. For detailed instructions on how to query an index, see the Algolia website:

To query Algolia, you need:

  • application id: This is your Algolia application id. You can find it in your Algolia account settings.
  • algolia_key: You can retrieve the value of this key by doing GET on /{tenant}/project/configuration. This key can be one of the following:
    • searchKey: Read-only, can be used to search for published products only. This key is safe to be used in JavaScript storefront application, as it only allows to query products which were marked as published.
    • backofficeSearchKey: Read-only, can be used to search any indexed product (published and unpublished). You should better keep it secret to not expose confidential data.


Error Types

For more information about possible errors in the Algolia Search service, see the API Reference section.
For general information about error types in SAP Hybris services, see Errors.


Glossary

TermDescription
facetedSearch setting option, configured for the Product fields. If set to `true`, the given attribute is used for faceted navigation.
searchableSearch setting option, configured for Product fields in the PCM service. If set to `true`, the given configuration attribute is used for search.


  • Send feedback

    If you find any information that is unclear or incorrect, please let us know so that we can improve the Dev Portal content.

  • Get Help

    Use our private help channel. Receive updates over email and contact our specialists directly.

  • hybris Experts

    If you need more information about this topic, visit hybris Experts to post your own question and interact with our community and experts.