Skip to content

Commit

Permalink
Use contains relation for geo_point intersection over geo_point field (
Browse files Browse the repository at this point in the history
…#75272) (#75321)

Lucene does not match points that are encoded to Integer.MAX_VALUE for intersects.
  • Loading branch information
iverase authored Jul 14, 2021
1 parent dbd97cd commit 85a55e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.lucene.document.LatLonDocValuesField;
import org.apache.lucene.document.LatLonPoint;
import org.apache.lucene.document.ShapeField;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.geo.LatLonGeometry;
import org.apache.lucene.index.LeafReaderContext;
Expand All @@ -28,6 +29,7 @@
import org.elasticsearch.common.xcontent.support.MapXContentParser;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.Point;
import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData;
import org.elasticsearch.index.query.SearchExecutionContext;
Expand Down Expand Up @@ -260,9 +262,17 @@ public Query geoShapeQuery(Geometry shape, String fieldName, ShapeRelation relat
if (luceneGeometries.length == 0) {
return new MatchNoDocsQuery();
}
Query query = LatLonPoint.newGeometryQuery(fieldName, relation.getLuceneRelation(), luceneGeometries);
final ShapeField.QueryRelation luceneRelation;
if (shape.type() == ShapeType.POINT && relation == ShapeRelation.INTERSECTS) {
// For point queries and intersects, lucene does not match points that are encoded to Integer.MAX_VALUE.
// We use contains instead.
luceneRelation = ShapeField.QueryRelation.CONTAINS;
} else {
luceneRelation = relation.getLuceneRelation();
}
Query query = LatLonPoint.newGeometryQuery(fieldName, luceneRelation, luceneGeometries);
if (hasDocValues()) {
Query dvQuery = LatLonDocValuesField.newSlowGeometryQuery(fieldName, relation.getLuceneRelation(), luceneGeometries);
Query dvQuery = LatLonDocValuesField.newSlowGeometryQuery(fieldName, luceneRelation, luceneGeometries);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected void createMapping(String indexName, String type, String fieldName, Se
client().admin().indices().prepareCreate(defaultIndexName).addMapping(type, xcb).get();
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/75103")
public void testFieldAlias() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder()
.startObject()
Expand Down

0 comments on commit 85a55e1

Please sign in to comment.