forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the MapperFieldType.rangeQuery API. (elastic#26552)
RangeQueryBuilder needs to perform too many `instanceof` checks in order to check for `date` or `range` fields in order to know what it should do with the shape relation, time zone and date format. This commit adds those 3 parameters to the `rangeQuery` factory method so that those instanceof checks are not necessary anymore.
- Loading branch information
Showing
20 changed files
with
207 additions
and
138 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
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
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
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
63 changes: 63 additions & 0 deletions
63
core/src/main/java/org/elasticsearch/index/mapper/SimpleMappedFieldType.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,63 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.geo.ShapeRelation; | ||
import org.elasticsearch.common.joda.DateMathParser; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
import org.joda.time.DateTimeZone; | ||
|
||
/** | ||
* {@link MappedFieldType} base impl for field types that are neither dates nor ranges. | ||
*/ | ||
public abstract class SimpleMappedFieldType extends MappedFieldType { | ||
|
||
protected SimpleMappedFieldType() { | ||
super(); | ||
} | ||
|
||
protected SimpleMappedFieldType(MappedFieldType ref) { | ||
super(ref); | ||
} | ||
|
||
@Override | ||
public final Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, | ||
ShapeRelation relation, DateTimeZone timeZone, DateMathParser parser, QueryShardContext context) { | ||
if (relation == ShapeRelation.DISJOINT) { | ||
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + | ||
"] does not support DISJOINT ranges"); | ||
} | ||
// We do not fail on non-null time zones and date parsers | ||
// The reasoning is that on query parsers, you might want to set a time zone or format for date fields | ||
// but then the API has no way to know which fields are dates and which fields are not dates | ||
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context); | ||
} | ||
|
||
/** | ||
* Same as {@link #rangeQuery(Object, Object, boolean, boolean, ShapeRelation, DateTimeZone, DateMathParser, QueryShardContext)} | ||
* but without the trouble of relations or date-specific options. | ||
*/ | ||
protected Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, | ||
QueryShardContext context) { | ||
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries"); | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.