Я хочу использовать https://github.com/opensearch-project/s ... opensearch в своем приложении на основе весенней загрузки.
Я пытался следовать инструкции по импорту и настройке клиента, но безуспешно:
Ниже мой код:
pom.xml
org.opensearch.client
spring-data-opensearch-starter
${spring-data-opensearch-starter.version}
org.opensearch.client
opensearch-rest-high-level-client
org.opensearch.client
opensearch-java
${opensearch-java.version}
OpenSearchCustomClientConfig.java
import org.opensearch.client.RestHighLevelClient;
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration;
import org.opensearch.data.client.orhlc.ClientConfiguration;
import org.opensearch.data.client.orhlc.RestClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OpenSearchCustomClientConfig extends AbstractOpenSearchConfiguration {
@Override
@Bean
public RestHighLevelClient opensearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:32526")
.build();
return RestClients.create(clientConfiguration).rest();
}
}
MyApp.java
@SpringBootApplication(exclude = {ElasticsearchDataAutoConfiguration.class})
@ConfigurationPropertiesScan
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class);
}
}
MyService.java
@Autowired
RestHighLevelClient restHighLevelClient;
...
final var queryBuilder = QueryBuilders.matchQuery("content", "120");
final var searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(1000);
searchSourceBuilder.query(queryBuilder);
var sr = new SearchRequest();
sr.indices("pdf-search");
sr.source(searchSourceBuilder);
var response = restHighLevelClient.search(sr, RequestOptions.DEFAULT);
1 попытка:
OpenSearchCustomClientConfig.java не компилируется из-за ошибки «Невозможно разрешить RestHighLevelClient»2 попытка:
Удалить
org.opensearch.client
opensearch-rest-high-level-client
из pom.xml
ошибка:
"The bean 'opensearchClient', defined in class path resource [org/opensearch/spring/boot/autoconfigure/OpenSearchClientConfigurations$OpenSearchClientConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [myapp/configuration/OpenSearchCustomClientConfig.class] and overriding is disabled."
3 попытки:
Добавить
main:
allow-bean-definition-overriding: true
в application.yml
ошибка: «Параметр 4 конструктора в MyService требует bean-компонента типа 'org. opensearch.client.RestHighLevelClient', который не удалось найти."
4 попытка:
Код удален из 3, попробуйте использовать это вместо этого:
spring:
main
autoconfigure:
exclude: org.opensearch.spring.boot.autoconfigure.OpenSearchClientAutoConfiguration, org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration
ошибка:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchOperations' defined in class path resource [OpenSearchCustomClientConfig.class]: Post-processing of merged bean definition failed
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:577) ~[spring-beans-6.1.5.jar:6.1.5]
...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.opensearch.data.client.orhlc.OpenSearchRestTemplate] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@4e0e2f2a]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483) ~[spring-core-6.1.5.jar:6.1.5]
У меня нет идей, что нужно сделать, чтобы это настроить...
Использование
spring-boot 3.2.4
Подробнее здесь: https://stackoverflow.com/questions/786 ... ch-starter
Как использовать Spring-data-opensearch-starter ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение