-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rest Api Compatibility] Typed query (#75453)
Type query support was removed in #47207. This query will throw an exception in v7 rest api compatibility indicating that the support was removed + deprecation warnings. In v8 it will not be available and error about type query being not found will be returned. relates main meta issue #51816 relates types removal meta #54160
- Loading branch information
Showing
5 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...pec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/search/10_type_query.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
setup: | ||
- skip: | ||
features: | ||
- "headers" | ||
- "allowed_warnings_regex" | ||
--- | ||
type query throws exception when used: | ||
- do: | ||
index: | ||
index: "test1" | ||
id: 1 | ||
type: "cat" | ||
refresh: true | ||
body: | ||
foo: "bar" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
||
- do: | ||
catch: /\[types removal\] Type queries are deprecated, prefer to filter on a field instead./ | ||
search: | ||
rest_total_hits_as_int: true | ||
index: "test1" | ||
body: | ||
query: | ||
type: | ||
value: "cat" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
||
- do: | ||
catch: /\[types removal\] Type queries are deprecated, prefer to filter on a field instead./ | ||
search: | ||
rest_total_hits_as_int: true | ||
index: "test1" | ||
body: | ||
query: | ||
type: | ||
value: "_doc" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
97 changes: 97 additions & 0 deletions
97
server/src/main/java/org/elasticsearch/index/query/TypeQueryV7Builder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.query; | ||
|
||
import org.apache.lucene.search.MatchNoDocsQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ParseField; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.core.RestApiVersion; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
|
||
import java.io.IOException; | ||
|
||
public class TypeQueryV7Builder extends AbstractQueryBuilder<TypeQueryV7Builder> { | ||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TypeQueryV7Builder.class); | ||
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Type queries are deprecated, " + | ||
"prefer to filter on a field instead."; | ||
|
||
private static final String NAME = "type"; | ||
public static final ParseField NAME_V7 = new ParseField(NAME).forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)); | ||
private static final ParseField VALUE_FIELD = new ParseField("value"); | ||
private static final ObjectParser<TypeQueryV7Builder, Void> PARSER = new ObjectParser<>(NAME, TypeQueryV7Builder::new); | ||
|
||
static { | ||
PARSER.declareString(QueryBuilder::queryName, | ||
AbstractQueryBuilder.NAME_FIELD.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7))); | ||
PARSER.declareFloat(QueryBuilder::boost, | ||
AbstractQueryBuilder.BOOST_FIELD.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7))); | ||
PARSER.declareString(TypeQueryV7Builder::setValue, | ||
VALUE_FIELD.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7))); | ||
} | ||
|
||
private String value; | ||
|
||
public TypeQueryV7Builder() { | ||
} | ||
|
||
/** | ||
* Read from a stream. | ||
*/ | ||
public TypeQueryV7Builder(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) throws IOException { | ||
} | ||
|
||
@Override | ||
protected void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(NAME); | ||
builder.field(VALUE_FIELD.getPreferredName(), MapperService.SINGLE_MAPPING_NAME); | ||
printBoostAndQueryName(builder); | ||
builder.endObject(); | ||
} | ||
|
||
@Override | ||
protected Query doToQuery(SearchExecutionContext context) throws IOException { | ||
return new MatchNoDocsQuery(); | ||
} | ||
|
||
@Override | ||
protected boolean doEquals(TypeQueryV7Builder other) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return 0; | ||
} | ||
|
||
public static TypeQueryV7Builder fromXContent(XContentParser parser) throws IOException { | ||
deprecationLogger.compatibleApiWarning("type_query", TYPES_DEPRECATION_MESSAGE); | ||
throw new ParsingException(parser.getTokenLocation(), TYPES_DEPRECATION_MESSAGE); | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return NAME; | ||
} | ||
|
||
public void setValue(String value){ | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters