0

我使用弹性搜索 7.9 版,并在每个月滚动的索引中索引文档。我的问题是弹性搜索中的并发更新请求需要很长时间。例如,如果更新对象的总时间是 6000 毫秒,则在弹性搜索中更新文档需要 5500 毫秒,这对我们来说不是很好。这就是我配置与elasticsearch的连接的方式:

HttpHost[] hosts = new HttpHost[addresses.length];
                for (int i = 0, size = addresses.length; i < size; i++) {
                    hosts[i] = new HttpHost(addresses[i], port, "https");
                }
                Path trustStorePath = Paths.get(CERTIFICATE_FILEPATH));
                KeyStore truststore = KeyStore.getInstance("pkcs12");
                try (InputStream is = Files.newInputStream(trustStorePath)) {
                    truststore.load(is, PASSWORD);
                }
                SSLContextBuilder sslBuilder = SSLContexts.custom()
                        .loadTrustMaterial(truststore, null);
                final SSLContext sslContext = sslBuilder.build();
                SSLIOSessionStrategy sslConnectionSocketFactory = new SSLIOSessionStrategy(sslContext, NoopHostnameVerifier.INSTANCE);
                final CredentialsProvider credentialsProvider =
                        new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY,
                        new UsernamePasswordCredentials(USERNAME, PASSWORD));
                IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                        .setIoThreadCount(Runtime.getRuntime().availableProcessors())
                        .setConnectTimeout(6000)
                        .setSoTimeout(6000)
                        .build();
                ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
                PoolingNHttpClientConnectionManager poolingConnManager = new PoolingNHttpClientConnectionManager(ioReactor, RegistryBuilder.
                        <SchemeIOSessionStrategy>create()
                        .register("http", NoopIOSessionStrategy.INSTANCE)
                        .register("https", sslConnectionSocketFactory)
                        .build()
                );
                poolingConnManager.setMaxTotal(THREAD_POOL_SIZE);
                restClient = new RestHighLevelClient(RestClient.builder(hosts)
                        .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setSSLContext(sslContext)
                                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                                .setDefaultCredentialsProvider(credentialsProvider)
                                .setConnectionManager(poolingConnManager)
                        )
                        .setRequestConfigCallback(requestConfigBuilder ->
                                requestConfigBuilder
                                        .setConnectTimeout(6000)
                                        .setConnectionRequestTimeout(6000)
                                        .setSocketTimeout(6000)
                        )
                );

这是我在项目中的更新请求

UpdateRequest request = new UpdateRequest(
                indexName, id)
                .doc(doc, XContentType.JSON)
                .setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
                .retryOnConflict(5);
        
            UpdateResponse response = dataRestClient.update(request, RequestOptions.DEFAULT);
            

连接配置有问题吗

4

0 回答 0