Skip to content

Commit

Permalink
Not allowing index names in request body for multi-get/search/bulk wh…
Browse files Browse the repository at this point in the history
…en indices are already given in url

closes #3636
  • Loading branch information
kimchy committed Sep 5, 2013
1 parent 3cb143f commit ccf098b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Expand Up @@ -155,6 +155,7 @@ BulkRequest internalAdd(UpdateRequest request, @Nullable Object payload) {
}
return this;
}

/**
* Adds an {@link DeleteRequest} to the list of actions to execute.
*/
Expand Down
Expand Up @@ -236,6 +236,10 @@ public void add(@Nullable String defaultIndex, @Nullable String defaultType, @Nu
}

public void add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, BytesReference data) throws Exception {
add(defaultIndex, defaultType, defaultFields, data, true);
}

public void add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, BytesReference data, boolean allowExplicitIndex) throws Exception {
XContentParser parser = XContentFactory.xContent(data).createParser(data);
try {
XContentParser.Token token;
Expand All @@ -260,6 +264,9 @@ public void add(@Nullable String defaultIndex, @Nullable String defaultType, @Nu
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("_index".equals(currentFieldName)) {
if (!allowExplicitIndex) {
throw new ElasticSearchIllegalArgumentException("explicit index in multi get is not allowed");
}
index = parser.text();
} else if ("_type".equals(currentFieldName)) {
type = parser.text();
Expand Down
Expand Up @@ -24,8 +24,8 @@
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.replication.ReplicationType;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
Expand Down
Expand Up @@ -39,6 +39,8 @@

public class RestMultiGetAction extends BaseRestHandler {

private final boolean allowExplicitIndex;

@Inject
public RestMultiGetAction(Settings settings, Client client, RestController controller) {
super(settings, client);
Expand All @@ -48,6 +50,8 @@ public RestMultiGetAction(Settings settings, Client client, RestController contr
controller.registerHandler(POST, "/{index}/_mget", this);
controller.registerHandler(GET, "/{index}/{type}/_mget", this);
controller.registerHandler(POST, "/{index}/{type}/_mget", this);

this.allowExplicitIndex = settings.getAsBoolean("rest.action.multi.allow_explicit_index", true);
}

@Override
Expand All @@ -65,7 +69,7 @@ public void handleRequest(final RestRequest request, final RestChannel channel)
}

try {
multiGetRequest.add(request.param("index"), request.param("type"), sFields, request.content());
multiGetRequest.add(request.param("index"), request.param("type"), sFields, request.content(), allowExplicitIndex);
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
Expand Down

0 comments on commit ccf098b

Please sign in to comment.