Skip to content

Commit 6ddb5ef

Browse files
Merge pull request #257 from aodn/feature/8096-update-elastic-java
upgrade elastic-java to 8.19.10 with relevant code change
2 parents 32225fc + 2e72fdc commit 6ddb5ef

7 files changed

Lines changed: 33 additions & 31 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<dependency>
6868
<groupId>co.elastic.clients</groupId>
6969
<artifactId>elasticsearch-java</artifactId>
70-
<version>8.13.3</version>
70+
<version>8.19.10</version>
7171
</dependency>
7272
<dependency>
7373
<groupId>org.mapstruct</groupId>

server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/CQLFields.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ public enum CQLFields implements CQLFieldsInterface {
104104
(order) -> new SortOptions.Builder().script(s -> s
105105
.type(ScriptSortType.Number)
106106
.nested(NestedSortValue.of(p -> p.path(StacSummeries.Temporal.sortField)))
107-
.script(script -> script.inline(line -> line
107+
.script(script -> script
108108
.lang("painless")
109109
.source("if (doc['" + StacSummeries.TemporalEnd.searchField + "'].size() == 0) {" +
110-
" return Long.MAX_VALUE; " +
110+
" return Long.MAX_VALUE; " +
111111
" } " +
112112
" else {" +
113113
" return doc['" + StacSummeries.TemporalEnd.searchField + "'].stream()" +
114114
" .mapToLong(f -> f.toEpochMilli())" +
115115
" .max()" +
116116
" .getAsLong()" +
117117
" }"
118-
))
118+
)
119119
).order(order)
120120
)
121121
),
@@ -312,22 +312,23 @@ public enum CQLFields implements CQLFieldsInterface {
312312

313313
@Override
314314
public Query getPropertyEqualToQuery(String literal) {
315-
if(getOverridePropertyEqualsToQuery() == null) {
315+
if (getOverridePropertyEqualsToQuery() == null) {
316316
return MatchPhraseQuery.of(builder -> builder
317317
.field(this.searchField)
318318
.query(literal)
319319
)._toQuery();
320-
}
321-
else {
320+
} else {
322321
return getOverridePropertyEqualsToQuery().apply(literal);
323322
}
324323
}
325324

326325
@Override
327326
public Query getPropertyGreaterThanOrEqualsToQuery(String literal) {
328-
return RangeQuery.of(builder -> builder
329-
.field(this.searchField)
330-
.gte(JsonData.of(literal))
327+
return RangeQuery.of(builder -> builder
328+
// set as untyped because the property type is uncertain
329+
.untyped(u -> u
330+
.field(this.searchField)
331+
.gte(JsonData.of(literal)))
331332
)._toQuery();
332333
}
333334

@@ -354,7 +355,7 @@ public Query getBoundingBoxQuery(TopLeftBottomRightGeoBounds tlbr) {
354355
@Override
355356
public Query getIsNullQuery() {
356357
Query fieldExist = ExistsQuery.of(f -> f
357-
.field(this.searchField))._toQuery();
358+
.field(this.searchField))._toQuery();
358359

359360
return BoolQuery.of(b -> b
360361
.mustNot(fieldExist))._toQuery();
@@ -368,8 +369,10 @@ public Query getLikeQuery(String literal) {
368369
.flags("ALL")
369370
.value(literal))._toQuery();
370371
}
372+
371373
/**
372374
* Given param, find any of those is not a valid CQLCollectionsField
375+
*
373376
* @param args -
374377
* @return Invalid enum
375378
*/
@@ -379,8 +382,7 @@ public static List<String> findInvalidEnum(List<String> args) {
379382
try {
380383
CQLFields.valueOf(str);
381384
return false;
382-
}
383-
catch (IllegalArgumentException e) {
385+
} catch (IllegalArgumentException e) {
384386
return true;
385387
}
386388
})

server/src/main/java/au/org/aodn/ogcapi/server/core/parser/elastic/AfterImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields;
44
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
55
import au.org.aodn.ogcapi.server.core.model.enumeration.StacSummeries;
6-
import co.elastic.clients.json.JsonData;
76
import org.geotools.filter.AttributeExpressionImpl;
87
import org.geotools.filter.LiteralExpressionImpl;
98
import org.geotools.filter.text.cql2.CQLException;
@@ -42,9 +41,10 @@ public AfterImpl(Expression expression1, Expression expression2, Class<T> enumTy
4241
.path(StacSummeries.Temporal.searchField)
4342
.query(q1 -> q1
4443
.range(r -> r
45-
.field(StacSummeries.TemporalStart.searchField)
46-
.gte(JsonData.of(dateFormatter.format(literal.getValue())))
47-
.format("strict_date_optional_time")
44+
.date(d -> d
45+
.field(StacSummeries.TemporalStart.searchField)
46+
.gte(dateFormatter.format(literal.getValue()))
47+
.format("strict_date_optional_time"))
4848
)
4949
)
5050
)._toQuery();

server/src/main/java/au/org/aodn/ogcapi/server/core/parser/elastic/BeforeImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
55
import au.org.aodn.ogcapi.server.core.model.enumeration.StacSummeries;
66
import co.elastic.clients.elasticsearch._types.query_dsl.NestedQuery;
7-
import co.elastic.clients.json.JsonData;
87
import org.geotools.filter.AttributeExpressionImpl;
98
import org.geotools.filter.LiteralExpressionImpl;
109
import org.geotools.filter.text.cql2.CQLException;
@@ -42,9 +41,10 @@ public BeforeImpl(Expression expression1, Expression expression2, Class<T> enumT
4241
.path(StacSummeries.Temporal.searchField)
4342
.query(q1 -> q1
4443
.range(r -> r
45-
.field(StacSummeries.TemporalEnd.searchField)
46-
.lte(JsonData.of(dateFormatter.format(literal.getValue())))
47-
.format("strict_date_optional_time")
44+
.date(d -> d
45+
.field(StacSummeries.TemporalEnd.searchField)
46+
.lte(dateFormatter.format(literal.getValue()))
47+
.format("strict_date_optional_time"))
4848
)
4949
)
5050
)._toQuery();

server/src/main/java/au/org/aodn/ogcapi/server/core/parser/elastic/DuringImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import co.elastic.clients.elasticsearch._types.query_dsl.NestedQuery;
88
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
99
import co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery;
10-
import co.elastic.clients.json.JsonData;
1110
import org.geotools.filter.AttributeExpressionImpl;
1211
import org.geotools.filter.LiteralExpressionImpl;
1312
import org.geotools.filter.text.cql2.CQLException;
@@ -69,20 +68,22 @@ public DuringImpl(Expression expression1, Expression expression2, Class<T> enumT
6968
&& cqlFields == CQLFields.temporal) {
7069

7170
Query gte = RangeQuery.of(r -> r
71+
.date(d -> d
7272
.field(StacSummeries.TemporalStart.searchField)
73-
.gte(JsonData.of(dateFormatter.format(period.getBeginning().getPosition().getDate())))
74-
.format("strict_date_optional_time"))._toQuery();
73+
.gte(dateFormatter.format(period.getBeginning().getPosition().getDate()))
74+
.format("strict_date_optional_time")))._toQuery();
7575

7676
Query lte = RangeQuery.of(r -> r
77+
.date(d -> d
7778
.field(StacSummeries.TemporalEnd.searchField)
78-
.lte(JsonData.of(dateFormatter.format(period.getEnding().getPosition().getDate())))
79-
.format("strict_date_optional_time"))._toQuery();
79+
.lte(dateFormatter.format(period.getEnding().getPosition().getDate()))
80+
.format("strict_date_optional_time")))._toQuery();
8081

8182

8283
this.query = NestedQuery.of(n -> n
8384
.path(StacSummeries.Temporal.searchField)
84-
.query(BoolQuery.of(q -> q
85-
.must(gte, lte))._toQuery()
85+
.query(BoolQuery.of(q -> q
86+
.must(gte, lte))._toQuery()
8687
)
8788
)._toQuery();
8889
}

server/src/main/java/au/org/aodn/ogcapi/server/core/service/ElasticSearchBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected SearchResult<StacCollectionModel> searchCollectionBy(final List<Query>
178178
builder.query(q -> q.scriptScore(ss -> ss
179179
// to get the original _score from ELasticsearch
180180
.query(bq -> bq.bool(createBoolQueryForProperties(queries, should, filters)))
181-
.script(s -> s.inline(i -> i
181+
.script(s -> s
182182
.lang("painless")
183183
.source(
184184
// Step 1: Retrieve internal quality score from summaries.score field
@@ -197,7 +197,6 @@ protected SearchResult<StacCollectionModel> searchCollectionBy(final List<Query>
197197
// Final score = Elasticsearch relevance * normalized quality
198198
"return _score * multiplier;"
199199
)
200-
)
201200
))
202201
);
203202
}

server/src/test/resources/application-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ogcapi:
22
docker:
3-
elasticVersion: "8.13.3"
3+
elasticVersion: "8.19.10"
44

55
elasticsearch:
66
index:

0 commit comments

Comments
 (0)