-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add geo_shape mapper supporting doc-values in Spatial Plugin (#55037)
After #53562, the `geo_shape` field mapper is registered within a module. This opens the door for introducing a new `geo_shape` field mapper into the Spatial Plugin that has doc-values support. This is very much an extension of server's GeoShapeFieldMapper, but with the addition of the doc values implementation.
- Loading branch information
Showing
41 changed files
with
3,880 additions
and
34 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
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
51 changes: 51 additions & 0 deletions
51
...va/org/elasticsearch/xpack/spatial/index/mapper/AbstractAtomicGeoShapeShapeFieldData.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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.spatial.index.mapper; | ||
|
||
import org.apache.lucene.util.Accountable; | ||
import org.elasticsearch.index.fielddata.ScriptDocValues; | ||
import org.elasticsearch.index.fielddata.SortedBinaryDocValues; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public abstract class AbstractAtomicGeoShapeShapeFieldData implements LeafGeoShapeFieldData { | ||
|
||
@Override | ||
public final SortedBinaryDocValues getBytesValues() { | ||
throw new UnsupportedOperationException("scripts and term aggs are not supported by geo_shape doc values"); | ||
} | ||
|
||
@Override | ||
public final ScriptDocValues.BytesRefs getScriptValues() { | ||
throw new UnsupportedOperationException("scripts are not supported by geo_shape doc values"); | ||
} | ||
|
||
public static LeafGeoShapeFieldData empty(final int maxDoc) { | ||
return new AbstractAtomicGeoShapeShapeFieldData() { | ||
|
||
@Override | ||
public long ramBytesUsed() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Collection<Accountable> getChildResources() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public MultiGeoShapeValues getGeoShapeValues() { | ||
return MultiGeoShapeValues.EMPTY; | ||
} | ||
}; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...ava/org/elasticsearch/xpack/spatial/index/mapper/AbstractLatLonShapeDVIndexFieldData.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,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.spatial.index.mapper; | ||
|
||
import org.apache.lucene.index.DocValuesType; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.search.SortField; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.util.BigArrays; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.fielddata.IndexFieldData; | ||
import org.elasticsearch.index.fielddata.IndexFieldDataCache; | ||
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
import org.elasticsearch.indices.breaker.CircuitBreakerService; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.MultiValueMode; | ||
import org.elasticsearch.search.sort.BucketedSort; | ||
import org.elasticsearch.search.sort.SortOrder; | ||
|
||
public abstract class AbstractLatLonShapeDVIndexFieldData extends DocValuesIndexFieldData implements IndexGeoShapeFieldData { | ||
AbstractLatLonShapeDVIndexFieldData(Index index, String fieldName) { | ||
super(index, fieldName); | ||
} | ||
|
||
@Override | ||
public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, XFieldComparatorSource.Nested nested, | ||
boolean reverse) { | ||
throw new IllegalArgumentException("can't sort on geo_shape field without using specific sorting feature, like geo_distance"); | ||
} | ||
|
||
public static class LatLonShapeDVIndexFieldData extends AbstractLatLonShapeDVIndexFieldData { | ||
public LatLonShapeDVIndexFieldData(Index index, String fieldName) { | ||
super(index, fieldName); | ||
} | ||
|
||
@Override | ||
public LeafGeoShapeFieldData load(LeafReaderContext context) { | ||
LeafReader reader = context.reader(); | ||
FieldInfo info = reader.getFieldInfos().fieldInfo(fieldName); | ||
if (info != null) { | ||
checkCompatible(info); | ||
} | ||
return new LatLonShapeDVAtomicShapeFieldData(reader, fieldName); | ||
} | ||
|
||
@Override | ||
public LeafGeoShapeFieldData loadDirect(LeafReaderContext context) throws Exception { | ||
return load(context); | ||
} | ||
|
||
@Override | ||
public BucketedSort newBucketedSort(BigArrays bigArrays, Object missingValue, MultiValueMode sortMode, | ||
IndexFieldData.XFieldComparatorSource.Nested nested, SortOrder sortOrder, DocValueFormat format, | ||
int bucketSize, BucketedSort.ExtraData extra) { | ||
throw new IllegalArgumentException("can't sort on geo_shape field without using specific sorting feature, like geo_distance"); | ||
} | ||
|
||
/** helper: checks a fieldinfo and throws exception if its definitely not a LatLonDocValuesField */ | ||
static void checkCompatible(FieldInfo fieldInfo) { | ||
// dv properties could be "unset", if you e.g. used only StoredField with this same name in the segment. | ||
if (fieldInfo.getDocValuesType() != DocValuesType.NONE | ||
&& fieldInfo.getDocValuesType() != DocValuesType.BINARY) { | ||
throw new IllegalArgumentException("field=\"" + fieldInfo.name + "\" was indexed with docValuesType=" | ||
+ fieldInfo.getDocValuesType() + " but this type has docValuesType=" | ||
+ DocValuesType.BINARY + ", is the field really a geo-shape field?"); | ||
} | ||
} | ||
} | ||
|
||
public static class Builder implements IndexFieldData.Builder { | ||
@Override | ||
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, | ||
CircuitBreakerService breakerService, MapperService mapperService) { | ||
// ignore breaker | ||
return new LatLonShapeDVIndexFieldData(indexSettings.getIndex(), fieldType.name()); | ||
} | ||
} | ||
} |
Oops, something went wrong.