Skip to content

[BUG] search pipeline not working inside template with reranking #20730

@asfoorial

Description

@asfoorial

Describe the bug

I am running the following in OpenSearch 3.2.0. Executing the below query works fine with reranking but it fails inside search template.

PUT testindex/_doc/1
{
  "content":"I like to play playstation"
}

PUT testindex/_doc/2
{
  "content":"I am downloading opensearch"
}

PUT testindex/_doc/3
{
  "content":"I would like to go to school"
}

PUT /_search/pipeline/my_pipeline
{
  "description": "Pipeline for reranking with a cross-encoder",
  "response_processors": [
    {
      "rerank": {
        "ml_opensearch": {
          "model_id": "zixilpwBeCNW-ZZWVSNk"
        },
        "context": {
          "document_fields": [
            "content"
          ]
        }
      }
    }
  ]
}

GET testindex/_search
{
  "search_pipeline":"my_pipeline",
  "query": {
    "query_string": {
      "default_field": "content",
      "query": "I"
    }
  },
  "ext": {
    "rerank": {
        "query_context": {
         "query_text": "school"
        }
    }
    
  }
}

In the result, document 3 comes first.

When wrapping the query inside a search template, reranking does not take effect as shown in the below.

POST _scripts/play_search_template
{
  "script": {
    "lang": "mustache",
    "source": """
    {
  "search_pipeline":"my_pipeline",
  "query": {
    "query_string": {
      "default_field": "content",
      "query": "I"
    }
  },
  "ext": {
    "rerank": {
        "query_context": {
         "query_text": "school"
        }
    }
    
  }
}
    """,
    "params": {
      
    }
  }
}

GET testindex/_search/template
{
  "id":"play_search_template"
}

Note that setting search pipeline in the body works fine as shown in the below example.

POST _scripts/play_search_template
{
  "script": {
    "lang": "mustache",
    "source": """
    {
  "search_pipeline":{
    "response_processors": [
      {
        "rerank": {
          "ml_opensearch": {
            "model_id": "zixilpwBeCNW-ZZWVSNk"
          },
          "context": {
            "document_fields": [
              "content"
            ]
          }
        }
      }
    ]
  },
  "query": {
    "query_string": {
      "default_field": "content",
      "query": "I"
    }
  },
  "ext": {
    "rerank": {
        "query_context": {
         "query_text": "school"
        }
    }
    
  }
}
    """,
    "params": {
      
    }
  }
}

GET testindex/_search/template
{
  "id":"play_search_template"
}

Related component

No response

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

.

Additional Details

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions