Elastic Search 高级 Java 客户端 UpdateByQueryRequest API 需要帮助
Elastic Search High Level Java Client UpdateByQueryRequest API help required
我正在从正常的 ES Http 调用迁移到 ES HighLevelJavaClient。
我想转换这个旧的实现 POST /_update_by_query
{
"script": {
"inline": "ctx._source.collibra_match_for = []"
},
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": "doc['collibra_match_for.keyword'].values.length > 0",
"lang": "painless"
}
}
}
}
}
}
至高级客户端代码。
我试过的代码是:
UpdateByQueryRequest request = new UpdateByQueryRequest();
request.setConflicts("proceed");
request.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.scriptQuery(new Script("doc['collibra_match_for.keyword'].values.length > 0"))));
request.setScript(new Script(ScriptType.INLINE, "painless","ctx._source.collibra_match_for = []",Collections.emptyMap()));
request.setRefresh(true);
try {
BulkByScrollResponse bulkResponse = esClient.updateByQuery(request, RequestOptions.DEFAULT);
long totalDocs = bulkResponse.getTotal();
} catch (IOException e) {
e.printStackTrace();
}
}
但是我收到了这个错误:
Elasticsearch exception [type=exception, reason=Incorrect HTTP method for uri [/_update_by_query?requests_per_second=-1&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&refresh=true&conflicts=proceed&timeout=1m] and method [POST], allowed: [DELETE, PUT, GET, HEAD]]
任何帮助将不胜感激:)
我真的找到了这个问题的答案..
我们只需要在构造函数中添加索引名称。
这是 question.Hope 的最终答案,将来对某人有用:)
UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX_NAME);
request.setConflicts("proceed");
request.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.scriptQuery(new Script("doc['collibra_match_for.keyword'].values.length > 0"))));
request.setScript(new Script(ScriptType.INLINE, "painless","ctx._source.collibra_match_for = []",Collections.emptyMap()));
request.setRefresh(true);
try {
BulkByScrollResponse bulkResponse = esClient.updateByQuery(request, RequestOptions.DEFAULT);
long totalDocs = bulkResponse.getTotal();
} catch (IOException e) {
e.printStackTrace();
}
我正在从正常的 ES Http 调用迁移到 ES HighLevelJavaClient。
我想转换这个旧的实现 POST /_update_by_query
{
"script": {
"inline": "ctx._source.collibra_match_for = []"
},
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": "doc['collibra_match_for.keyword'].values.length > 0",
"lang": "painless"
}
}
}
}
}
}
至高级客户端代码。
我试过的代码是:
UpdateByQueryRequest request = new UpdateByQueryRequest();
request.setConflicts("proceed");
request.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.scriptQuery(new Script("doc['collibra_match_for.keyword'].values.length > 0"))));
request.setScript(new Script(ScriptType.INLINE, "painless","ctx._source.collibra_match_for = []",Collections.emptyMap()));
request.setRefresh(true);
try {
BulkByScrollResponse bulkResponse = esClient.updateByQuery(request, RequestOptions.DEFAULT);
long totalDocs = bulkResponse.getTotal();
} catch (IOException e) {
e.printStackTrace();
}
}
但是我收到了这个错误:
Elasticsearch exception [type=exception, reason=Incorrect HTTP method for uri [/_update_by_query?requests_per_second=-1&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&refresh=true&conflicts=proceed&timeout=1m] and method [POST], allowed: [DELETE, PUT, GET, HEAD]]
任何帮助将不胜感激:)
我真的找到了这个问题的答案.. 我们只需要在构造函数中添加索引名称。 这是 question.Hope 的最终答案,将来对某人有用:)
UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX_NAME);
request.setConflicts("proceed");
request.setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.scriptQuery(new Script("doc['collibra_match_for.keyword'].values.length > 0"))));
request.setScript(new Script(ScriptType.INLINE, "painless","ctx._source.collibra_match_for = []",Collections.emptyMap()));
request.setRefresh(true);
try {
BulkByScrollResponse bulkResponse = esClient.updateByQuery(request, RequestOptions.DEFAULT);
long totalDocs = bulkResponse.getTotal();
} catch (IOException e) {
e.printStackTrace();
}