|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.spatial.index.mapper; |
| 9 | + |
| 10 | +import org.apache.lucene.index.FieldInfo; |
| 11 | +import org.apache.lucene.index.FieldInfos; |
| 12 | +import org.elasticsearch.action.DocWriteRequest; |
| 13 | +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; |
| 14 | +import org.elasticsearch.action.bulk.BulkRequest; |
| 15 | +import org.elasticsearch.action.index.IndexRequest; |
| 16 | +import org.elasticsearch.action.support.IndicesOptions; |
| 17 | +import org.elasticsearch.common.settings.Settings; |
| 18 | +import org.elasticsearch.index.IndexMode; |
| 19 | +import org.elasticsearch.index.IndexService; |
| 20 | +import org.elasticsearch.index.IndexSettings; |
| 21 | +import org.elasticsearch.plugins.Plugin; |
| 22 | +import org.elasticsearch.test.ESSingleNodeTestCase; |
| 23 | +import org.elasticsearch.xcontent.XContentType; |
| 24 | +import org.elasticsearch.xpack.spatial.LocalStateSpatialPlugin; |
| 25 | + |
| 26 | +import java.io.IOException; |
| 27 | +import java.util.Collection; |
| 28 | +import java.util.List; |
| 29 | +import java.util.Map; |
| 30 | + |
| 31 | +import static org.hamcrest.Matchers.equalTo; |
| 32 | +import static org.hamcrest.Matchers.hasKey; |
| 33 | +import static org.hamcrest.Matchers.startsWith; |
| 34 | + |
| 35 | +public class GeoShapeDocValueFormatTests extends ESSingleNodeTestCase { |
| 36 | + |
| 37 | + @Override |
| 38 | + protected Collection<Class<? extends Plugin>> getPlugins() { |
| 39 | + return List.of(LocalStateSpatialPlugin.class); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * geo_shape uses binary doc values internally. As geo_shape does not work well with binary doc_value compression, if logsdb |
| 44 | + * is used, geo_shape should use the Lucene doc value format rather than ES819TSDBDocValuesFormat. |
| 45 | + */ |
| 46 | + public void testGeoShapeDocValueUseLuceneFormat() throws IOException { |
| 47 | + String indexName = "test"; |
| 48 | + String fieldName = "field_name"; |
| 49 | + Settings settings = Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.getName()).build(); |
| 50 | + IndexService indexService = createIndex(indexName, settings, "doc", "@timestamp", "type=date", fieldName, "type=geo_shape"); |
| 51 | + |
| 52 | + var indexRequest = new IndexRequest(indexName) |
| 53 | + .opType(DocWriteRequest.OpType.CREATE) |
| 54 | + .source(""" |
| 55 | + { |
| 56 | + "@timestamp": "2025-10-01T12:34:56.789", |
| 57 | + "%field": { |
| 58 | + "type" : "Point", |
| 59 | + "coordinates" : [-77.03653, 38.897676] |
| 60 | + } |
| 61 | + } |
| 62 | + """.replace("%field", fieldName), XContentType.JSON); |
| 63 | + var response = client().bulk(new BulkRequest().add(indexRequest)).actionGet(); |
| 64 | + assertFalse(response.hasFailures()); |
| 65 | + safeGet(indicesAdmin().refresh(new RefreshRequest(indexName).indicesOptions(IndicesOptions.lenientExpandOpenHidden()))); |
| 66 | + |
| 67 | + try (var searcher = indexService.getShard(0).acquireSearcher(indexName)) { |
| 68 | + try (var indexReader = searcher.getIndexReader()) { |
| 69 | + var leaves = indexReader.leaves(); |
| 70 | + assertThat(leaves.size(), equalTo(1)); |
| 71 | + FieldInfos fieldInfos = leaves.getFirst().reader().getFieldInfos(); |
| 72 | + FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldName); |
| 73 | + assertNotNull(fieldInfo); |
| 74 | + Map<String, String> attributes = fieldInfo.attributes(); |
| 75 | + assertThat(attributes, hasKey("PerFieldDocValuesFormat.format")); |
| 76 | + assertThat(attributes.get("PerFieldDocValuesFormat.format"), startsWith("Lucene")); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments