Skip to content

Commit 0c53204

Browse files
committed
Added RealtimeRequest interface and let GetRequest, MultiGetRequest, TermVectorsRequest and MultiTermVectorsRequest implement it.
This is useful because now all requests that are realtime are now grouped under the same marker interface.
1 parent 21abc2f commit 0c53204

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.action;
21+
22+
/**
23+
* Indicates that a request can execute in realtime (reads from the translog).
24+
* All {@link ActionRequest} that are realtime should implement this interface.
25+
*/
26+
public interface RealtimeRequest {
27+
28+
/**
29+
* @param realtime Controls whether this request should be realtime by reading from the translog. If <code>null</code>
30+
* is specified then whether the operation will be realtime depends on the api of the concrete request
31+
* subclass.
32+
*/
33+
<R extends RealtimeRequest> R realtime(Boolean realtime);
34+
35+
}

core/src/main/java/org/elasticsearch/action/get/GetRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.elasticsearch.action.ActionRequest;
2323
import org.elasticsearch.action.ActionRequestValidationException;
24+
import org.elasticsearch.action.RealtimeRequest;
2425
import org.elasticsearch.action.ValidateActions;
2526
import org.elasticsearch.action.support.single.shard.SingleShardRequest;
2627
import org.elasticsearch.common.Nullable;
@@ -43,7 +44,7 @@
4344
* @see org.elasticsearch.client.Requests#getRequest(String)
4445
* @see org.elasticsearch.client.Client#get(GetRequest)
4546
*/
46-
public class GetRequest extends SingleShardRequest<GetRequest> {
47+
public class GetRequest extends SingleShardRequest<GetRequest> implements RealtimeRequest {
4748

4849
private String type;
4950
private String id;
@@ -244,6 +245,7 @@ public boolean realtime() {
244245
return this.realtime == null ? true : this.realtime;
245246
}
246247

248+
@Override
247249
public GetRequest realtime(Boolean realtime) {
248250
this.realtime = realtime;
249251
return this;

core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import java.util.Iterator;
4343
import java.util.List;
4444

45-
public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements Iterable<MultiGetRequest.Item>, CompositeIndicesRequest {
45+
public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements Iterable<MultiGetRequest.Item>, CompositeIndicesRequest, RealtimeRequest {
4646

4747
/**
4848
* A single get item.
@@ -319,6 +319,7 @@ public boolean realtime() {
319319
return this.realtime == null ? true : this.realtime;
320320
}
321321

322+
@Override
322323
public MultiGetRequest realtime(Boolean realtime) {
323324
this.realtime = realtime;
324325
return this;

core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.io.IOException;
3333
import java.util.*;
3434

35-
public class MultiTermVectorsRequest extends ActionRequest<MultiTermVectorsRequest> implements Iterable<TermVectorsRequest>, CompositeIndicesRequest {
35+
public class MultiTermVectorsRequest extends ActionRequest<MultiTermVectorsRequest> implements Iterable<TermVectorsRequest>, CompositeIndicesRequest, RealtimeRequest {
3636

3737
String preference;
3838
List<TermVectorsRequest> requests = new ArrayList<>();
@@ -162,4 +162,12 @@ public void ids(String[] ids) {
162162
public int size() {
163163
return requests.size();
164164
}
165+
166+
@Override
167+
public MultiTermVectorsRequest realtime(Boolean realtime) {
168+
for (TermVectorsRequest request : requests) {
169+
request.realtime(realtime);
170+
}
171+
return this;
172+
}
165173
}

core/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.ElasticsearchParseException;
2626
import org.elasticsearch.action.ActionRequestValidationException;
2727
import org.elasticsearch.action.DocumentRequest;
28+
import org.elasticsearch.action.RealtimeRequest;
2829
import org.elasticsearch.action.ValidateActions;
2930
import org.elasticsearch.action.get.MultiGetRequest;
3031
import org.elasticsearch.action.support.single.shard.SingleShardRequest;
@@ -50,7 +51,7 @@
5051
* Note, the {@link #index()}, {@link #type(String)} and {@link #id(String)} are
5152
* required.
5253
*/
53-
public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> implements DocumentRequest<TermVectorsRequest> {
54+
public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> implements DocumentRequest<TermVectorsRequest>, RealtimeRequest {
5455

5556
private String type;
5657

@@ -405,6 +406,7 @@ public boolean realtime() {
405406
/**
406407
* Choose whether term vectors be generated real-time.
407408
*/
409+
@Override
408410
public TermVectorsRequest realtime(Boolean realtime) {
409411
this.realtime = realtime;
410412
return this;

0 commit comments

Comments
 (0)