如何使用java API构建脚本化查询

时间:2017-04-19 14:48:30

标签: elasticsearch

我使用以下代码构建脚本化查询

ScriptQueryBuilder sb = new ScriptQueryBuilder( new Script("ctx._source.id=9"));

--> This is produing the following ES query where script tag has been created twice
    {
      "script" : {
        "script" : {
          "inline" : "ctx._source.id=9",
          "lang" : "painless"
        },
        "boost" : 1.0
      }
    }

当我更改为查询构建器时,脚本标记仍然生成两次如何克服

QueryBuilder qb = QueryBuilders.scriptQuery(new Script("ctx._source.id=9"));

{
  "script" : {
    "script" : {
      "inline" : "ctx._source.id=9",
      "lang" : "painless"
    },
    "boost" : 1.0
  }
}

我错过了什么?如何删除额外的脚本标签?

以下是使用

的代码
QueryBuilder qb = QueryBuilders.scriptQuery(new Script("ctx._source.id=10"));
Update update = new Update.Builder(qb).index(index).type(type).id("1").build();

            JestResult result = JestClientInstance.getInstance().getClient().execute(update);

0 个答案:

没有答案