Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes types from SearchRequest and QueryShardContext #42112

Merged
merged 4 commits into from
May 29, 2019
Merged
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 @@ -391,7 +391,7 @@ static Request update(UpdateRequest updateRequest) throws IOException {
* searches.
*/
static Request search(SearchRequest searchRequest, String searchEndpoint) throws IOException {
Request request = new Request(HttpPost.METHOD_NAME, endpoint(searchRequest.indices(), searchRequest.types(), searchEndpoint));
Request request = new Request(HttpPost.METHOD_NAME, endpoint(searchRequest.indices(), searchEndpoint));

Params params = new Params(request);
addSearchRequestParams(params, searchRequest);
Expand Down Expand Up @@ -455,7 +455,7 @@ static Request searchTemplate(SearchTemplateRequest searchTemplateRequest) throw
request = new Request(HttpGet.METHOD_NAME, "_render/template");
} else {
SearchRequest searchRequest = searchTemplateRequest.getRequest();
String endpoint = endpoint(searchRequest.indices(), searchRequest.types(), "_search/template");
String endpoint = endpoint(searchRequest.indices(), "_search/template");
request = new Request(HttpGet.METHOD_NAME, endpoint);

Params params = new Params(request);
Expand Down Expand Up @@ -551,8 +551,7 @@ private static Request prepareReindexRequest(ReindexRequest reindexRequest, bool
}

static Request updateByQuery(UpdateByQueryRequest updateByQueryRequest) throws IOException {
String endpoint =
endpoint(updateByQueryRequest.indices(), updateByQueryRequest.getDocTypes(), "_update_by_query");
String endpoint = endpoint(updateByQueryRequest.indices(), "_update_by_query");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
Params params = new Params(request)
.withRouting(updateByQueryRequest.getRouting())
Expand All @@ -579,8 +578,7 @@ static Request updateByQuery(UpdateByQueryRequest updateByQueryRequest) throws I
}

static Request deleteByQuery(DeleteByQueryRequest deleteByQueryRequest) throws IOException {
String endpoint =
endpoint(deleteByQueryRequest.indices(), deleteByQueryRequest.getDocTypes(), "_delete_by_query");
String endpoint = endpoint(deleteByQueryRequest.indices(), "_delete_by_query");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
Params params = new Params(request)
.withRouting(deleteByQueryRequest.getRouting())
Expand Down Expand Up @@ -710,10 +708,12 @@ static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType,
return new NByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
}

@Deprecated
static String endpoint(String index, String type, String id) {
return new EndpointBuilder().addPathPart(index, type, id).build();
}

@Deprecated
static String endpoint(String index, String type, String id, String endpoint) {
return new EndpointBuilder().addPathPart(index, type, id).addPathPartAsIs(endpoint).build();
}
Expand All @@ -726,6 +726,7 @@ static String endpoint(String[] indices, String endpoint) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).build();
}

@Deprecated
static String endpoint(String[] indices, String[] types, String endpoint) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addCommaSeparatedPathParts(types)
.addPathPartAsIs(endpoint).build();
Expand All @@ -736,6 +737,7 @@ static String endpoint(String[] indices, String endpoint, String[] suffixes) {
.addCommaSeparatedPathParts(suffixes).build();
}

@Deprecated
static String endpoint(String[] indices, String endpoint, String type) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).addPathPart(type).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ static Request deleteJob(final DeleteRollupJobRequest deleteRollupJobRequest) th
}

