Skip to content

Commit 39244bb

Browse files
committed
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 938a99a commit 39244bb

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

Lines changed: 14 additions & 1 deletion
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;
@@ -1352,18 +1353,30 @@ Params withRealtime(boolean realtime) {
13521353

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

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

1373+
Params withRefreshPolicy(RefreshPolicy refreshPolicy) {
1374+
if (refreshPolicy != RefreshPolicy.NONE) {
1375+
return putParam("refresh", refreshPolicy.getValue());
1376+
}
1377+
return this;
1378+
}
1379+
13671380
Params withRetryOnConflict(int retryOnConflict) {
13681381
if (retryOnConflict > 0) {
13691382
return putParam("retry_on_conflict", String.valueOf(retryOnConflict));
Lines changed: 59 additions & 0 deletions
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)