Skip to content
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

Use contains relation for geo_point intersection over geo_point field #75272

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -34,7 +34,6 @@ protected void createMapping(String indexName, String fieldName, Settings settin
client().admin().indices().prepareCreate(indexName).setMapping(xcb).setSettings(settings).get();
}

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