|
31 | 31 |
|
32 | 32 | package org.opensearch.index.mapper;
|
33 | 33 |
|
| 34 | +import org.apache.logging.log4j.LogManager; |
| 35 | +import org.apache.logging.log4j.Logger; |
34 | 36 | import org.apache.lucene.document.Field;
|
35 | 37 | import org.apache.lucene.document.FieldType;
|
36 | 38 | import org.apache.lucene.document.LatLonShape;
|
37 | 39 | import org.apache.lucene.index.IndexOptions;
|
38 | 40 | import org.apache.lucene.index.IndexableField;
|
39 | 41 | import org.apache.lucene.search.Query;
|
| 42 | +import org.opensearch.Version; |
40 | 43 | import org.opensearch.common.Explicit;
|
41 | 44 | import org.opensearch.common.geo.GeometryParser;
|
42 | 45 | import org.opensearch.common.geo.ShapeRelation;
|
|
77 | 80 | * @opensearch.internal
|
78 | 81 | */
|
79 | 82 | public class GeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<Geometry, Geometry> {
|
| 83 | + private static final Logger logger = LogManager.getLogger(GeoShapeFieldMapper.class); |
80 | 84 | public static final String CONTENT_TYPE = "geo_shape";
|
81 | 85 | public static final FieldType FIELD_TYPE = new FieldType();
|
82 | 86 | static {
|
@@ -205,9 +209,24 @@ protected void addDocValuesFields(
|
205 | 209 | final List<IndexableField> indexableFields,
|
206 | 210 | final ParseContext context
|
207 | 211 | ) {
|
208 |
| - Field[] fieldsArray = new Field[indexableFields.size()]; |
209 |
| - fieldsArray = indexableFields.toArray(fieldsArray); |
210 |
| - context.doc().add(LatLonShape.createDocValueField(name, fieldsArray)); |
| 212 | + /* |
| 213 | + * We are adding the doc values for GeoShape only if the index is created with 2.9 and above version of |
| 214 | + * OpenSearch. If we don't do that after the upgrade of OpenSearch customers are not able to index documents |
| 215 | + * with GeoShape fields. Github issue: https://github.com/opensearch-project/OpenSearch/issues/10958, |
| 216 | + * https://github.com/opensearch-project/OpenSearch/issues/10795 |
| 217 | + */ |
| 218 | + if (context.indexSettings().getIndexVersionCreated().onOrAfter(Version.V_2_9_0)) { |
| 219 | + Field[] fieldsArray = new Field[indexableFields.size()]; |
| 220 | + fieldsArray = indexableFields.toArray(fieldsArray); |
| 221 | + context.doc().add(LatLonShape.createDocValueField(name, fieldsArray)); |
| 222 | + } else { |
| 223 | + logger.warn( |
| 224 | + "The index was created with Version : {}, for geoshape doc values to work index must be " |
| 225 | + + "created with OpenSearch Version : {} or above", |
| 226 | + context.indexSettings().getIndexVersionCreated(), |
| 227 | + Version.V_2_9_0 |
| 228 | + ); |
| 229 | + } |
211 | 230 | }
|
212 | 231 |
|
213 | 232 | @Override
|
|
0 commit comments