如何使用Java';Elasticsearch的无痛脚本中的ArrayList类?

如何使用Java';Elasticsearch的无痛脚本中的ArrayList类?,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我想为elasticsearch中的脚本得分写一个脚本 在“共享api引用”下有一个java类列表 上面的脚本按预期工作。但我想使用Java的ArrayList或其他类 GET hockey/_search { "explain": true, "query": { "match_all": {} }, "script_fields": { "total_goals": { "script": { "lang": "painless"

我想为elasticsearch中的脚本得分写一个脚本

在“共享api引用”下有一个java类列表

上面的脚本按预期工作。但我想使用Java的ArrayList或其他类

GET hockey/_search
{
  "explain": true, 
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "total_goals": {
      "script": {
        "lang": "painless",
        "source": """
          ArrayList<Integer> al = new ArrayList<Integer>();
          al.add(1);
          al.add(2);
          return al;

        """,
        "params":{
          "last" : "any parameters required"
        }

      }
    }
  }
}

GET hockey/\u搜索
{
“解释”:对,
“查询”:{
“全部匹配”:{}
},
“脚本_字段”:{
“总目标”:{
“脚本”:{
“郎”:“无痛”,
“来源”:”
ArrayList al=新的ArrayList();
al.添加(1);
al.添加(2);
返回al;
""",
“参数”:{
“last”:“所需的任何参数”
}
}
}
}
}
这会引发以下错误

{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "\n          ArrayList<Integer> al = new ArrayL ...",
          "                    ^---- HERE"
        ],
        "script" : "\n          ArrayList<Integer> al = new ArrayList<Integer>();\n          al.add(1);\n          al.add(2);\n          return al;\n          \n        ",
        "lang" : "painless"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "hockey",
        "node" : "UIMgEAZNRzmIpRGyQtNk9g",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "\n          ArrayList<Integer> al = new ArrayL ...",
            "                    ^---- HERE"
          ],
          "script" : "\n          ArrayList<Integer> al = new ArrayList<Integer>();\n          al.add(1);\n          al.add(2);\n          return al;\n          \n        ",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "invalid sequence of tokens near ['<'].",
            "caused_by" : {
              "type" : "no_viable_alt_exception",
              "reason" : null
            }
          }
        }
      }
    ]
  },
  "status" : 400
}

{
“错误”:{
“根本原因”:[
{
“类型”:“脚本异常”,
“原因”:“编译错误”,
“脚本堆栈”:[
“\n ArrayList al=新ArrayL…”,
“^----这里”
],
“脚本”:“\n ArrayList al=new ArrayList();\n al.add(1);\n al.add(2);\n return al;\n\n”,
“郎”:“无痛”
}
],
“类型”:“搜索\阶段\执行\异常”,
“原因”:“所有碎片均失败”,
“阶段”:“查询”,
“分组”:正确,
“失败的\u碎片”:[
{
“碎片”:0,
“索引”:“曲棍球”,
“节点”:“UIMgEAZNRzmIpRGyQtNk9g”,
“理由”:{
“类型”:“脚本异常”,
“原因”:“编译错误”,
“脚本堆栈”:[
“\n ArrayList al=新ArrayL…”,
“^----这里”
],
“脚本”:“\n ArrayList al=new ArrayList();\n al.add(1);\n al.add(2);\n return al;\n\n”,
“郎”:“无痛”,
“原因”:{
“类型”:“非法参数\异常”,

“原因”:“在[”附近的令牌序列无效。您可以使用
ArrayList al=new ArrayList();
或者干脆使用
def al=new ArrayList();
中的更多信息

仅供参考:你可以利用来检查什么是什么

{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "\n          ArrayList<Integer> al = new ArrayL ...",
          "                    ^---- HERE"
        ],
        "script" : "\n          ArrayList<Integer> al = new ArrayList<Integer>();\n          al.add(1);\n          al.add(2);\n          return al;\n          \n        ",
        "lang" : "painless"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "hockey",
        "node" : "UIMgEAZNRzmIpRGyQtNk9g",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "\n          ArrayList<Integer> al = new ArrayL ...",
            "                    ^---- HERE"
          ],
          "script" : "\n          ArrayList<Integer> al = new ArrayList<Integer>();\n          al.add(1);\n          al.add(2);\n          return al;\n          \n        ",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "invalid sequence of tokens near ['<'].",
            "caused_by" : {
              "type" : "no_viable_alt_exception",
              "reason" : null
            }
          }
        }
      }
    ]
  },
  "status" : 400
}