# Adding search query term to the input for ml\_inference processor

**URL:** <https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737>\
**Category:** Machine Learning\
**Created:** [December 7, 2024, 10:51pm UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737 "2024-12-07T22:51:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spork](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/spork/32/8225_2.png) [@spork](https://forum.opensearch.org/u/spork)\
**Post date:** [December 7, 2024, 10:51pm UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737/1 "2024-12-07T22:51:56Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
2.17 AWS OS

**Describe the issue** :  
I’d like to add query search term as input in the ml\_inference processor. I followed the example here: [ML inference (response) - OpenSearch Documentation](https://opensearch.org/docs/latest/search-plugins/search-pipelines/ml-inference-search-response/#example-reranking-search-results-using-a-text-similarity-model)

My processor is as follows:

```auto
PUT /_search/pipeline/my_pipeline_request_review_llm
{
  "response_processors": [
    {
      "ml_inference": {
        "tag": "ml_inference",
        "description": "This processor is going to run llm",
        "model_id": "GzeEVZMB-kzw4OgFUNaB",
        "function_name": "REMOTE",
        "input_map": [
          {
            "context": "title",
            "question": "$._request.query.term.title.value"
          }
        ],
        "output_map": [
          {
            "ext.ml_inference.llm_response": "generated_text"
          }
        ],
        "model_config": {
          "prompt": "Based on following context: ${parameters.context.toString()}. Answer the question: ${parameters.question.toString()} ?"
        },
        "ignore_missing": false,
        "ignore_failure": false
      }
    }
  ]
}

```

Running search:

```auto
GET test_tech_news2/_search?search_pipeline=my_pipeline_request_review_llm
{
  "_source": ["title"],
  "query": {
    "term": {
      "title": {
        "value": "Sample Document"
      }
    }
  }
}

```

I get the following response:

```auto
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "cannot find all required input fields: [title, $._request.query.term.title.value] in hit:{\n \"_index\" : \"test_tech_news2\",\n \"_id\" : \"K8PXopMBNsmyby02l4zY\",\n \"_score\" : 0.2876821,\n \"_source\" : {\n \"title\" : \"Sample Document\"\n }\n}"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "cannot find all required input fields: [title, $._request.query.term.title.value] in hit:{\n \"_index\" : \"test_tech_news2\",\n \"_id\" : \"K8PXopMBNsmyby02l4zY\",\n \"_score\" : 0.2876821,\n \"_source\" : {\n \"title\" : \"Sample Document\"\n }\n}"
  },
  "status": 400
}

```

For some reason it’s not letting me use `$._request.query.term.title.value` here. I tried a few workaround but none have worked so far.

Please help

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

**Author:** ![mingshi](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@mingshi](https://forum.opensearch.org/u/mingshi)\
**Post date:** [December 20, 2024, 5:40pm UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737/2 "2024-12-20T17:40:30Z")

</div>

Hi @spork,

I tried to replicate your use case, I found out that it’s your query didn’t return any documents, that’s why it’s not able to get the required field “title” from the processors.

please notice because you’re using a `term` query, which is case-sensitive and looks for exact matches. By default, OpenSearch applies standard analysis to string fields, which includes lowercasing the text.

You can test it out, when creating an index when capital case,

```auto
PUT http://localhost:9200/test_tech_news2/_doc/1
{
    "title": "Sample Document"
}

```

And you try to use term query with the same query text, you will get 0 hit,

```auto
GET http://localhost:9200/test_tech_news2/_search
{
  "_source": ["title"],
  "query": {
    "term": {
      "title": {
        "value": "Sample Document"
      }
    }
  }
}

```

```auto
{
    "took": 9,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

```

But if you use lower case, and search with single word, you will get a hit:

GET [http://localhost:9200/test\_tech\_news2/\_search](http://localhost:9200/test_tech_news2/_search)

```auto
{
  "_source": ["title"],
  "query": {
    "term": {
      "title": {
        "value": "sample"
      }
    }
  }
}

```

```auto
{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.2876821,
        "hits": [
            {
                "_index": "test_tech_news2",
                "_id": "1",
                "_score": 0.2876821,
                "_source": {
                    "title": "Sample Document"
                }
            }
        ]
    }
}

```

Can you please confirm the query you are searching for, there are search hits return, then try to search with search pipeline? Hope this work for you.

---

<div class="post-metadata">

**Author:** ![yeonghyeonKo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/yeonghyeonko/32/8202_2.png) [@yeonghyeonKo](https://forum.opensearch.org/u/yeonghyeonKo)\
**Post date:** [December 21, 2024, 2:34am UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737/3 "2024-12-21T02:34:49Z")

</div>

As @mingshi said, term query is usually used when you want to filter by keyword.

it’s not appropriate to apply search\_pipeline for vector search. You can use match or neural query instead.

---

<div class="post-metadata">

**Author:** ![spork](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/spork/32/8225_2.png) [@spork](https://forum.opensearch.org/u/spork)\
**Post date:** [January 2, 2025, 8:46pm UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737/4 "2025-01-02T20:46:49Z")

</div>

@yeonghyeonKo: “it’s not appropriate to apply search\_pipeline for vector search. You can use match or neural query instead.”

I’m confused by this statement -  
(1) why isn’t it appropriate to use search\_pipeline for vector search?  
(2) doesn’t using “neural query” imply that we’d be searching against vector fields?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [March 3, 2025, 8:47pm UTC](https://forum.opensearch.org/t/adding-search-query-term-to-the-input-for-ml-inference-processor/22737/5 "2025-03-03T20:47:18Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
