Search template not working with terms query


(Narmatha) #1

I have an index with a long field and i am just trying to use search template to use terms query but it throws exception.

"pid": {
"type": "long"
}
Search Template: PUT /_search/template/article_query_template

{
"template": {
"query": {
"terms": {
"pid": "{{articleId}}"
}
}
}
}
Search Query :

POST test2*/_search

{
"query": {
"template": {
"id": "article_query_template",
"params" : {
"articleId" : [1, 2]
}
}
}
}
Exception : reason": "[terms] query does not support [pid]".

Its working without template. How to fix this issue.


(Adrien Grand) #2

Since you are passing a json array, you need to escape it:

GET _search/template
{
  "template": """{
    "query": {
      "terms": {
        "pid": {{#toJson}}articleId{{/toJson}}
      }
    }
  }""",
  "params": {
    "articleId": [
      1,
      2
    ]
  }
}

(Narmatha) #3

It shows error without quotes {{#toJson}}articleId{{/toJson}}.

Also array search thows exception "reason": "For input string: ""articleId""".

The field is of type long.


(system) #4

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