Retain originalIndex info when rewriting FieldCapabilities requests (#27761)

A FieldCapabilities request can cover multiple indices (or aliases pointing to multiple indices).
When rewriting the request for each index, store the original requested indices.
This commit is contained in:
Albert Zaharovits 2017-12-19 13:38:41 +02:00 committed by GitHub
parent 1383cab267
commit 01a47baa10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -19,7 +19,10 @@
package org.elasticsearch.action.fieldcaps;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.single.shard.SingleShardRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -30,32 +33,54 @@ public class FieldCapabilitiesIndexRequest
extends SingleShardRequest<FieldCapabilitiesIndexRequest> {
private String[] fields;
private OriginalIndices originalIndices;
// For serialization
FieldCapabilitiesIndexRequest() {}
FieldCapabilitiesIndexRequest(String[] fields, String index) {
FieldCapabilitiesIndexRequest(String[] fields, String index, OriginalIndices originalIndices) {
super(index);
if (fields == null || fields.length == 0) {
throw new IllegalArgumentException("specified fields can't be null or empty");
}
this.fields = fields;
assert index != null;
this.index(index);
this.originalIndices = originalIndices;
}
public String[] fields() {
return fields;
}
@Override
public String[] indices() {
return originalIndices.indices();
}
@Override
public IndicesOptions indicesOptions() {
return originalIndices.indicesOptions();
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
fields = in.readStringArray();
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
originalIndices = OriginalIndices.readOriginalIndices(in);
} else {
originalIndices = OriginalIndices.NONE;
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(fields);
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
OriginalIndices.writeOriginalIndices(originalIndices, out);
}
}
@Override

View File

@ -110,7 +110,7 @@ public class TransportFieldCapabilitiesAction extends HandledTransportAction<Fie
}
};
for (String index : concreteIndices) {
shardAction.execute(new FieldCapabilitiesIndexRequest(request.fields(), index), innerListener);
shardAction.execute(new FieldCapabilitiesIndexRequest(request.fields(), index, localIndices), innerListener);
}
// this is the cross cluster part of this API - we force the other cluster to not merge the results but instead

View File

@ -59,6 +59,8 @@ import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.explain.ExplainAction;
import org.elasticsearch.action.explain.ExplainRequest;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
import org.elasticsearch.action.get.GetAction;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.MultiGetAction;
@ -188,6 +190,19 @@ public class IndicesRequestIT extends ESIntegTestCase {
assertSameIndices(getFieldMappingsRequest, getFieldMappingsShardAction);
}
public void testFieldCapabilities() {
String fieldCapabilitiesShardAction = FieldCapabilitiesAction.NAME + "[index][s]";
interceptTransportActions(fieldCapabilitiesShardAction);
FieldCapabilitiesRequest fieldCapabilitiesRequest = new FieldCapabilitiesRequest();
fieldCapabilitiesRequest.indices(randomIndicesOrAliases());
fieldCapabilitiesRequest.fields(randomAlphaOfLength(8));
internalCluster().coordOnlyNodeClient().fieldCaps(fieldCapabilitiesRequest).actionGet();
clearInterceptedActions();
assertSameIndices(fieldCapabilitiesRequest, fieldCapabilitiesShardAction);
}
public void testAnalyze() {
String analyzeShardAction = AnalyzeAction.NAME + "[s]";
interceptTransportActions(analyzeShardAction);