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:

  1. GET /my_index/_search?search_pipeline=my_pipeline

copy

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:

  1. POST /my-index/_search
  2. {
  3. "query" : {
  4. "match" : {
  5. "text_field" : "some search text"
  6. }
  7. },
  8. "search_pipeline" : {
  9. "request_processors": [
  10. {
  11. "filter_query" : {
  12. "tag" : "tag1",
  13. "description" : "This processor is going to restrict to publicly visible documents",
  14. "query" : {
  15. "term": {
  16. "visibility": "public"
  17. }
  18. }
  19. }
  20. }
  21. ],
  22. "response_processors": [
  23. {
  24. "rename_field": {
  25. "field": "message",
  26. "target_field": "notification"
  27. }
  28. }
  29. ]
  30. }
  31. }

copy

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:

  1. PUT /my_index/_settings
  2. {
  3. "index.search.default_pipeline" : "my_pipeline"
  4. }

copy

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

  1. GET /my_index/_search

copy

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

Response

  1. {
  2. "took" : 19,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 1,
  13. "relation" : "eq"
  14. },
  15. "max_score" : 0.0,
  16. "hits" : [
  17. {
  18. "_index" : "my_index",
  19. "_id" : "1",
  20. "_score" : 0.0,
  21. "_source" : {
  22. "message" : "This is a public message",
  23. "visibility" : "public"
  24. }
  25. }
  26. ]
  27. }
  28. }

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:

  1. GET /alias1/_search

copy

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

Response

  1. {
  2. "took": 59,
  3. "timed_out": false,
  4. "_shards": {
  5. "total": 2,
  6. "successful": 2,
  7. "skipped": 0,
  8. "failed": 0
  9. },
  10. "hits": {
  11. "total": {
  12. "value": 1,
  13. "relation": "eq"
  14. },
  15. "max_score": 0.0,
  16. "hits": [
  17. {
  18. "_index": "my_index1",
  19. "_id": "1",
  20. "_score": 0.0,
  21. "_source": {
  22. "message": "This is a public message",
  23. "visibility": "public"
  24. }
  25. }
  26. ]
  27. }
  28. }

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:

  1. GET /my_index/_search?search_pipeline=_none

copy

Removing the default pipeline

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

  1. PUT /my_index/_settings
  2. {
  3. "index.search.default_pipeline" : null
  4. }

copy

  1. PUT /my_index/_settings
  2. {
  3. "index.search.default_pipeline" : "_none"
  4. }

copy