【问题标题】:Elasticsearch search template not working with terms queryElasticsearch 搜索模板不适用于术语查询
【发布时间】:2017-09-05 11:06:31
【问题描述】:

我有一个长字段的索引,我只是想使用搜索模板来使用术语查询,但它会引发异常。

"pid": {
         "type": "long"
       }

搜索模板: PUT /_search/template/article_query_template

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

搜索查询:

POST test2*/_search

{
  "query": {
          "template": {
              "id": "article_query_template", 
              "params" : {
                  "articleId" : ["1"]
              }
          }
      }
}

例外:原因”:“[terms] 查询不支持 [pid]”。

它在没有模板的情况下工作。如何解决此问题。

【问题讨论】:

  • 不确定您的模板定义中是否需要 query 两次。
  • @Val 我已删除单个查询并尝试测试,但再次遇到相同的异常。
  • 你用的是哪个版本的ES?
  • @val ES 2.4.1 版本

标签: elasticsearch search


【解决方案1】:

像这样创建你的模板:

{
"source": {
    "query": {
        "term": {
            "message": "{{query_string}}"
        }
    }
}
}

并传递如下参数:

{
"id": "<templateName>", 
"params": {
    "query_string": "search for these words"
}}

更多详情请见here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多