Customer Search enables merchants to search across a large number of Customers in a Project, supporting back-office use cases.
Representations
CustomerSearchRequest
query | The Customer search query. |
sort Array of SearchSorting | Controls how results to your query are sorted. If not provided, the results are sorted by relevance in descending order. |
limit Int | The maximum number of search results to be returned. Default:20 Minimum: 1 Maximum: 100 |
offset Int | The number of search results to be skipped in the response for pagination. Default:0 Minimum: 0 Maximum: 9900 |
{
"query": {
"fullText": {
"field": "all",
"value": "john"
}
}
}
CustomerPagedSearchResponse
total Int | Total number of results matching the query. Minimum:0 |
limit Int | Number of results requested. Minimum: 1 Maximum: 100 |
offset Int | Number of elements skipped. Minimum: 0 Maximum: 9900 |
results Array of CustomerSearchResult | Search result containing the Customers matching the search query. |
{
"results": [
{
"id": "e41337a0-ea96-4ddc-a9a4-d267976f21e0",
"relevance": 0.9264881
},
{
"id": "05cd5998-015c-4232-8943-ff8a1880bcbc",
"relevance": 0.6989829
},
{
"id": "09c3c5a2-6569-49dd-b021-af5de4cf4b02",
"relevance": 0.6989829
}
],
"limit": 100,
"offset": 0,
"total": 3
}
CustomerSearchResult
id String | id of the Customer matching the search query. |
relevance Float | How closely this customer matches the search query. |
CustomerSearchIndexingStatusResponse
status | Current status of indexing the Customer Search. |
states | Progress of indexing. Only available when indexing is in progress. |
startedAt DateTime | Date and time (UTC) when the last indexing started. |
retryCount Int | Indicates how many times the system tried to start indexing after failed attempts. The counter is set to null after an indexing finished successfully. |
lastModifiedAt DateTime | Time when the status was last modified. |
{
"status": "Indexing",
"states": {
"indexed": 43242,
"failed": 0,
"estimatedTotal": 100000
},
"startedAt": "2023-08-15T12:56:07.89Z",
"retryCount": 2,
"lastModifiedAt": "2023-08-15T12:56:07.89Z"
}
CustomerIndexingProgress
indexed Int | The number of Customers successfully indexed. |
failed Int | The number of Customers that failed to be indexed. |
estimatedTotal Int | The estimated total number of Customers to be indexed. |
CustomerIndexingStatus
The current indexing status of Customer Search.
Scheduled
Indexing is scheduled.
Indexing
Indexing is in progress.
Ready
- Indexing is complete and the Search Customers endpoint returns up-to-date results.
Failed
Indexing failed due to an internal error.
Search Customers
view_customers:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String | key of the Project. |
application/json
application/json
Get indexing status
Returns the indexing status of the Customer Search for a Project.
view_project_settings:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String | key of the Project. |
CustomerSearchIndexingStatusResponse
asapplication/json
curl --get https://api.{region}.commercetools.com/{projectKey}/customers/search/indexing-status -i \
--header "Authorization: Bearer ${BEARER_TOKEN}"
Check if Customer Search index exists
200 OK
if an index exists; otherwise, returns a 409 Conflict
.view_customers:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String | key of the Project. |
curl --head https://api.{region}.commercetools.com/{projectKey}/customers/search -i \
--header "Authorization: Bearer ${BEARER_TOKEN}"
Searchable Customer fields
Number and date fields
Standard field | Data type | Query for |
---|---|---|
dateOfBirth | date | Customers with a certain date of birth. |
createdAt | dateTime | Customers created at a certain date and time. |
lastModifiedAt | dateTime | Customers last modified at any of its fields at a certain date and time. |
version | long | Customers with a certain version of the resource. |
Example:
Find Customers signed up in December 2023:
{
"query": {
"range": {
"field": "createdAt",
"gte": "2023-12-01T00:00:00.000Z",
"lt": "2024-01-01T00:00:00.000Z"
}
}
}
Text fields
Standard field | Query for |
---|---|
addresses.all | Customers with a certain string in the combination of all Address fields. |
addresses.city | Customers with a certain string in the city field of all the Customer's addresses. |
addresses.company | Customers with a certain string in the company field of all the Customer's addresses. |
addresses.country | Customers with a certain string in the country field of all the Customer's addresses. |
addresses.firstName | Customers with a certain string in the firstName field of all the Customer's addresses. |
addresses.lastName | Customers with a certain string in the lastName field of all the Customer's addresses. |
addresses.mobile | Customers with a certain string in the mobile field of all the Customer's addresses. |
addresses.phone | Customers with a certain string in the phone field of all the Customer's addresses. |
addresses.postalCode | Customers with a certain string in the postalCode field of all the Customer's addresses. |
addresses.streetName | Customers with a certain string in the streetName field of all the Customer's addresses. |
addresses.streetNumber | Customers with a certain string in the streetNumber field of all the Customer's addresses. |
all | Customers with a certain string in any of the Customer's fields. Does not support wildcard expressions. |
companyName | Customers working for a certain company. |
email | Customers with a certain email address. |
firstName | Customers with a certain first name. |
lastName | Customers with a certain last name. |
middleName | Customers with a certain middle name. |
fullName | Customers with a certain string in their full name as a combination of firstName , middleName , and lastName fields. |
Examples:
Find Customers with the first name of John (case insensitive):
{
"query": {
"fullText": {
"field": "firstName",
"value": "john"
}
}
}
companyName
, but also in email
addresses like email@example.com.{
"query": {
"fullText": {
"field": "all",
"value": "example"
}
}
}
Keyword fields
Standard field | Query for |
---|---|
id | a Customer with a specific id . |
key | a Customer with a specific key . |
customerNumber | a Customer with a specific customerNumber . |
externalId | a Customer with a specific externalId . |
vatId | a Customer with a specific vatId . |
customerGroupAssignments.customerGroup.id BETA | Customers with CustomerGroupAssignment identified by the id of the CustomerGroup. |
customerGroup.id | Customers with a specific CustomerGroup identified by its id . |
stores.key | Customers of a specific Store identified by its key . |
Example:
Find Customers associated with one of the specified Stores:
{
"query": {
"or": [
{
"exact": {
"field": "stores.key",
"value": "store1"
}
},
{
"exact": {
"field": "stores.key",
"value": "store2"
}
},
{
"exact": {
"field": "stores.key",
"value": "store3"
}
}
]
}
}
Custom Fields
custom.<field-name>
queries for Customers with a Custom Field of a specific name, and the SearchFieldType determines the data type of the field.ltext
SearchFieldType is not supported.accountPlan
to the enum key of silver
.{
"query": {
"exact": {
"field": "custom.accountPlan.key",
"value": "silver",
"fieldType": "enum"
}
}
}