Skip to content

Commit 5fdfc75

Browse files
committed
geo_point runtime field implementation (elastic#63164)
Run time field that emits geo points from lat/lon values.
1 parent b6025c3 commit 5fdfc75

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/mapper/RuntimeFieldMapper.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ public static class Builder extends ParametrizedFieldMapper.Builder {
116116
IpFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), IpFieldScript.CONTEXT);
117117
return new IpScriptFieldType(builder.buildFullName(context), builder.script.getValue(), factory, builder.meta.getValue());
118118
}, GeoPointFieldMapper.CONTENT_TYPE, (builder, context) -> {
119-
builder.formatAndLocaleNotSupported();
120-
GeoPointFieldScript.Factory factory = builder.scriptCompiler.compile(
121-
builder.script.getValue(),
122-
GeoPointFieldScript.CONTEXT);
123-
return new GeoPointScriptFieldType(
124-
builder.buildFullName(context),
125-
builder.script.getValue(),
126-
factory,
127-
builder.meta.getValue()
128-
);
129-
}, KeywordFieldMapper.CONTENT_TYPE, (builder, context) -> {
119+
builder.formatAndLocaleNotSupported();
120+
GeoPointFieldScript.Factory factory = builder.scriptCompiler.compile(
121+
builder.script.getValue(),
122+
GeoPointFieldScript.CONTEXT
123+
);
124+
return new GeoPointScriptFieldType(
125+
builder.buildFullName(context),
126+
builder.script.getValue(),
127+
factory,
128+
builder.meta.getValue()
129+
);
130+
}, KeywordFieldMapper.CONTENT_TYPE, (builder, context) -> {
130131
builder.formatAndLocaleNotSupported();
131132
StringFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), StringFieldScript.CONTEXT);
132133
return new KeywordScriptFieldType(

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/GeoPointScriptFieldTypeTests.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ protected boolean supportsRangeQueries() {
6565
@Override
6666
public void testDocValues() throws IOException {
6767
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
68-
iw.addDocument(org.elasticsearch.common.collect.List.of(
69-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}")))
68+
iw.addDocument(
69+
org.elasticsearch.common.collect.List.of(
70+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}"))
71+
)
7072
);
71-
iw.addDocument(org.elasticsearch.common.collect.List.of(
72-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}")))
73+
iw.addDocument(
74+
org.elasticsearch.common.collect.List.of(
75+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}"))
76+
)
7377
);
7478
List<Object> results = new ArrayList<>();
7579
try (DirectoryReader reader = iw.getReader()) {
@@ -116,11 +120,15 @@ public void testSort() throws IOException {
116120
@Override
117121
public void testUsedInScript() throws IOException {
118122
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
119-
iw.addDocument(org.elasticsearch.common.collect.List.of(
120-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}")))
123+
iw.addDocument(
124+
org.elasticsearch.common.collect.List.of(
125+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}"))
126+
)
121127
);
122-
iw.addDocument(org.elasticsearch.common.collect.List.of(
123-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}")))
128+
iw.addDocument(
129+
org.elasticsearch.common.collect.List.of(
130+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}"))
131+
)
124132
);
125133
try (DirectoryReader reader = iw.getReader()) {
126134
IndexSearcher searcher = newSearcher(reader);
@@ -149,11 +157,15 @@ public double execute(ExplanationHolder explanation) {
149157
@Override
150158
public void testExistsQuery() throws IOException {
151159
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
152-
iw.addDocument(org.elasticsearch.common.collect.List.of(
153-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}")))
160+
iw.addDocument(
161+
org.elasticsearch.common.collect.List.of(
162+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 45.0, \"lon\" : 45.0}}"))
163+
)
154164
);
155-
iw.addDocument(org.elasticsearch.common.collect.List.of(
156-
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}")))
165+
iw.addDocument(
166+
org.elasticsearch.common.collect.List.of(
167+
new StoredField("_source", new BytesRef("{\"foo\": {\"lat\": 0.0, \"lon\" : 0.0}}"))
168+
)
157169
);
158170
try (DirectoryReader reader = iw.getReader()) {
159171
IndexSearcher searcher = newSearcher(reader);

0 commit comments

Comments
 (0)