forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Type information is no longer available, thereofre type query in v7 compatibility is working as match_all query previously removed in elastic#47207 relates main meta issue elastic#51816 relates types removal meta elastic#54160
- Loading branch information
Showing
3 changed files
with
94 additions
and
2 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
89 changes: 89 additions & 0 deletions
89
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,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"; | ||
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(); | ||
} | ||
|
||
@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; | ||
} | ||
} |
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