Link Search Menu Expand Document Documentation Menu

Using a search pipeline

You can use a search pipeline in the following ways:

Specifying an existing search pipeline for a request

After you create a search pipeline, you can use the pipeline with a query by specifying the pipeline name in the search_pipeline query parameter:

GET /my_index/_search?search_pipeline=my_pipeline

For a complete example of using a search pipeline with a filter_query processor, see filter_query processor example.

Using a temporary search pipeline for a request

As an alternative to creating a search pipeline, you can define a temporary search pipeline to be used for only the current query:

POST /my-index/_search
{
  "query" : {
    "match" : {
      "text_field" : "some search text"
    }
  },
  "search_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"
        }
      }
    ]
  }
}

With this syntax, the pipeline does not persist and is used only for the query for which it is specified.

Default search pipeline

For convenience, you can set a default search pipeline for an index. Once your index has a default pipeline, you don’t need to specify the search_pipeline query parameter in every search request.

Setting a default search pipeline for an index

To set a default search pipeline for an index, specify the index.search.default_pipeline in the index’s settings:

PUT /my_index/_settings 
{
  "index.search.default_pipeline" : "my_pipeline"
}

After setting the default pipeline for my_index, you can try the same search for all documents:

GET /my_index/_search

The response contains only the public document, indicating that the pipeline was applied by default:

Response
{
  "took" : 19,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : [
      {
        "_index" : "my_index",
        "_id" : "1",
        "_score" : 0.0,
        "_source" : {
          "message" : "This is a public message",
          "visibility" : "public"
        }
      }
    ]
  }
}

You can search across multiple indexes that share the same default pipeline. For example, alias1 has two indexes, my_index1 and my_index2, both of which have the default pipeline my_pipeline attached to them:

GET /alias1/_search

The response includes only the public version of the document, confirming that the default pipeline was successfully applied:

Response
{
    "took": 59,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": "my_index1",
                "_id": "1",
                "_score": 0.0,
                "_source": {
                    "message": "This is a public message",
                    "visibility": "public"
                }
            }
        ]
    }
}

Disabling the default pipeline for a request

If you want to run a search request without applying the default pipeline, you can set the search_pipeline query parameter to _none:

GET /my_index/_search?search_pipeline=_none

Removing the default pipeline

To remove the default pipeline from an index, set it to null or _none:

PUT /my_index/_settings 
{
  "index.search.default_pipeline" : null
}

PUT /my_index/_settings 
{
  "index.search.default_pipeline" : "_none"
}