Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.bulk.BulkRequest;
Expand Down Expand Up @@ -202,6 +203,17 @@ static Request updateAliases(IndicesAliasesRequest indicesAliasesRequest) throws
return new Request(HttpPost.METHOD_NAME, "/_aliases", parameters.getParams(), entity);
}

static Request updateSettings(UpdateSettingsRequest updateSettingsRequest) throws IOException {
String endpoint = endpoint(updateSettingsRequest.indices(), "_settings");

Params parameters = Params.builder()
.withTimeout(updateSettingsRequest.timeout())
.withMasterTimeout(updateSettingsRequest.masterNodeTimeout());

HttpEntity entity = createEntity(updateSettingsRequest, REQUEST_BODY_CONTENT_TYPE);
return new Request(HttpPut.METHOD_NAME, endpoint, parameters.getParams(), entity);
}

static Request putMapping(PutMappingRequest putMappingRequest) throws IOException {
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
if (putMappingRequest.getConcreteIndex() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
Expand Down Expand Up @@ -375,6 +377,24 @@ public final void updateAsync(UpdateRequest updateRequest, ActionListener<Update
performRequestAsyncAndParseEntity(updateRequest, Request::update, UpdateResponse::fromXContent, listener, emptySet(), headers);
}

/**
*Updates the settings of an index/indices or all the indices
* <p>
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html"</a>
*/
public final UpdateSettingsResponse updateSettings(UpdateSettingsRequest updateSettingsRequest, Header... headers) throws IOException {
return performRequestAndParseEntity(updateSettingsRequest, Request::updateSettings, UpdateSettingsResponse::fromXContent, emptySet(), headers);
}

/**
*Asynchronously updates the settings of an index/indices or all the indices
* <p>
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html"</a>
*/
public final void updateSettingsAsync(UpdateSettingsRequest updateSettingsRequest, ActionListener<UpdateSettingsResponse> listener, Header... headers) {
performRequestAsyncAndParseEntity(updateSettingsRequest, Request::updateSettings, UpdateSettingsResponse::fromXContent, listener, emptySet(), headers);
}

/**
* Deletes a document by id using the Delete API
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.*;

import java.io.IOException;
import java.util.Map;
Expand All @@ -43,7 +41,7 @@
/**
* Request for an update index settings action
*/
public class UpdateSettingsRequest extends AcknowledgedRequest<UpdateSettingsRequest> implements IndicesRequest.Replaceable {
public class UpdateSettingsRequest extends AcknowledgedRequest<UpdateSettingsRequest> implements IndicesRequest.Replaceable, ToXContentObject{

private String[] indices;
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true);
Expand Down Expand Up @@ -178,4 +176,13 @@ public void writeTo(StreamOutput out) throws IOException {
writeSettingsToStream(settings, out);
out.writeBoolean(preserveExisting);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
settings.toXContent(builder, params);
builder.endObject();
return builder;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;

Expand All @@ -30,6 +32,9 @@
*/
public class UpdateSettingsResponse extends AcknowledgedResponse {

private static final ConstructingObjectParser<UpdateSettingsResponse, Void> PARSER = new ConstructingObjectParser<>("update_settings",
true, args -> new UpdateSettingsResponse((boolean) args[0]));

UpdateSettingsResponse() {
}

Expand All @@ -48,4 +53,9 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeAcknowledged(out);
}

public static UpdateSettingsResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

}