概述:
我尝试了 API 和本地 Elasticsearch 之间的非安全连接,一切正常。为了确保连接安全,我执行了以下步骤在我的弹性体上添加 xpack 插件并在 api 中使用它:
我的代码在弹性配置中发生了变化:
@Bean
public TransportClient transportClient() throws UnknownHostException {
Settings settings = Settings.builder()
.put("cluster.name", clusterName)
.put("xpack.security.user", "api:apipass")
.build();
try (TransportClient client = new PreBuiltXPackTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName(host), tcpPort))) {
String token = basicAuthHeaderValue("api", new SecureString("apipass".toCharArray()));
client.filterWithHeader(Collections.singletonMap("Authorization", token))
.prepareSearch().get();
return client;
}
}
Run Code Online (Sandbox Code Playgroud)
问题:
当尝试通过应用程序运行弹性查询时,将引发以下异常:
Caused by: java.lang.IllegalStateException: transport client is closed
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:243) ~[elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) ~[elasticsearch-6.0.0.jar:6.0.0]
at …Run Code Online (Sandbox Code Playgroud) elasticsearch elasticsearch-plugin spring-boot spring-data-elasticsearch elasticsearch-x-pack
我想在使用name进行搜索时cozum或在使用 name 进行记录后检索相同的对象。我已经搜索过这个并建议了。如何使用 spring data elasticsearch 实现此功能?\xc3\xa7\xc3\xb6z\xc3\xbcm\xc3\xa7\xc3\xb6z\xc3\xbcmasciifolding filter
@Document(indexName = "erp")\n public class Company {\n \n @Id\n private String id;\n \n private String name;\n \n private String description;\n \n @Field(type = FieldType.Nested, includeInParent = true)\n private List<Employee> employees;\n\n // getters, setter\n }\nRun Code Online (Sandbox Code Playgroud)\n spring elasticsearch spring-data spring-boot spring-data-elasticsearch
如何在 spring-boot 中为以下库指定更新版本的 Elasticsearch。这需要是一个gradle依赖
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '2.3.4.RELEASE'
say 7.9.1 instead of 7.6.2
Run Code Online (Sandbox Code Playgroud)
它会适用于较新的版本吗?
我想使用多播功能设置一个Elasticsearch集群。一个节点是一个外部Elasticsearch节点,另一个节点是一个节点客户端(客户端属性设置为true-not hold data)。
该节点客户端是使用spring数据elasticsearch创建的。所以我想将数据从Postgresql数据库索引到外部elasticsearch节点。我已经使用jdbc river插件对数据进行了索引。
但是我想知道是否可以使用postgresql而不是使用river插件来处理索引数据的任何应用程序?
我正在使用elasticsearch spring数据,我想添加过滤器,以便可以按字段存在/不存在或字段值为null / not null进行搜索。我应该怎么做?
我知道我应该使用这样的东西:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"exists": {
"field": "price"
}
},
... <-- your other constraints, if any
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在Elasticsearch Spring数据中实现它?
Optional.ofNullable(searchParams.getUid()).ifPresent(v -> filters.add(boolFilter().must(???????));
Run Code Online (Sandbox Code Playgroud) java elasticsearch spring-data spring-boot spring-data-elasticsearch
我是 ElasticsearchTemplate 的新手。我想根据我的查询从 Elasticsearch 获取 1000 个文档。我已经使用 QueryBuilder 创建了我的查询,它运行良好。我浏览了以下链接,其中指出可以使用扫描和滚动来实现大数据集。
链接一
链接二
我正在尝试在以下代码部分中实现此功能,我从上面提到的链接之一复制粘贴了这些代码。但我收到以下错误:
The type ResultsMapper is not generic; it cannot be parameterized with arguments <myInputDto>.
MyInputDto是@Document我项目中带有注释的类。一天结束,我只想从 Elasticsearch 检索 1000 个文档。我试图找到size参数,但我认为它不受支持。
String scrollId = esTemplate.scan(searchQuery, 1000, false);
List<MyInputDto> sampleEntities = new ArrayList<MyInputDto>();
boolean hasRecords = true;
while (hasRecords) {
Page<MyInputDto> page = esTemplate.scroll(scrollId, 5000L,
new ResultsMapper<MyInputDto>() {
@Override
public Page<MyInputDto> mapResults(SearchResponse response) {
List<MyInputDto> chunk = new ArrayList<MyInputDto>();
for (SearchHit searchHit : response.getHits()) {
if (response.getHits().getHits().length …Run Code Online (Sandbox Code Playgroud) 我的测试用例中有以下弹性搜索容器配置
@Container
public static GenericContainer container = new GenericContainer<>("elasticsearch:7.7.0")
.withExposedPorts(9200,9300).withEnv("discovery.type","single-node")
.withNetwork(Network.newNetwork())
.withNetworkAliases("someNetwork");
Run Code Online (Sandbox Code Playgroud)
在@BeforeAll 注释方法中,我像这样弹性搜索 url 属性
System.setProperty("spring.data.elasticsearch.cluster-nodes", container.getContainerIpAddress() + ":" + container.getMappedPort(9300));
Run Code Online (Sandbox Code Playgroud)
当我检查正在运行的容器时(在测试用例调试暂停期间),从 power shell 中,我在端口列下发现了类似的内容:0.0.0.0 : 32844->9200 / tcp, 0.0.0.0:32843->9300/tcp 当我打印container.getContainerIpAddress() + ":" + container.getMappedPort(9300),我在容器端口列中得到了映射到 9300 的相同端口,在本例中为localhost:32843,确保端口是随机的并且在每个新运行。
当代码`conf = repo.save(conf); 运行,我得到以下异常:
引起:org.apache.http.ProtocolException:无效的协议版本:这不是 HTTP 端口 在 org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:209) 在 org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:245) 在 org.apache.http .impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) 在 org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) 在 org.apache.http.impl.nio .reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) 在 org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) 在 org.apache.http.impl.nio.reactor.AbstractIOReactor .processEvent(AbstractIOReactor.java:337) 在 org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) 在 org.apache.http.impl.nio.reactor。AbstractIOReactor.execute(AbstractIOReactor.java:276) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker。 run(AbstractMultiworkerIOReactor.java:591) at java.base/java.lang.Thread.run(Thread.java:834) …
我正在使用 Elasticsearch 7.3 并且无法将其连接到我的 Spring boot 应用程序以使用ElasticsearchRepository.
@Configuration
public class ElasticSearchConfig {
@Value("${elasticsearch.host:localhost}")
public String host;
@Value("${elasticsearch.port:9300}")
public int port;
public String getHost() {
return host;
}
public int getPort() {
return port;
}
private int timeout = 60;
@Bean
public RestHighLevelClient client() {
System.out.println("host:" + host + "port:" + port);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "changeme"));
RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "http")).setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(timeout * 1000).setSocketTimeout(timeout * 1000)
.setConnectionRequestTimeout(0)); …Run Code Online (Sandbox Code Playgroud) spring elasticsearch spring-boot spring-data-elasticsearch resthighlevelclient
我正在使用 spring-data-elasticsearch-4.0.1.RELEASE 和 elasticsearch 版本 7.6.2 并尝试在保存到弹性时忽略一些字段。@JsonIgnore 现在不起作用还有其他方法可以实现此目的吗?我已经尝试过,@Field(index = false)但这也行不通。
我想将 AWS elastic search(开放搜索)与我的 Spring Boot 应用程序集成。为此,我按照https://medium.com/@prasanth_rajendran/how-to-integrate-spring-boot-elasticsearch-data-with-aws-445e6fc72998上的教程进行了细微的更改。
我收到的错误是Elasticsearch 版本 6 或更高版本是必需的,但我无法修复它。
这是我的应用程序中的代码片段
我使用的依赖项
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elasticsearch</artifactId>
<version>1.12.244</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>2.4.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是父pom依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Run Code Online (Sandbox Code Playgroud)
application.yml 看起来像这样
server:
port: 8087
spring:
application:
name: AWS ELK Demo
management:
health:
elasticsearch:
enabled: false
cloud:
aws:
credentials:
access-key: my-access-key
secret-key: my-secret key
region:
static: eu-central-1
Run Code Online (Sandbox Code Playgroud)
Rest高级客户端的配置类
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.example.awselkdemo.repository")
public class ElasticSearchRestClientConfiguration …Run Code Online (Sandbox Code Playgroud) amazon-web-services opensearch elasticsearch spring-boot spring-data-elasticsearch