-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[Rest Api Compatibility] Typed query #75453
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fcce7af
[Rest Api Compatibility] Typed query
pgomulka be5f38b
register in named xcontent for compatibility
pgomulka 37eb4cc
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka ea9236f
rework named xcontent registry
pgomulka 06cd590
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka 58e29ab
failing test
pgomulka a4f506a
rolling upgraded failing
pgomulka 4b23f28
full cluster test
pgomulka d679df3
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka 3b11f6e
tests
pgomulka 63e113b
new test
pgomulka 52c6e68
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka 8001998
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka f7bc8e4
test skip
pgomulka 5f2f3cb
cleanup
pgomulka 0b425a6
exception
pgomulka 36fc16c
tests
pgomulka 682a2e7
precommit
pgomulka f728494
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka eb643ea
Merge remote-tracking branch 'upstream/master' into compat/type_query
pgomulka e075707
remove unused code
pgomulka aec8676
scope and javadoc
pgomulka 0ee3b1c
add type query to searchmodule tests
pgomulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than adding this back into the core server package, could we put it into a separate module instead? I think that would avoid changes to
Node
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, will do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of simplicity I kept this query in the server module (same package as previously)
I was worried that if we keep all v7 queries in single module it will have far too many dependencies.