Rename field processor

The rename_field search response processor intercepts a search response and renames the specified field. This is useful when your index and your application use different names for the same field. For example, if you rename a field in your index, the rename_field processor can change the new name to the old one before sending the response to your application.

Request fields

The following table lists all available request fields.

FieldData typeDescription
fieldStringThe field to rename. Required.
target_fieldStringThe new field name. Required.
tagStringThe processor’s identifier.
descriptionStringA description of the processor.
ignore_failureBooleanIf true, OpenSearch ignores any failure of this processor and continues to run the remaining processors in the search pipeline. Optional. Default is false.

Example

The following example demonstrates using a search pipeline with a rename_field processor.

Setup

Create an index named my_index and index a document with the field message:

  1. POST /my_index/_doc/1
  2. {
  3. "message": "This is a public message",
  4. "visibility":"public"
  5. }

copy

Creating a search pipeline

The following request creates a search pipeline with a rename_field response processor that renames the field message to notification:

  1. PUT /_search/pipeline/my_pipeline
  2. {
  3. "response_processors": [
  4. {
  5. "rename_field": {
  6. "field": "message",
  7. "target_field": "notification"
  8. }
  9. }
  10. ]
  11. }

copy

Using a search pipeline

Search for documents in my_index without a search pipeline:

  1. GET /my_index/_search

copy

The response contains the field message:

Response

  1. {
  2. "took" : 1,
  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" : 2,
  13. "relation" : "eq"
  14. },
  15. "max_score" : 1.0,
  16. "hits" : [
  17. {
  18. "_index" : "my_index",
  19. "_id" : "1",
  20. "_score" : 1.0,
  21. "_source" : {
  22. "message" : "This is a public message",
  23. "visibility" : "public"
  24. }
  25. }
  26. ]
  27. }
  28. }

To search with a pipeline, specify the pipeline name in the search_pipeline query parameter:

  1. GET /my_index/_search?search_pipeline=my_pipeline

copy

The message field has been renamed to notification:

Response

  1. {
  2. "took" : 2,
  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. "visibility" : "public",
  23. "notification" : "This is a public message"
  24. }
  25. }
  26. ]
  27. }
  28. }

You can also use the fields option to search for specific fields in a document:

  1. POST /my_index/_search?pretty&search_pipeline=my_pipeline
  2. {
  3. "fields":["visibility", "message"]
  4. }

copy

In the response, the field message has been renamed to notification:

Response

  1. {
  2. "took" : 4,
  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. "visibility" : "public",
  23. "notification" : "This is a public message"
  24. },
  25. "fields" : {
  26. "visibility" : [
  27. "public"
  28. ],
  29. "notification" : [
  30. "This is a public message"
  31. ]
  32. }
  33. }
  34. ]
  35. }
  36. }