use of io.searchbox.client.JestClientFactory in project vind by RBMHTechnology.
the class ElasticSearchClientBuilder method build.
public static JestClient build(String host, String port) {
final String conn = String.format("http://%s:%s", host, port);
log.info("Creating ElasticSearch REST Client over {}..,", conn);
final JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(conn).multiThreaded(true).build());
return factory.getObject();
}
use of io.searchbox.client.JestClientFactory in project DataX by alibaba.
the class ESClient method createClient.
public void createClient(String endpoint, String user, String passwd, boolean multiThread, int readTimeout, boolean compression, boolean discovery) {
JestClientFactory factory = new JestClientFactory();
Builder httpClientConfig = new HttpClientConfig.Builder(endpoint).setPreemptiveAuth(new HttpHost(endpoint)).multiThreaded(multiThread).connTimeout(30000).readTimeout(readTimeout).maxTotalConnection(200).requestCompressionEnabled(compression).discoveryEnabled(discovery).discoveryFrequency(5l, TimeUnit.MINUTES);
if (!("".equals(user) || "".equals(passwd))) {
httpClientConfig.defaultCredentials(user, passwd);
}
factory.setHttpClientConfig(httpClientConfig.build());
jestClient = factory.getObject();
}
use of io.searchbox.client.JestClientFactory in project spring-boot by spring-projects.
the class JestAutoConfiguration method jestClient.
@Bean(destroyMethod = "shutdownClient")
@ConditionalOnMissingBean
public JestClient jestClient() {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(createHttpClientConfig());
return factory.getObject();
}
use of io.searchbox.client.JestClientFactory in project opennms by OpenNMS.
the class ClientRecoveryTest method test.
@Test
public void test() {
LOG.debug("***************** start of test ClientRecoveryTest");
try {
IndexNameFunction indexNameFunction = new IndexNameFunction();
String rootIndexName = EventToIndex.INDEX_NAMES.get(EventToIndex.Indices.ALARMS);
String indexName = indexNameFunction.apply(rootIndexName, new Date());
// Get Jest client
HttpClientConfig clientConfig = new HttpClientConfig.Builder("http://localhost:9200").multiThreaded(true).build();
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(clientConfig);
JestClient jestClient = factory.getObject();
try {
String query = "{\n" + "\n \"query\": {" + "\n \"match\": {" + "\n \"alarmid\": \"1359\"" + "\n }" + "\n }" + "\n }";
Search search = new Search.Builder(query).addIndex(indexName).build();
SearchResult sresult = jestClient.execute(search);
LOG.debug("received search result: " + sresult.getJsonString() + "\n response code:" + sresult.getResponseCode() + "\n error message: " + sresult.getErrorMessage());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
// shutdown client
jestClient.shutdownClient();
}
} catch (Exception ex) {
ex.printStackTrace();
}
LOG.debug("***************** end of test ClientRecoveryTest");
}
use of io.searchbox.client.JestClientFactory in project nutch by apache.
the class ElasticRestIndexWriter method open.
@Override
public void open(Configuration conf, String name) throws IOException {
hosts = conf.getStrings(ElasticRestConstants.HOST);
port = conf.getInt(ElasticRestConstants.PORT, 9200);
user = conf.get(ElasticRestConstants.USER);
password = conf.get(ElasticRestConstants.PASSWORD);
https = conf.getBoolean(ElasticRestConstants.HTTPS, false);
trustAllHostnames = conf.getBoolean(ElasticRestConstants.HOSTNAME_TRUST, false);
languages = conf.getStrings(ElasticRestConstants.LANGUAGES);
separator = conf.get(ElasticRestConstants.SEPARATOR, DEFAULT_SEPARATOR);
sink = conf.get(ElasticRestConstants.SINK, DEFAULT_SINK);
// trust ALL certificates
SSLContext sslContext = null;
try {
sslContext = new SSLContextBuilder().loadTrustMaterial(new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
LOG.error("Failed to instantiate sslcontext object: \n{}", ExceptionUtils.getStackTrace(e));
throw new SecurityException();
}
// skip hostname checks
HostnameVerifier hostnameVerifier = null;
if (trustAllHostnames) {
hostnameVerifier = NoopHostnameVerifier.INSTANCE;
} else {
hostnameVerifier = new DefaultHostnameVerifier();
}
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
JestClientFactory jestClientFactory = new JestClientFactory();
if (hosts == null || hosts.length == 0 || port <= 1) {
throw new IllegalStateException("No hosts or port specified. Please set the host and port in nutch-site.xml");
}
List<String> urlsOfElasticsearchNodes = new ArrayList<String>();
for (String host : hosts) {
urlsOfElasticsearchNodes.add(new URL(https ? "https" : "http", host, port, "").toString());
}
HttpClientConfig.Builder builder = new HttpClientConfig.Builder(urlsOfElasticsearchNodes).multiThreaded(true).connTimeout(300000).readTimeout(300000);
if (https) {
if (user != null && password != null) {
builder.defaultCredentials(user, password);
}
builder.defaultSchemeForDiscoveredNodes("https").sslSocketFactory(// this only affects sync calls
sslSocketFactory).httpsIOSessionStrategy(// this only affects async calls
httpsIOSessionStrategy);
}
jestClientFactory.setHttpClientConfig(builder.build());
client = jestClientFactory.getObject();
defaultIndex = conf.get(ElasticRestConstants.INDEX, "nutch");
defaultType = conf.get(ElasticRestConstants.TYPE, "doc");
maxBulkDocs = conf.getInt(ElasticRestConstants.MAX_BULK_DOCS, DEFAULT_MAX_BULK_DOCS);
maxBulkLength = conf.getInt(ElasticRestConstants.MAX_BULK_LENGTH, DEFAULT_MAX_BULK_LENGTH);
bulkBuilder = new Bulk.Builder().defaultIndex(defaultIndex).defaultType(defaultType);
}
Aggregations