下面的弹性查询有什么问题?

时间:2018-08-29 18:26:58

标签: elasticsearch

我希望最大值按desc顺序匹配数据。我写了这个脚本

{   
    "size": 100,
    "from": 0,
    "sort": [
        {
             "_script": {
                 "script":{
                     "source":"int total = 0; for (int i = 0; i < params.words.length; ++i) { if(doc['orgname'].indexOf(params.words[i])!=-1)total+=1; } return total;",
                     "params": {
                         "words": ["script", "bees", "org"]
                     }
                 },
                 "type": "number",
                 "order":"desc"
             }
         }
     ],
"query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "orgname": {
              "value": "script"
            }
          }
        },
        {
          "wildcard": {
            "orgname": {
              "value": "bees"
            }
          }
        },
        {
          "wildcard": {
            "orgname": {
              "value": "org"
            }
          }
        },
        {
            "prefix": {
                "orgname": {
                    "value": "scriptbees org"
                }
            }
        }
      ]
    }
  }
}
     

}

但是此查询抛出以下错误

  

{       “ error”:“ SearchPhaseExecutionException [无法执行阶段[query_fetch],所有分片均失败; shardFailures {[IQiimpLORCaXNtoHjJWR1A] [vmqa] [0]:SearchParseException [[vmqa] [0]:从[0],尺寸[100]:解析失败[无法解析源[{\ n \“ size \”:100,\ n \“从\”:0,\ n \“ sort \”:[\ n \ t {\ n \“ _ script \” :{\ n \“ script \”:{\ n \“ source \”:\“ int总计= 0; for(int i = 0; i

谁能给我正确的语法。 谢谢

0 个答案:

没有答案