-
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
Changes from 3 commits
fcce7af
be5f38b
37eb4cc
ea9236f
06cd590
58e29ab
a4f506a
4b23f28
d679df3
3b11f6e
63e113b
52c6e68
8001998
f7bc8e4
5f2f3cb
0b425a6
36fc16c
682a2e7
f728494
eb643ea
e075707
aec8676
0ee3b1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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.MatchAllDocsQuery; | ||
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.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> { | ||
public static final String NAME = "type"; | ||
public static final ParseField NAME_V7 = new ParseField("type").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((queryBuilder, value) -> {}, | ||
VALUE_FIELD.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7))); | ||
} | ||
|
||
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 MatchAllDocsQuery(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do actually still have type information available: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you suggest to check if the value used on a type query is _doc (this is the only type we can have, right?) then return matchAll otherwise matchNone? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what values can I expect from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still specify non- |
||
} | ||
|
||
@Override | ||
protected boolean doEquals(TypeQueryV7Builder other) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return 0; | ||
} | ||
|
||
public static TypeQueryV7Builder fromXContent(XContentParser parser) throws IOException { | ||
try { | ||
return PARSER.apply(parser, null); | ||
} catch (IllegalArgumentException e) { | ||
throw new ParsingException(parser.getTokenLocation(), e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return NAME; | ||
} | ||
} |
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.