ElasticSearch异常:java.lang.IllegalArgumentException: script_lang not supported

Abnormal

The reason is because the official position parameters for example clerical error, see the official document code is as follows:

UpdateByQueryRequestBuilder updateByQuery =
  UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
updateByQuery.source("source_index")
    .script(new Script(
    	//1
        ScriptType.INLINE,
        //2
        "if (ctx._source.awesome == 'absolutely') {"
            + "  ctx.op='noop'"
            + "} else if (ctx._source.awesome == 'lame') {"
            + "  ctx.op='delete'"
            + "} else {"
            + "ctx._source.awesome = 'absolutely'}",
            +
      	 //3
        "painless",
        //4
        Collections.emptyMap()));
BulkByScrollResponse response = updateByQuery.get();

Official API example code above is provided, this example is wrong, because the correct sequence of configuration parameters Script should be 1,3,2,4, API source code can be a good thing to prove this

 /**
     * Constructor for a script that does not need to use compiler options.
     * @param type :脚本的存储和索引的方式
     * @param lang :脚本语言
     * @param idOrCode  :脚本代码
     * @param params   :脚本绑定用户输入参数
     */
    public Script(ScriptType type, String lang, String idOrCode, Map<String, Object> params) {
        this(type, lang, idOrCode, type == ScriptType.INLINE ? Collections.emptyMap() : null, params);
    }
Published 94 original articles · won praise 55 · views 110 000 +

Guess you like

Origin blog.csdn.net/Suubyy/article/details/87981250