Remove default index code from _x-pack/monitoring/_bulk
With the API no longer accepting {index}, we no longer need the code that supported it. Original commit: elastic/x-pack-elasticsearch@5d0ae37caa
This commit is contained in:
parent
71654d76e7
commit
946cbfb997
|
@ -85,10 +85,10 @@ public class MonitoringBulkRequest extends ActionRequest<MonitoringBulkRequest>
|
||||||
* Parses a monitoring bulk request and builds the list of documents to be indexed.
|
* Parses a monitoring bulk request and builds the list of documents to be indexed.
|
||||||
*/
|
*/
|
||||||
public MonitoringBulkRequest add(BytesReference content, String defaultMonitoringId, String defaultMonitoringVersion,
|
public MonitoringBulkRequest add(BytesReference content, String defaultMonitoringId, String defaultMonitoringVersion,
|
||||||
String defaultIndex, String defaultType) throws Exception {
|
String defaultType) throws Exception {
|
||||||
// MonitoringBulkRequest accepts a body request that has the same format as the BulkRequest:
|
// MonitoringBulkRequest accepts a body request that has the same format as the BulkRequest:
|
||||||
// instead of duplicating the parsing logic here we use a new BulkRequest instance to parse the content.
|
// instead of duplicating the parsing logic here we use a new BulkRequest instance to parse the content.
|
||||||
BulkRequest bulkRequest = Requests.bulkRequest().add(content, defaultIndex, defaultType);
|
BulkRequest bulkRequest = Requests.bulkRequest().add(content, null, defaultType);
|
||||||
|
|
||||||
for (ActionRequest request : bulkRequest.requests()) {
|
for (ActionRequest request : bulkRequest.requests()) {
|
||||||
if (request instanceof IndexRequest) {
|
if (request instanceof IndexRequest) {
|
||||||
|
@ -114,18 +114,12 @@ public class MonitoringBulkRequest extends ActionRequest<MonitoringBulkRequest>
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
int size = in.readVInt();
|
docs.addAll(in.readList(MonitoringBulkDoc::new));
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
add(new MonitoringBulkDoc(in));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeVInt(docs.size());
|
out.writeList(docs);
|
||||||
for (MonitoringBulkDoc doc : docs) {
|
|
||||||
doc.writeTo(out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ public class MonitoringBulkRequestBuilder
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MonitoringBulkRequestBuilder add(BytesReference content, String defaultId, String defaultVersion, String defaultIndex,
|
public MonitoringBulkRequestBuilder add(BytesReference content, String defaultId, String defaultVersion, String defaultType)
|
||||||
String defaultType) throws Exception {
|
throws Exception {
|
||||||
request.add(content, defaultId, defaultVersion, defaultIndex, defaultType);
|
request.add(content, defaultId, defaultVersion, defaultType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(RestRequest request, RestChannel channel, MonitoringClient client) throws Exception {
|
protected void handleRequest(RestRequest request, RestChannel channel, MonitoringClient client) throws Exception {
|
||||||
String defaultIndex = request.param("index");
|
|
||||||
String defaultType = request.param("type");
|
String defaultType = request.param("type");
|
||||||
|
|
||||||
String id = request.param(MONITORING_ID);
|
String id = request.param(MONITORING_ID);
|
||||||
|
@ -59,7 +58,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
MonitoringBulkRequestBuilder requestBuilder = client.prepareMonitoringBulk();
|
MonitoringBulkRequestBuilder requestBuilder = client.prepareMonitoringBulk();
|
||||||
requestBuilder.add(request.content(), id, version, defaultIndex, defaultType);
|
requestBuilder.add(request.content(), id, version, defaultType);
|
||||||
requestBuilder.execute(new RestBuilderListener<MonitoringBulkResponse>(channel) {
|
requestBuilder.execute(new RestBuilderListener<MonitoringBulkResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -109,12 +108,26 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
||||||
|
|
||||||
public void testAddMultipleDocs() throws Exception {
|
public void testAddMultipleDocs() throws Exception {
|
||||||
final int nbDocs = randomIntBetween(3, 20);
|
final int nbDocs = randomIntBetween(3, 20);
|
||||||
|
final MonitoringIndex[] indices = new MonitoringIndex[nbDocs];
|
||||||
|
final String[] types = new String[nbDocs];
|
||||||
final XContentType xContentType = XContentType.JSON;
|
final XContentType xContentType = XContentType.JSON;
|
||||||
|
int i;
|
||||||
|
|
||||||
try (BytesStreamOutput content = new BytesStreamOutput()) {
|
try (BytesStreamOutput content = new BytesStreamOutput()) {
|
||||||
try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType, content)) {
|
try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType, content)) {
|
||||||
for (int i = 0; i < nbDocs; i++) {
|
for (i = 0; i < nbDocs; i++) {
|
||||||
builder.startObject().startObject("index").endObject().endObject().flush();
|
builder.startObject().startObject("index");
|
||||||
|
if (rarely()) {
|
||||||
|
indices[i] = MonitoringIndex.DATA;
|
||||||
|
builder.field("_index", "_data");
|
||||||
|
} else {
|
||||||
|
indices[i] = MonitoringIndex.TIMESTAMPED;
|
||||||
|
}
|
||||||
|
if (randomBoolean()) {
|
||||||
|
types[i] = randomAsciiOfLength(5);
|
||||||
|
builder.field("_type", types[i]);
|
||||||
|
}
|
||||||
|
builder.endObject().endObject().flush();
|
||||||
content.write(xContentType.xContent().streamSeparator());
|
content.write(xContentType.xContent().streamSeparator());
|
||||||
builder.startObject().field("foo").value(i).endObject().flush();
|
builder.startObject().field("foo").value(i).endObject().flush();
|
||||||
content.write(xContentType.xContent().streamSeparator());
|
content.write(xContentType.xContent().streamSeparator());
|
||||||
|
@ -123,20 +136,23 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
||||||
|
|
||||||
String defaultMonitoringId = randomBoolean() ? randomAsciiOfLength(2) : null;
|
String defaultMonitoringId = randomBoolean() ? randomAsciiOfLength(2) : null;
|
||||||
String defaultMonitoringVersion = randomBoolean() ? randomAsciiOfLength(3) : null;
|
String defaultMonitoringVersion = randomBoolean() ? randomAsciiOfLength(3) : null;
|
||||||
String defaultIndex = randomFrom("_data", null);
|
String defaultType = rarely() ? randomAsciiOfLength(4) : null;
|
||||||
String defaultType = randomBoolean() ? randomAsciiOfLength(4) : null;
|
|
||||||
|
|
||||||
MonitoringIndex index = MonitoringIndex.from(defaultIndex);
|
|
||||||
|
|
||||||
MonitoringBulkRequest request = new MonitoringBulkRequest();
|
MonitoringBulkRequest request = new MonitoringBulkRequest();
|
||||||
request.add(content.bytes(), defaultMonitoringId, defaultMonitoringVersion, defaultIndex, defaultType);
|
request.add(content.bytes(), defaultMonitoringId, defaultMonitoringVersion, defaultType);
|
||||||
assertThat(request.getDocs(), hasSize(nbDocs));
|
assertThat(request.getDocs(), hasSize(nbDocs));
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
for (MonitoringBulkDoc doc : request.getDocs()) {
|
for (MonitoringBulkDoc doc : request.getDocs()) {
|
||||||
|
String expectedType = types[i] != null ? types[i] : defaultType;
|
||||||
|
|
||||||
assertThat(doc.getMonitoringId(), equalTo(defaultMonitoringId));
|
assertThat(doc.getMonitoringId(), equalTo(defaultMonitoringId));
|
||||||
assertThat(doc.getMonitoringVersion(), equalTo(defaultMonitoringVersion));
|
assertThat(doc.getMonitoringVersion(), equalTo(defaultMonitoringVersion));
|
||||||
assertThat(doc.getIndex(), sameInstance(index));
|
assertThat(doc.getIndex(), sameInstance(indices[i]));
|
||||||
assertThat(doc.getType(), equalTo(defaultType));
|
assertThat(doc.getType(), equalTo(expectedType));
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +186,9 @@ public class MonitoringBulkRequestTests extends ESTestCase {
|
||||||
MonitoringBulkRequest request2 = new MonitoringBulkRequest();
|
MonitoringBulkRequest request2 = new MonitoringBulkRequest();
|
||||||
request2.readFrom(in);
|
request2.readFrom(in);
|
||||||
|
|
||||||
assertThat(request2.docs.size(), CoreMatchers.equalTo(request.docs.size()));
|
assertThat(in.available(), equalTo(0));
|
||||||
|
assertThat(request2.docs.size(), equalTo(request.docs.size()));
|
||||||
|
|
||||||
for (int i = 0; i < request2.docs.size(); i++) {
|
for (int i = 0; i < request2.docs.size(); i++) {
|
||||||
MonitoringBulkDoc doc = request.docs.get(i);
|
MonitoringBulkDoc doc = request.docs.get(i);
|
||||||
MonitoringBulkDoc doc2 = request2.docs.get(i);
|
MonitoringBulkDoc doc2 = request2.docs.get(i);
|
||||||
|
|
Loading…
Reference in New Issue