如何从其余高级客户端6.2.4实现多个删除?

时间:2019-03-13 10:54:22

标签: spring elasticsearch

以下代码仅适用于ElasticSearchClient。我想使用RestHighLevelClient 6.2.4版本。

checkAuthStatus(){
        firebase.auth().onAuthStateChanged(user => {
            this.setState({ btnWithImg: user });

            if(user !== null){
                this.setState({ userIsLoggedIn: true });
                this.props.toggleLogIn();
            }
        });
    }

1 个答案:

答案 0 :(得分:1)

Delete by Query API之前的RestHighLevelClient仅支持version 6.5 and above

如果您使用的是6.2.4,尽管如此,您仍然可以使用低级客户端调用_delete_by_query端点:

Response response = restClient.performRequest("POST", "/persons/_delete_by_query"); 
String jsonResponse = EntityUtils.toString(response.getEntity());
// parse the JSON and do something

如果您需要传递查询,可以这样做:

Map<String, String> params = Collections.emptyMap();
String jsonString = "{ \"query\": { \"range\" : { \"age\" : { \"gte\" : 10 } } } }";
HttpEntity query = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);

Response response = restClient.performRequest("POST", "/persons/_delete_by_query", params, query); 
String jsonResponse = EntityUtils.toString(response.getEntity());
// parse the JSON and do something