创建搜索管道
搜索管道存储在集群状态中。要创建搜索管道,您必须在 OpenSearch 集群中配置一个有序的处理器列表。您可以在管道中拥有多个相同类型的处理器。每个处理器都有一个 tag
标识符,用于将其与其他处理器区分开来。标记特定处理器在调试错误消息时会很有帮助,尤其是在添加多个相同类型的处理器时。
请求示例
以下请求创建一个搜索管道,其中包含一个 filter_query
请求处理器,该处理器使用术语查询仅返回公共消息;以及一个响应处理器,该处理器将字段 message
重命名为 notification
PUT /_search/pipeline/my_pipeline
{
"request_processors": [
{
"filter_query" : {
"tag" : "tag1",
"description" : "This processor is going to restrict to publicly visible documents",
"query" : {
"term": {
"visibility": "public"
}
}
}
}
],
"response_processors": [
{
"rename_field": {
"field": "message",
"target_field": "notification"
}
}
]
}
忽略处理器故障
默认情况下,如果搜索管道的某个处理器失败,管道将停止。如果您希望管道在处理器失败时继续运行,可以在创建管道时将该处理器的 ignore_failure
参数设置为 true
"filter_query" : {
"tag" : "tag1",
"description" : "This processor is going to restrict to publicly visible documents",
"ignore_failure": true,
"query" : {
"term": {
"visibility": "public"
}
}
}
如果处理器失败,OpenSearch 将记录该故障并继续运行搜索管道中的所有剩余处理器。要检查是否存在任何故障,可以使用搜索管道指标。
更新搜索管道
要动态更新搜索管道,请使用搜索管道 API 替换现有搜索管道。
请求示例
以下示例请求通过添加 filter_query
请求处理器和 rename_field
响应处理器来 upsert(更新或插入)my_pipeline
PUT /_search/pipeline/my_pipeline
{
"request_processors": [
{
"filter_query": {
"tag": "tag1",
"description": "This processor returns only publicly visible documents",
"query": {
"term": {
"visibility": "public"
}
}
}
}
],
"response_processors": [
{
"rename_field": {
"field": "message",
"target_field": "notification"
}
}
]
}
搜索管道版本
创建管道时,可以在 version
参数中为其指定版本
PUT _search/pipeline/my_pipeline
{
"version": 1234,
"request_processors": [
{
"script": {
"source": """
if (ctx._source['size'] > 100) {
ctx._source['explain'] = false;
}
"""
}
}
]
}
在所有后续的 get pipeline
请求响应中都会提供版本
GET _search/pipeline/my_pipeline
响应包含管道版本
响应
{
"my_pipeline": {
"version": 1234,
"request_processors": [
{
"script": {
"source": """
if (ctx._source['size'] > 100) {
ctx._source['explain'] = false;
}
"""
}
}
]
}
}