【问题标题】:How to use addScriptParam during updating a document in elasticsearch 5.2?如何在 elasticsearch 5.2 中更新文档时使用 addScriptParam?
【发布时间】:2017-08-29 15:14:50
【问题描述】:

如何在使用 java api 在 elasticsearch 中更新文档时使用 addScriptParam,我刚刚从 1.6.0 版升级到更新的 Elasticsearch 5.2 版,我在以下代码中获得了编译时间

for (n<-0 to followList.size-1) {
          var newObject:java.util.Map[String,Object] = Maps.newHashMap();
          var follow=followList.get(n)
          var followuuid=follow.getFollowID
          var uuidType=follow.getClassType().toString()
          newObject.put("FollowingItemUuid",followuuid)
          newObject.put("FollowingItemUuidType",uuidType)
          bulkRequest.add(client.prepareUpdate("testdb", ARTISTUSER_COLLECTION_NAME, artistUser.uuid)
          .addScriptParam("newObject", newObject)  
          .setScript(new Script(script.ScriptType.INLINE,"ctx._source.FollowingItems += newObject",null,null)))

        }

eclipse 报错

value addScriptParam is not a member of org.elasticsearch.action.update.UpdateRequestBuilder possible cause: maybe a semicolon is missing before `value 
 addScriptParam'?

我在网上研究过,但没有得到解决方案我知道 ES 较新版本在更新 API 中改变了很多东西,但我没有找到任何关于 addScriptParam 如何在 ES 5.2 java API 中使用 addScriptParam 的示例?

【问题讨论】:

    标签: java scala elasticsearch elasticsearch-5


    【解决方案1】:

    根据documentation,请使用script(Script)方法。

    @Deprecated
    public UpdateRequest addScriptParam(java.lang.String name, java.lang.Object value)
    Deprecated. Use script(Script) instead
    Add a script parameter.
    

    【讨论】:

    • 我在这里使用过脚本 .setScript(new Script(script.ScriptType.INLINE,"ctx._source.FollowingItems += newObject",null,null))) 但我不知道如何在其中添加参数
    • 您能否用您在 setScript(...) 调用中尝试过的内容更新您的原始帖子?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 2018-01-31
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2016-09-08
    相关资源
    最近更新 更多