Skip to content

Commit f063587

Browse files
authored
HLRC: add client side RefreshPolicy (#33209)
With the switch to client side request and response objects, we need a client side version of RefreshPolicy. This change adds a client side version of RefreshPolicy along with a method to add it to the parameters of a request. The existing method to add WriteRequest.RefreshPolicy to the parameters of a request is now deprecated.
1 parent 6fd9710 commit f063587

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import org.elasticsearch.action.support.IndicesOptions;
8989
import org.elasticsearch.action.support.WriteRequest;
9090
import org.elasticsearch.action.update.UpdateRequest;
91+
import org.elasticsearch.client.security.RefreshPolicy;
9192
import org.elasticsearch.cluster.health.ClusterHealthStatus;
9293
import org.elasticsearch.common.Nullable;
9394
import org.elasticsearch.common.Priority;
@@ -1353,18 +1354,30 @@ Params withRealtime(boolean realtime) {
13531354

13541355
Params withRefresh(boolean refresh) {
13551356
if (refresh) {
1356-
return withRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
1357+
return withRefreshPolicy(RefreshPolicy.IMMEDIATE);
13571358
}
13581359
return this;
13591360
}
13601361

1362+
/**
1363+
* @deprecated If creating a new HLRC ReST API call, use {@link RefreshPolicy}
1364+
* instead of {@link WriteRequest.RefreshPolicy} from the server project
1365+
*/
1366+
@Deprecated
13611367
Params withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) {
13621368
if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) {
13631369
return putParam("refresh", refreshPolicy.getValue());
13641370
}
13651371
return this;
13661372
}
13671373

1374+
Params withRefreshPolicy(RefreshPolicy refreshPolicy) {
1375+
if (refreshPolicy != RefreshPolicy.NONE) {
1376+
return putParam("refresh", refreshPolicy.getValue());
1377+
}
1378+
return this;
1379+
}
1380+
13681381
Params withRetryOnConflict(int retryOnConflict) {
13691382
if (retryOnConflict > 0) {
13701383
return putParam("retry_on_conflict", String.valueOf(retryOnConflict));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.security;
21+
22+
/**
23+
* Enumeration of values that control the refresh policy for a request that
24+
* supports specifying a refresh policy.
25+
*/
26+
public enum RefreshPolicy {
27+
28+
/**
29+
* Don't refresh after this request. The default.
30+
*/
31+
NONE("false"),
32+
/**
33+
* Force a refresh as part of this request. This refresh policy does not scale for high indexing or search throughput but is useful
34+
* to present a consistent view to for indices with very low traffic. And it is wonderful for tests!
35+
*/
36+
IMMEDIATE("true"),
37+
/**
38+
* Leave this request open until a refresh has made the contents of this request visible to search. This refresh policy is
39+
* compatible with high indexing and search throughput but it causes the request to wait to reply until a refresh occurs.
40+
*/
41+
WAIT_UNTIL("wait_for");
42+
43+
private final String value;
44+
45+
RefreshPolicy(String value) {
46+
this.value = value;
47+
}
48+
49+
public String getValue() {
50+
return value;
51+
}
52+
53+
/**
54+
* Get the default refresh policy, which is <code>NONE</code>
55+
*/
56+
public static RefreshPolicy getDefault() {
57+
return RefreshPolicy.NONE;
58+
}
59+
}

0 commit comments

Comments
 (0)