static Request search(final SearchRequest request) throws IOException {
if (request.types().length > 0) {
/*
* Ideally we'd check this with the standard validation framework
* but we don't have a special request for rollup search so that'd
* be difficult.
*/
ValidationException ve = new ValidationException();
ve.addValidationError("types are not allowed in rollup search");
throw ve;
}
return RequestConverters.search(request, "_rollup_search");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ public void testReindex() throws IOException {
);
reindexRequest.setRemoteInfo(remoteInfo);
}
if (randomBoolean()) {
reindexRequest.setSourceDocTypes("doc", "tweet");
}
if (randomBoolean()) {
reindexRequest.setSourceBatchSize(randomInt(100));
}
Expand Down Expand Up @@ -457,9 +454,6 @@ public void testUpdateByQuery() throws IOException {
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.indices(randomIndicesNames(1, 5));
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
updateByQueryRequest.setDocTypes(generateRandomStringArray(5, 5, false, false));
}
if (randomBoolean()) {
int batchSize = randomInt(100);
updateByQueryRequest.setBatchSize(batchSize);
Expand Down Expand Up @@ -505,8 +499,6 @@ public void testUpdateByQuery() throws IOException {
Request request = RequestConverters.updateByQuery(updateByQueryRequest);
StringJoiner joiner = new StringJoiner("/", "/", "");
joiner.add(String.join(",", updateByQueryRequest.indices()));
if (updateByQueryRequest.getDocTypes().length > 0)
joiner.add(String.join(",", updateByQueryRequest.getDocTypes()));
joiner.add("_update_by_query");
assertEquals(joiner.toString(), request.getEndpoint());
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
Expand All @@ -518,9 +510,6 @@ public void testDeleteByQuery() throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest();
deleteByQueryRequest.indices(randomIndicesNames(1, 5));
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
deleteByQueryRequest.setDocTypes(generateRandomStringArray(5, 5, false, false));
}
if (randomBoolean()) {
int batchSize = randomInt(100);
deleteByQueryRequest.setBatchSize(batchSize);
Expand Down Expand Up @@ -559,8 +548,6 @@ public void testDeleteByQuery() throws IOException {
Request request = RequestConverters.deleteByQuery(deleteByQueryRequest);
StringJoiner joiner = new StringJoiner("/", "/", "");
joiner.add(String.join(",", deleteByQueryRequest.indices()));
if (deleteByQueryRequest.getDocTypes().length > 0)
joiner.add(String.join(",", deleteByQueryRequest.getDocTypes()));
joiner.add("_delete_by_query");
assertEquals(joiner.toString(), request.getEndpoint());
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
Expand Down Expand Up @@ -1065,13 +1052,6 @@ public void testSearch() throws Exception {
String[] indices = randomIndicesNames(0, 5);
SearchRequest searchRequest = new SearchRequest(indices);

int numTypes = randomIntBetween(0, 5);
String[] types = new String[numTypes];
for (int i = 0; i < numTypes; i++) {
types[i] = "type-" + randomAlphaOfLengthBetween(2, 5);
}
searchRequest.types(types);

Map<String, String> expectedParams = new HashMap<>();
setRandomSearchParams(searchRequest, expectedParams);
setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams);
Expand Down Expand Up @@ -1128,10 +1108,6 @@ public void testSearch() throws Exception {
if (Strings.hasLength(index)) {
endpoint.add(index);
}
String type = String.join(",", types);
if (Strings.hasLength(type)) {
endpoint.add(type);
}
endpoint.add(searchEndpoint);
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
assertEquals(endpoint.toString(), request.getEndpoint());
Expand All @@ -1142,7 +1118,6 @@ public void testSearch() throws Exception {
public void testSearchNullIndicesAndTypes() {
expectThrows(NullPointerException.class, () -> new SearchRequest((String[]) null));
expectThrows(NullPointerException.class, () -> new SearchRequest().indices((String[]) null));
expectThrows(NullPointerException.class, () -> new SearchRequest().types((String[]) null));
}

public void testCountNotNullSource() throws IOException {
Expand Down Expand Up @@ -1257,7 +1232,7 @@ public void testMultiSearch() throws IOException {
requests.add(searchRequest);
};
MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())),
REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null, null,
REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null,
xContentRegistry(), true);
assertEquals(requests, multiSearchRequest.requests());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.core.IndexerState;
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.core.IndexerState;
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
import org.elasticsearch.client.rollup.GetRollupCapsResponse;
Expand All @@ -40,10 +40,10 @@
import org.elasticsearch.client.rollup.GetRollupJobResponse;
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper;
import org.elasticsearch.client.rollup.PutRollupJobRequest;
import org.elasticsearch.client.rollup.StartRollupJobRequest;
import org.elasticsearch.client.rollup.StartRollupJobResponse;
import org.elasticsearch.client.rollup.RollableIndexCaps;
import org.elasticsearch.client.rollup.RollupJobCaps;
import org.elasticsearch.client.rollup.StartRollupJobRequest;
import org.elasticsearch.client.rollup.StartRollupJobResponse;
import org.elasticsearch.client.rollup.StopRollupJobRequest;
import org.elasticsearch.client.rollup.StopRollupJobResponse;
import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig;
Expand All @@ -54,10 +54,10 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation;
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -259,20 +259,6 @@ public void testSearch() throws Exception {
assertThat(avg.value(), closeTo(sum / numDocs, 0.00000001));
}

public void testSearchWithType() throws Exception {
SearchRequest search = new SearchRequest(rollupIndex);
search.types("a", "b", "c");
search.source(new SearchSourceBuilder()
.size(0)
.aggregation(new AvgAggregationBuilder("avg").field("value")));
try {
highLevelClient().rollup().search(search, RequestOptions.DEFAULT);
fail("types are not allowed but didn't fail");
} catch (ValidationException e) {
assertEquals("Validation Failed: 1: types are not allowed in rollup search;", e.getMessage());
}
}

public void testGetMissingRollupJob() throws Exception {
GetRollupJobRequest getRollupJobRequest = new GetRollupJobRequest("missing");
RollupClient rollupClient = highLevelClient().rollup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testNgramHighlightingWithBrokenPositions() throws IOException {
client().prepareIndex("test", "test", "1")
.setSource("name", "ARCOTEL Hotels Deutschland").get();
refresh();
SearchResponse search = client().prepareSearch("test").setTypes("test")
SearchResponse search = client().prepareSearch("test")
.setQuery(matchQuery("name.autocomplete", "deut tel").operator(Operator.OR))
.highlighter(new HighlightBuilder().field("name.autocomplete")).get();
assertHighlight(search, 0, "name.autocomplete", 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setUp() throws Exception {
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);

service = new ExpressionScriptEngine();
lookup = new SearchLookup(mapperService, ignored -> fieldData, null);
lookup = new SearchLookup(mapperService, ignored -> fieldData);
}

private FieldScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.elasticsearch.script.expression;

import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
Expand All @@ -33,6 +30,10 @@
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void setUp() throws Exception {
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);

service = new ExpressionScriptEngine();
lookup = new SearchLookup(mapperService, ignored -> fieldData, null);
lookup = new SearchLookup(mapperService, ignored -> fieldData);
}

private NumberSortScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.elasticsearch.script.expression;

import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
Expand All @@ -33,6 +30,10 @@
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void setUp() throws Exception {
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);

service = new ExpressionScriptEngine();
lookup = new SearchLookup(mapperService, ignored -> fieldData, null);
lookup = new SearchLookup(mapperService, ignored -> fieldData);
}

private TermsSetQueryScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testAllOpsDisabledIndexedScripts() throws IOException {
client().prepareSearch()
.setSource(new SearchSourceBuilder().scriptField("test1",
new Script(ScriptType.STORED, null, "script1", Collections.emptyMap())))
.setIndices("test").setTypes("scriptTest").get();
.setIndices("test").get();
fail("search script should have been rejected");
} catch(Exception e) {
assertThat(e.toString(), containsString("cannot execute scripts using [field] context"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ public void testParseRequest() throws Exception {
assertThat(request.requests().get(0).getRequest().preference(), nullValue());
assertThat(request.requests().get(1).getRequest().indices()[0], equalTo("test2"));
assertThat(request.requests().get(1).getRequest().indices()[1], equalTo("test3"));
assertThat(request.requests().get(1).getRequest().types()[0], equalTo("type1"));
assertThat(request.requests().get(1).getRequest().requestCache(), nullValue());
assertThat(request.requests().get(1).getRequest().preference(), equalTo("_local"));
assertThat(request.requests().get(2).getRequest().indices()[0], equalTo("test4"));
assertThat(request.requests().get(2).getRequest().indices()[1], equalTo("test1"));
assertThat(request.requests().get(2).getRequest().types()[0], equalTo("type2"));
assertThat(request.requests().get(2).getRequest().types()[1], equalTo("type1"));
assertThat(request.requests().get(2).getRequest().routing(), equalTo("123"));
assertNotNull(request.requests().get(0).getScript());
assertNotNull(request.requests().get(1).getScript());
Expand Down
Loading