Skip to content

Commit fe3a18e

Browse files
committed
Enhance Point In Time support with APIs to list active point-in-time searches (opensearch-project#218)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent c90869d commit fe3a18e

7 files changed

Lines changed: 481 additions & 55 deletions

File tree

spring-data-opensearch/src/main/java/org/opensearch/data/client/orhlc/OpenSearchRestTemplate.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.opensearch.client.RequestOptions;
4646
import org.opensearch.client.RestHighLevelClient;
4747
import org.opensearch.common.unit.TimeValue;
48+
import org.opensearch.data.core.OpenSearchOperations;
4849
import org.opensearch.index.query.MoreLikeThisQueryBuilder;
4950
import org.opensearch.index.query.QueryBuilders;
5051
import org.opensearch.index.reindex.BulkByScrollResponse;
@@ -80,7 +81,7 @@
8081
* OpenSearchRestTemplate
8182
* @since 0.1
8283
*/
83-
public class OpenSearchRestTemplate extends AbstractElasticsearchTemplate {
84+
public class OpenSearchRestTemplate extends AbstractElasticsearchTemplate implements OpenSearchOperations {
8485

8586
private static final Log LOGGER = LogFactory.getLog(OpenSearchRestTemplate.class);
8687

@@ -468,6 +469,13 @@ public Boolean closePointInTime(String pit) {
468469
return false;
469470
}
470471

472+
@Override
473+
public List<PitInfo> listPointInTime() {
474+
return execute(client -> client.getAllPits(RequestOptions.DEFAULT))
475+
.getPitInfos().stream().map(pit -> new PitInfo(pit.getPitId(), pit.getCreationTime(), null))
476+
.toList();
477+
}
478+
471479
public SearchResponse suggest(SuggestBuilder suggestion, IndexCoordinates index) {
472480
SearchRequest searchRequest = requestFactory.searchRequest(suggestion, index);
473481
return execute(client -> client.search(searchRequest, RequestOptions.DEFAULT));

spring-data-opensearch/src/main/java/org/opensearch/data/client/osc/OpenSearchTemplate.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.opensearch.client.opensearch.core.pit.DeletePitRequest;
3838
import org.opensearch.client.opensearch.core.search.SearchResult;
3939
import org.opensearch.client.transport.Version;
40+
import org.opensearch.data.core.OpenSearchOperations;
4041
import org.springframework.data.elasticsearch.BulkFailureException;
4142
import org.springframework.data.elasticsearch.client.UnsupportedBackendOperation;
4243
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
@@ -75,7 +76,7 @@
7576
* @author Haibo Liu
7677
* @since 4.4
7778
*/
78-
public class OpenSearchTemplate extends AbstractElasticsearchTemplate {
79+
public class OpenSearchTemplate extends AbstractElasticsearchTemplate implements OpenSearchOperations {
7980

8081
private static final Log LOGGER = LogFactory.getLog(OpenSearchTemplate.class);
8182

@@ -615,6 +616,14 @@ public Boolean closePointInTime(String pit) {
615616
return !response.pits().isEmpty();
616617
}
617618

619+
@Override
620+
public List<PitInfo> listPointInTime() {
621+
return execute(client -> client.listAllPit()).pits()
622+
.stream()
623+
.map(pit -> new PitInfo(pit.pitId(), pit.creationTime(), pit.keepAlive() == null ? null : Duration.ofMillis(pit.keepAlive())))
624+
.toList();
625+
}
626+
618627
// endregion
619628

620629
// region script methods
@@ -719,5 +728,4 @@ protected List<IndexedObjectInformation> checkForBulkOperationFailure(BulkRespon
719728

720729
}
721730
// endregion
722-
723731
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.opensearch.data.core;
2+
3+
import java.time.Duration;
4+
import java.util.List;
5+
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
6+
7+
/**
8+
* The extension over {@link ElasticsearchOperations} with OpenSearch specific operations.
9+
*/
10+
public interface OpenSearchOperations extends ElasticsearchOperations {
11+
/**
12+
* Return all active point in time searches
13+
* @return all active point in time searches
14+
*/
15+
List<PitInfo> listPointInTime();
16+
17+
/**
18+
* Describes the point in time entry
19+
*
20+
* @param id the point in time id
21+
* @param creationTime the time this point in time was created
22+
* @param keepAlive the new keep alive value for this point in time
23+
*/
24+
record PitInfo(String id, long creationTime, Duration keepAlive) {
25+
}
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.data.client.orhlc;
11+
12+
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
13+
14+
import org.junit.jupiter.api.DisplayName;
15+
import org.opensearch.data.client.junit.jupiter.OpenSearchRestTemplateConfiguration;
16+
import org.opensearch.data.core.OpenSearchSpecificIntegrationTests;
17+
import org.springframework.context.annotation.Bean;
18+
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.context.annotation.Import;
20+
import org.springframework.data.elasticsearch.core.query.BaseQueryBuilder;
21+
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
22+
import org.springframework.test.context.ContextConfiguration;
23+
24+
@ContextConfiguration(classes = {OpenSearchORHLCSpecificIntegrationTests.Config.class})
25+
@DisplayName("Using OpenSearch RestHighLevelClient")
26+
public class OpenSearchORHLCSpecificIntegrationTests extends OpenSearchSpecificIntegrationTests {
27+
28+
@Configuration
29+
@Import({OpenSearchRestTemplateConfiguration.class})
30+
static class Config {
31+
@Bean
32+
IndexNameProvider indexNameProvider() {
33+
return new IndexNameProvider("integration-specific-os");
34+
}
35+
}
36+
@Override
37+
protected BaseQueryBuilder<?, ?> getBuilderWithMatchAllQuery() {
38+
return new NativeSearchQueryBuilder().withQuery(matchAllQuery());
39+
}
40+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2022-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.opensearch.data.client.osc;
17+
18+
import org.junit.jupiter.api.DisplayName;
19+
import org.opensearch.data.client.junit.jupiter.OpenSearchTemplateConfiguration;
20+
import org.opensearch.data.core.OpenSearchSpecificIntegrationTests;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.Import;
24+
import org.springframework.data.elasticsearch.core.query.BaseQueryBuilder;
25+
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
26+
import org.springframework.test.context.ContextConfiguration;
27+
28+
/**
29+
* @author Farid Faoudi
30+
* @author Sascha Woo
31+
* @since 4.4
32+
*/
33+
@ContextConfiguration(classes = { OpenSearchOSCSpecificIntegrationTests.Config.class })
34+
@DisplayName("Using OpenSearch Client")
35+
public class OpenSearchOSCSpecificIntegrationTests extends OpenSearchSpecificIntegrationTests {
36+
37+
@Configuration
38+
@Import({ OpenSearchTemplateConfiguration.class })
39+
static class Config {
40+
@Bean
41+
IndexNameProvider indexNameProvider() {
42+
return new IndexNameProvider("integration-specific-os");
43+
}
44+
}
45+
46+
@Override
47+
protected BaseQueryBuilder<?, ?> getBuilderWithMatchAllQuery() {
48+
return Queries.getBuilderWithMatchAllQuery();
49+
}
50+
}

0 commit comments

Comments
 (0)