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

[Remove] Type from Search Internals #2109

Merged
merged 4 commits into from
Feb 17, 2022
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 @@ -432,7 +432,7 @@ static Request update(UpdateRequest updateRequest) throws IOException {
* for standard 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();
addSearchRequestParams(params, searchRequest);
Expand Down Expand Up @@ -502,7 +502,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();
Expand Down Expand Up @@ -633,7 +633,7 @@ private static Request prepareReindexRequest(ReindexRequest reindexRequest, bool

private static Request prepareDeleteByQueryRequest(DeleteByQueryRequest deleteByQueryRequest, boolean waitForCompletion)
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().withRouting(deleteByQueryRequest.getRouting())
.withRefresh(deleteByQueryRequest.isRefresh())
Expand Down Expand Up @@ -661,7 +661,7 @@ private static Request prepareDeleteByQueryRequest(DeleteByQueryRequest deleteBy
}

static Request prepareUpdateByQueryRequest(UpdateByQueryRequest updateByQueryRequest, boolean waitForCompletion) 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().withRouting(updateByQueryRequest.getRouting())
.withPipeline(updateByQueryRequest.getPipeline())
Expand Down Expand Up @@ -799,10 +799,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 @@ -815,6 +817,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)
Expand All @@ -829,6 +832,7 @@ static String endpoint(String[] indices, String endpoint, String[] 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 @@ -468,9 +468,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 @@ -536,9 +533,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 @@ -600,9 +594,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 @@ -614,9 +605,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 @@ -671,9 +659,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 @@ -1191,10 +1176,6 @@ public void testSearch() throws Exception {
if (Strings.hasLength(index)) {
endpoint.add(index);
}
String type = String.join(",", searchRequest.types());
if (Strings.hasLength(type)) {
endpoint.add(type);
}
endpoint.add(searchEndpoint);
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
assertEquals(endpoint.toString(), request.getEndpoint());
Expand All @@ -1204,14 +1185,6 @@ public void testSearch() throws Exception {

public static SearchRequest createTestSearchRequest(String[] indices, Map<String, String> expectedParams) {
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);

setRandomSearchParams(searchRequest, expectedParams);
setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams);

Expand Down Expand Up @@ -1278,7 +1251,6 @@ public static SearchSourceBuilder createTestSearchSourceBuilder() {
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 All @@ -1293,14 +1265,6 @@ public void testCountNotNullSource() throws IOException {
public void testCount() throws Exception {
String[] indices = randomIndicesNames(0, 5);
CountRequest countRequest = new CountRequest(indices);

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

Map<String, String> expectedParams = new HashMap<>();
setRandomCountParams(countRequest, expectedParams);
setRandomIndicesOptions(countRequest::indicesOptions, countRequest::indicesOptions, expectedParams);
Expand All @@ -1317,23 +1281,13 @@ public void testCount() throws Exception {
if (Strings.hasLength(index)) {
endpoint.add(index);
}
String type = String.join(",", types);
if (Strings.hasLength(type)) {
endpoint.add(type);
}
endpoint.add("_count");
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
assertEquals(endpoint.toString(), request.getEndpoint());
assertEquals(expectedParams, request.getParameters());
assertToXContentBody(countRequest, request.getEntity());
}

public void testCountNullIndicesAndTypes() {
expectThrows(NullPointerException.class, () -> new CountRequest((String[]) null));
expectThrows(NullPointerException.class, () -> new CountRequest().indices((String[]) null));
expectThrows(NullPointerException.class, () -> new CountRequest().types((String[]) null));
}

private static void setRandomCountParams(CountRequest countRequest, Map<String, String> expectedParams) {
if (randomBoolean()) {
countRequest.routing(randomAlphaOfLengthBetween(3, 10));
Expand Down Expand Up @@ -1416,7 +1370,6 @@ public void testMultiSearch() throws IOException {
null,
null,
null,
null,
xContentRegistry(),
true,
deprecationLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import static org.opensearch.index.query.QueryBuilders.spanWithinQuery;
import static org.opensearch.index.query.QueryBuilders.termQuery;
import static org.opensearch.index.query.QueryBuilders.termsQuery;
import static org.opensearch.index.query.QueryBuilders.typeQuery;
import static org.opensearch.index.query.QueryBuilders.wildcardQuery;
import static org.opensearch.index.query.QueryBuilders.wrapperQuery;
import static org.opensearch.index.query.functionscore.ScoreFunctionBuilders.exponentialDecayFunction;
Expand Down Expand Up @@ -447,12 +446,6 @@ public void testTerms() {
// end::terms
}

public void testType() {
// tag::type
typeQuery("my_type"); // <1>
// end::type
}

public void testWildcard() {
// tag::wildcard
wildcardQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public void testNgramHighlightingWithBrokenPositions() throws IOException {
client().prepareIndex("test", "test", "1").setSource("name", "ARCOTEL Hotels Deutschland").get();
refresh();
SearchResponse search = client().prepareSearch("test")
.setTypes("test")
.setQuery(matchQuery("name.autocomplete", "deut tel").operator(Operator.OR))
.highlighter(new HighlightBuilder().field("name.autocomplete"))
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void testAllOpsDisabledIndexedScripts() throws IOException {
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
)
.setIndices("test")
.setTypes("scriptTest")
.get();
fail("search script should have been rejected");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setUp() throws Exception {
when(fieldData.load(any())).thenReturn(atomicFieldData);

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

private FieldScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setUp() throws Exception {
when(fieldData.load(any())).thenReturn(atomicFieldData);

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

private NumberSortScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setUp() throws Exception {
when(fieldData.load(any())).thenReturn(atomicFieldData);

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

private TermsSetQueryScript.LeafFactory compile(String expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ public void testIndexedTemplateClient() throws Exception {
Map<String, Object> templateParams = new HashMap<>();
templateParams.put("fieldParam", "foo");

SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(
new SearchRequest("test").types("type")
).setScript("testTemplate").setScriptType(ScriptType.STORED).setScriptParams(templateParams).get();
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("test"))
.setScript("testTemplate")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
.get();
assertHitCount(searchResponse.getResponse(), 4);

assertAcked(client().admin().cluster().prepareDeleteStoredScript("testTemplate"));
Expand Down Expand Up @@ -238,22 +240,24 @@ public void testIndexedTemplate() throws Exception {
Map<String, Object> templateParams = new HashMap<>();
templateParams.put("fieldParam", "foo");

SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(
new SearchRequest().indices("test").types("type")
).setScript("1a").setScriptType(ScriptType.STORED).setScriptParams(templateParams).get();
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest().indices("test"))
.setScript("1a")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
.get();
assertHitCount(searchResponse.getResponse(), 4);

expectThrows(
ResourceNotFoundException.class,
() -> new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest().indices("test").types("type"))
() -> new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest().indices("test"))
.setScript("1000")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
.get()
);

templateParams.put("fieldParam", "bar");
searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("test").types("type"))
searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("test"))
.setScript("2")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
Expand Down Expand Up @@ -304,7 +308,7 @@ public void testIndexedTemplateOverwrite() throws Exception {

IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("testindex").types("test"))
() -> new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("testindex"))
.setScript("git01")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
Expand All @@ -320,9 +324,11 @@ public void testIndexedTemplateOverwrite() throws Exception {
.setContent(new BytesArray(query.replace("{{slop}}", Integer.toString(0))), XContentType.JSON)
);

SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(
new SearchRequest("testindex").types("test")
).setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams).get();
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("testindex"))
.setScript("git01")
.setScriptType(ScriptType.STORED)
.setScriptParams(templateParams)
.get();
assertHitCount(searchResponse.getResponse(), 1);
}
}
Expand Down Expand Up @@ -360,9 +366,11 @@ public void testIndexedTemplateWithArray() throws Exception {
String[] fieldParams = { "foo", "bar" };
arrayTemplateParams.put("fieldParam", fieldParams);

SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(
new SearchRequest("test").types("type")
).setScript("4").setScriptType(ScriptType.STORED).setScriptParams(arrayTemplateParams).get();
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()).setRequest(new SearchRequest("test"))
.setScript("4")
.setScriptType(ScriptType.STORED)
.setScriptParams(arrayTemplateParams)
.get();
assertHitCount(searchResponse.getResponse(), 5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.script.mustache;

import org.opensearch.client.node.NodeClient;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Settings;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
Expand All @@ -53,9 +52,6 @@
import static org.opensearch.rest.RestRequest.Method.POST;

public class RestMultiSearchTemplateAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiSearchTemplateAction.class);
static final String TYPES_DEPRECATION_MESSAGE = "[types removal]"
+ " Specifying types in multi search template requests is deprecated.";

private static final Set<String> RESPONSE_PARAMS;

Expand Down Expand Up @@ -95,14 +91,6 @@ public String getName() {
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
MultiSearchTemplateRequest multiRequest = parseRequest(request, allowExplicitIndex);

// Emit a single deprecation message if any search template contains types.
for (SearchTemplateRequest searchTemplateRequest : multiRequest.requests()) {
if (searchTemplateRequest.getRequest().types().length > 0) {
deprecationLogger.deprecate("msearch_with_types", TYPES_DEPRECATION_MESSAGE);
break;
}
}
return channel -> client.execute(MultiSearchTemplateAction.INSTANCE, multiRequest, new RestToXContentListener<>(channel));
}

Expand Down
Loading