ElasticSearch6.5.0 【script_lang not supported】


執行代碼:【就是想根據條件更新】把品牌為LiNing的都改成Cat。

UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
updateByQuery.source("clothes")
    .size(100)  // 嘗試獲取的最大文檔數
    .filter(QueryBuilders.matchQuery("brand","LiNing"))  // 查詢brand=LiNing的
    .script(new Script(
        ScriptType.INLINE, 
        "ctx._source['brand'] = 'Cat'",
        Script.DEFAULT_SCRIPT_LANG,
        Collections.emptyMap()))
    .abortOnVersionConflict(false); // 版本沖突策略:abortOnVersionConflict 版本沖突時不終止

 

報錯如下:

Exception in thread "main" java.lang.IllegalArgumentException: script_lang not supported [ctx._source['brand'] = 'Cat']
    at org.elasticsearch.script.ScriptService.getEngine(ScriptService.java:239)
    at org.elasticsearch.script.ScriptService.compile(ScriptService.java:293)
    at org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$ScriptApplier.apply(AbstractAsyncBulkByScrollAction.java:798)
    at org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$ScriptApplier.apply(AbstractAsyncBulkByScrollAction.java:759)
    at org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.buildBulk(AbstractAsyncBulkByScrollAction.java:207)
    at org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.prepareBulkRequest(AbstractAsyncBulkByScrollAction.java:317)
    at org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$1.doRun(AbstractAsyncBulkByScrollAction.java:280)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState$RunOnce.doRun(WorkerBulkByScrollTaskState.java:321)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState$DelayedPrepareBulkRequest$1.doRun(WorkerBulkByScrollTaskState.java:257)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Process finished with exit code 1

一開始我以為是有依賴沒導進來,在網上查有人說要導入groovy-all的包,結果簡直是放屁。

現在我們來看官網的示例:

一共四個參數,分別代表:腳本類型、腳本內容、lang,params。我的順序跟它一模一樣,第二個是腳本第三個是lang。真是嗶了狗了。

Java客戶端API和人家提供的curl方式是有異曲同工之妙的,那我們看一下前端版本:主要看人家的變量命名

最后,我看Java客戶端API的定義!!!順序是:↓↓↓  我發現 "lang": "painless" 應該在第2個位置!!第3個位置才是腳本內容!!

    public Script(ScriptType type, String lang, String idOrCode, Map<String, Object> params) {
        this(type, lang, idOrCode, type == ScriptType.INLINE ? Collections.emptyMap() : null, params);
    }

麻蛋,官方都搞反了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM