在Reactor API中搜索资源
Reactor API中的/search
端点允许您对存储的资源进行结构化查询。 本文档针对各种常见用例提供不同的搜索查询示例。
NOTE
在阅读本指南之前,请参阅搜索端点指南,了解有关接受的查询语法和其他使用准则的信息。
基本查询策略
以下示例演示了使用API搜索功能的一些基本概念。
跨多个字段搜索
通过在字段名称中使用通配符,可以跨多个字段执行搜索。 例如,要跨多个属性字段进行搜索,请使用attributes.*
作为字段名。
{
"data": {
"query": {
"attributes.*": {
"value": "evar7"
}
}
}
}
IMPORTANT
通常,搜索值必须与要搜索的数据类型匹配。 例如,针对整数字段的查询值
evar7
将失败。 跨多个字段搜索时,查询类型要求会放宽以避免错误,但可能会产生不需要的结果。将查询范围限定为特定资源类型
通过在请求中提供resource_types
,可以将搜索范围限定为特定资源类型。 例如,要跨data_elements
和rule_components
搜索:
{
"data": {
"from": 0,
"size": 25,
"query": {
"attributes.display_name": {
"value": "Performance"
}
},
"resource_types": [
"data_elements",
"rule_components"
]
}
}
排序响应
sort
属性可用于对响应进行排序。 例如,要按created_at
排序,最新的先排序:
{
"data": {
"from": 0,
"size": 25,
"query": {
"attributes.display_name": {
"value": "Performance"
}
},
"sort": [
{
"attributes.created_at": "desc"
}
],
"resource_types": [
"data_elements",
"rule_components"
]
}
}
常见搜索示例
以下示例演示了其他常见搜索模式。
具有特定名称的任何资源
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"attributes.name": {
"value": "Adobe"
}
}
}
}'
任何引用“evar7”的资源
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"attributes.*": {
"value": "evar7"
}
}
}
}'
“custom-code”委托类型的数据元素
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"attributes.delegate_descriptor_id": {
"value": "custom-code"
}
},
"resource_types": ["data_elements"]
}
}'
引用特定数据元素的规则组件
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"attributes.settings": {
"value": "myDataElement8"
}
},
"resource_types": ["rule_components"]
}
}'
特定属性中的规则
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"relationships.property.data.id": {
"value": "PR3cab070a9eb3423894e4a3038ef0e7b7"
}
},
"resource_types": ["rules"]
}
}'
按ID查找资源
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"id": {
"value": "PR3cab070a9eb3423894e4a3038ef0e7b7"
}
}
}
}'
使用“OR”术语逻辑执行搜索
curl -X POST \
https://reactor.adobe.io/search \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H 'x-api-key: {API_KEY}' \
-H 'x-gw-ims-org-id: {ORG_ID}' \
-H "Content-Type: application/vnd.api+json" \
-H 'Accept: application/vnd.api+json;revision=1' \
-d '{
"data": {
"query": {
"attributes.display_name": {
"value": "My Rule Holiday Sale",
"value_operator: "OR"
}
}
}
}'
recommendation-more-help
12b4e4a9-5028-4d88-8ce6-64a580811743