繁体   English   中英

通过脚本排序的Elasticsearch查询[语法]

[英]Elasticsearch query with sort by script [syntax]

我正在尝试使用此处建议的随机脚本对查询进行排序

我很难验证和运行查询,因为它不断向我返回错误。

我正在运行的查询是:

{
  "sort": {
    "_script": {
      "script": "(doc['_id'].value + salt).hashCode()",
      "type": "string",
      "params": {
        "salt": "some_random_string"
      },
      "order": "asc"
    }
  },
  "query": {
    "filtered": {
      "filter": {
        "and": [
          {
            "exists": {
              "field": "location"
            }
          },
          {
            "terms": {
              "streamIds": [
                796
              ]
            }
          }
        ]
      }
    }
  }
}

没有排序的查询将工作并返回结果。

我究竟做错了什么?

我试过按照这里建议的查询但无济于事。

发现Elasticsearch从1.4.3开始禁用脚本,这就是为什么它不起作用的原因。

起作用的代码:

{
   "query": {
      "function_score": {
         "query": {
            "filtered": {
               "filter": {
                  "and": [
                     {
                        "exists": {
                           "field": "location"
                        }
                     },
                     {
                        "terms": {
                           "streamIds": [
                              796
                           ]
                        }
                     }
                  ]
               }
            }
         },
         "random_score": {}
      }
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM