Skip to content

Commit d6293d9

Browse files
committed
Test that wildcard uses ES819 docs encoding and geo_shape does not
1 parent 602c203 commit d6293d9

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.wildcard.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.wildcard.Wildcard;
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.hasEntry;
33+
34+
public class WildcardDocValueFormatTests extends ESSingleNodeTestCase {
35+
36+
protected Collection<Class<? extends Plugin>> getPlugins() {
37+
return List.of(Wildcard.class);
38+
}
39+
40+
public void testWildcardDocValueUseES819Format() throws IOException {
41+
String indexName = "test";
42+
String fieldName = "field_name";
43+
Settings settings = Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.getName()).build();
44+
IndexService indexService = createIndex(indexName, settings, "doc", "@timestamp", "type=date", fieldName, "type=wildcard");
45+
46+
var indexRequest = new IndexRequest(indexName)
47+
.opType(DocWriteRequest.OpType.CREATE)
48+
.source("""
49+
{
50+
"@timestamp": "2025-10-01T12:34:56.789",
51+
"%field": "baz"
52+
}
53+
""".replace("%field", fieldName), XContentType.JSON);
54+
var response = client().bulk(new BulkRequest().add(indexRequest)).actionGet();
55+
assertFalse(response.hasFailures());
56+
safeGet(indicesAdmin().refresh(new RefreshRequest(indexName).indicesOptions(IndicesOptions.lenientExpandOpenHidden())));
57+
58+
try (var searcher = indexService.getShard(0).acquireSearcher(indexName)) {
59+
try (var indexReader = searcher.getIndexReader()) {
60+
var leaves = indexReader.leaves();
61+
assertThat(leaves.size(), equalTo(1));
62+
FieldInfos fieldInfos = leaves.getFirst().reader().getFieldInfos();
63+
FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldName);
64+
assertNotNull(fieldInfo);
65+
Map<String, String> attributes = fieldInfo.attributes();
66+
assertThat(attributes, hasEntry("PerFieldDocValuesFormat.format", "ES819TSDB"));
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)