Java Code Examples for io.searchbox.client.JestClientFactory#getObject()
The following examples show how to use
io.searchbox.client.JestClientFactory#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JestConfig.java From light-reading-cloud with MIT License | 6 votes |
@Bean public JestClient jestClient() { JestClientFactory factory = new JestClientFactory(); String[] sers = es_servers.split(","); HttpClientConfig httpClientConfig = new HttpClientConfig.Builder(Arrays.asList(sers)) .multiThreaded(true) .connTimeout(5000) .readTimeout(3000) .maxTotalConnection(10) .defaultMaxTotalConnectionPerRoute(10) .build(); factory.setHttpClientConfig(httpClientConfig); LOGGER.info("es_servers:{}", es_servers); return factory.getObject(); }
Example 2
Source File: TestCdiFactory.java From apiman with Apache License 2.0 | 6 votes |
@Produces @ApplicationScoped @Named("metrics") public static JestClient provideMetricsJestClient() { boolean enableESMetrics = "true".equals(System.getProperty("apiman-test.es-metrics", "false")); if (enableESMetrics) { String host = System.getProperty("apiman-test.es-metrics.host", "localhost"); String port = System.getProperty("apiman-test.es-metrics.port", "9200"); String connectionUrl = "http://" + host + ":" + port + ""; JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(connectionUrl).multiThreaded(true). connTimeout(JEST_TIMEOUT).readTimeout(JEST_TIMEOUT).build()); return factory.getObject(); } else { return null; } }
Example 3
Source File: HooverResource.java From newsleak with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } this.logger = this.getLogger(); // Construct a new Jest client according to configuration via factory JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(mHost + ":" + mPort).multiThreaded(false).build()); client = factory.getObject(); indexPath = mIndex + "/"; return true; }
Example 4
Source File: Jest.java From easy-sync with Apache License 2.0 | 6 votes |
private JestClient createJestClient(Es es) { JestClientFactory factory = new JestClientFactory(); List<String> addresses = Arrays.asList(es.getAddresses().split(";")); factory.setHttpClientConfig(new HttpClientConfig .Builder(addresses)// "http://localhost:9200") .multiThreaded(true) .connTimeout(10 * 000) .readTimeout(10 * 000) //Per default this implementation will create no more than 2 concurrent connections per given route // .defaultMaxTotalConnectionPerRoute(<YOUR_DESIRED_LEVEL_OF_CONCURRENCY_PER_ROUTE>) // and no more 20 connections in total // .maxTotalConnection(<YOUR_DESIRED_LEVEL_OF_CONCURRENCY_TOTAL>) .build()); JestClient jestClient = factory.getObject(); return jestClient; }
Example 5
Source File: ElasticSearchClientBuilder.java From vind with Apache License 2.0 | 5 votes |
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) .maxTotalConnection(10) .readTimeout(30000) .maxConnectionIdleTime(20, TimeUnit.SECONDS) .build()); return factory.getObject(); }
Example 6
Source File: BufferedJestHttpObjectFactory.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
ClientProvider<JestClient> getClientProvider(WrappedHttpClientConfig.Builder clientConfigBuilder) { return new JestClientProvider(clientConfigBuilder) { @Override public JestClient createClient() { WrappedHttpClientConfig wrappedHttpClientConfig = clientConfigBuilder.build(); JestClientFactory jestClientFactory = new BufferedJestClientFactory(wrappedHttpClientConfig); return jestClientFactory.getObject(); } }; }
Example 7
Source File: ElasticsearchService.java From c2mon with GNU Lesser General Public License v3.0 | 5 votes |
@Autowired public ElasticsearchService(C2monClientProperties properties, @Value("${c2mon.domain}") String domain) { this.timeSeriesIndex = domain + "-tag*"; this.configIndex = domain + "-tag-config"; this.alarmIndex = domain + "-alarm*"; this.maxResults = properties.getElasticsearch().getMaxResults(); JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(properties.getElasticsearch().getUrl()) .multiThreaded(true) .defaultCredentials(properties.getElasticsearch().getUsername(), properties.getElasticsearch().getPassword()) .build()); client = factory.getObject(); }
Example 8
Source File: JestClientDemo.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws IOException { // Construct a new Jest client according to configuration via factory JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig .Builder("http://172.22.6.9:9200") .multiThreaded(true) //Per default this implementation will create no more than 2 concurrent connections per given route .defaultMaxTotalConnectionPerRoute(2) // and no more 20 connections in total .maxTotalConnection(100) .build()); JestClient client = factory.getObject(); JestResult result = client.execute(new CreateIndex.Builder("user").build()); System.out.println("result = " + result.getJsonString()); }
Example 9
Source File: HttpESMetricsDispatcher.java From gradle-metrics-plugin with Apache License 2.0 | 5 votes |
@Override protected void startUpClient() { JestClientFactory factory = new JestClientFactory(); HttpClientConfig.Builder config = new HttpClientConfig .Builder(getURI(this.extension)) .multiThreaded(false); if (!Strings.isNullOrEmpty(extension.getEsBasicAuthUsername())) { config.defaultCredentials(extension.getEsBasicAuthUsername(), extension.getEsBasicAuthPassword()); } factory.setHttpClientConfig(config.build()); client = factory.getObject(); }
Example 10
Source File: BuildListener.java From elasticsearch-jenkins with MIT License | 5 votes |
public BuildListener() { LOG.info("Initializing"); /* final JestClientFactory factory = new JestClientFactory(); ClientConfig clientConfig = new ClientConfig.Builder(new ArrayList<String>()).multiThreaded(true).build(); factory.setClientConfig(clientConfig); jestClient = factory.getObject(); }*/ final JestClientFactory factory = new JestClientFactory(); HttpClientConfig clientConfig = new HttpClientConfig.Builder(new ArrayList<String>()).multiThreaded(true).build(); factory.setHttpClientConfig(clientConfig); jestClient = factory.getObject(); }
Example 11
Source File: ArticleServiceImpl.java From elasticsearch-jest-example with MIT License | 5 votes |
private static JestClient getJestClient() { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig .Builder("http://127.0.0.1:9200") .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create()) .multiThreaded(true) .readTimeout(10000) .build()); JestClient client = factory.getObject(); return client; }
Example 12
Source File: JestExample.java From elasticsearch-jest-example with MIT License | 5 votes |
private static JestClient getJestClient() { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig .Builder("http://127.0.0.1:9200") .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create()) .multiThreaded(true) .readTimeout(10000) .build()); JestClient client = factory.getObject(); return client; }
Example 13
Source File: ElasticsearchConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "shutdownClient") public JestClient jestClient() { // Construct a new Jest client according to configuration via factory JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig .Builder(environment.getProperty("jest.url")) .connTimeout(15000) .readTimeout(30000) .multiThreaded(true) .build()); return factory.getObject(); }
Example 14
Source File: JestDemoApplication.java From tutorials with MIT License | 5 votes |
private static JestClient jestClient() { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig( new HttpClientConfig.Builder("http://localhost:9200") .multiThreaded(true) .defaultMaxTotalConnectionPerRoute(2) .maxTotalConnection(20) .build()); return factory.getObject(); }
Example 15
Source File: JestManager.java From EserKnife with Apache License 2.0 | 4 votes |
/** * 获取JestClient对象 */ public static JestClient initJestClient(String clustName,EsClusterDetail esCluster) { JestClientFactory factory = new JestClientFactory(); StringBuilder key = new StringBuilder().append(clustName); try { if(esCluster != null && esCluster.getClusterList()!= null && esCluster.getClusterList().size() > 0){ List<Cluster> clusters = esCluster.getClusterList(); List<String> notes = new LinkedList<String>(); for (Cluster cluster : clusters){ notes.add("http://"+cluster.getHost()+":"+cluster.getHttpPort()); } HttpClientConfig.Builder httpClientConfig = new HttpClientConfig .Builder(notes) .connTimeout(1500) .readTimeout(15000) .multiThreaded(true) .discoveryEnabled(true) .discoveryFrequency(15000L, TimeUnit.MILLISECONDS); if(StringUtils.isNotBlank(esCluster.getUserName())){ CustomUser customUser = (CustomUser) RequestContext.getSessionAttribute(Constant.CUSTOM_USER_SESSION_NAME); ClusterInfo clusterInfo = CLUSTER_MAP.get(clustName); if(customUser != null){ if(customUser.isAdmin() && clusterInfo != null){ httpClientConfig.defaultCredentials(clusterInfo.getAdminRoleName(), clusterInfo.getAdminRolePwd()); key.append(clusterInfo.getAdminRoleName()); }else if (StringUtils.isNotBlank(customUser.getEsAccout()) && StringUtils.isNotBlank(customUser.getEsPwd())) { httpClientConfig.defaultCredentials(customUser.getEsAccout(), customUser.getEsPwd()); key.append(customUser.getEsAccout()); } else { httpClientConfig.defaultCredentials(clusterInfo != null ? clusterInfo.getMonitorRoleName() : "", clusterInfo != null ? clusterInfo.getMonitorRolePwd() : null); key.append(clusterInfo != null ? clusterInfo.getMonitorRoleName() : null); } }else{ httpClientConfig.defaultCredentials(clusterInfo.getMonitorRoleName(), clusterInfo.getMonitorRolePwd()); key.append(clusterInfo.getMonitorRoleName()); } } factory.setHttpClientConfig(httpClientConfig.build()); } }catch (Exception e){ e.printStackTrace(); LOGGER.error("初始化jestclient实例失败:",e); } JestClient jestClient = factory.getObject(); JEST_MAP.put(key.toString(),jestClient); return jestClient; }
Example 16
Source File: JestTest.java From java-study with Apache License 2.0 | 4 votes |
private static JestClient getJestClient() { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(elasticIps).connTimeout(60000).readTimeout(60000).multiThreaded(true).build()); return factory.getObject(); }
Example 17
Source File: JestTest.java From springBoot-study with Apache License 2.0 | 4 votes |
private static JestClient getJestClient() { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(elasticIps).connTimeout(60000).readTimeout(60000).multiThreaded(true).build()); return factory.getObject(); }
Example 18
Source File: JkesDeleteSinkTask.java From jkes with Apache License 2.0 | 4 votes |
public void start(Map<String, String> props, JestClient client) { try { log.info("Starting JkesDeleteSinkTask."); JkesDeleteSinkConnectorConfig config = new JkesDeleteSinkConnectorConfig(props); boolean ignoreSchema = config.getBoolean(JkesDeleteSinkConnectorConfig.SCHEMA_IGNORE_CONFIG); String versionType = config.getString(JkesDeleteSinkConnectorConfig.VERSION_TYPE_CONFIG); Set<String> topicIgnoreSchema = new HashSet<>(config.getList(JkesDeleteSinkConnectorConfig.TOPIC_SCHEMA_IGNORE_CONFIG)); long flushTimeoutMs = config.getLong(JkesDeleteSinkConnectorConfig.FLUSH_TIMEOUT_MS_CONFIG); int maxBufferedRecords = config.getInt(JkesDeleteSinkConnectorConfig.MAX_BUFFERED_RECORDS_CONFIG); int batchSize = config.getInt(JkesDeleteSinkConnectorConfig.BATCH_SIZE_CONFIG); long lingerMs = config.getLong(JkesDeleteSinkConnectorConfig.LINGER_MS_CONFIG); int maxInFlightRequests = config.getInt(JkesDeleteSinkConnectorConfig.MAX_IN_FLIGHT_REQUESTS_CONFIG); long retryBackoffMs = config.getLong(JkesDeleteSinkConnectorConfig.RETRY_BACKOFF_MS_CONFIG); int maxRetry = config.getInt(JkesDeleteSinkConnectorConfig.MAX_RETRIES_CONFIG); if (client != null) { this.client = client; } else { List<String> address = config.getList(JkesDeleteSinkConnectorConfig.CONNECTION_URL_CONFIG); JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(new HttpClientConfig.Builder(address).multiThreaded(true).build()); this.client = factory.getObject(); } JkesDocumentDeleter.Builder builder = new JkesDocumentDeleter.Builder(this.client) .setIgnoreSchema(ignoreSchema, topicIgnoreSchema) .setVersionType(versionType) .setFlushTimoutMs(flushTimeoutMs) .setMaxBufferedRecords(maxBufferedRecords) .setMaxInFlightRequests(maxInFlightRequests) .setBatchSize(batchSize) .setLingerMs(lingerMs) .setRetryBackoffMs(retryBackoffMs) .setMaxRetry(maxRetry); writer = builder.build(); writer.start(); } catch (ConfigException e) { throw new ConnectException("Couldn't start JkesDeleteSinkTask due to configuration error:", e); } }
Example 19
Source File: DefaultEsClientFactory.java From apiman with Apache License 2.0 | 4 votes |
/** * Creates a transport client from a configuration map. * @param config the configuration * @param indexName the name of the index * @param defaultIndexName the default index name * @return the ES client */ protected JestClient createJestClient(Map<String, String> config, String indexName, String defaultIndexName) { String host = config.get("client.host"); //$NON-NLS-1$ Integer port = NumberUtils.toInt(config.get("client.port"), 9200); //$NON-NLS-1$ String protocol = config.get("client.protocol"); //$NON-NLS-1$ String initialize = config.get("client.initialize"); //$NON-NLS-1$ String username = config.get("client.username"); //$NON-NLS-1$ String password = config.get("client.password"); //$NON-NLS-1$ Integer timeout = NumberUtils.toInt(config.get("client.timeout"), 10000); //$NON-NLS-1$ Integer maxConnectionIdleTime = NumberUtils.toInt(config.get("client.maxConnectionIdleTime"), 1000); //$NON-NLS-1$ if (StringUtils.isBlank(protocol)) { protocol = "http"; //$NON-NLS-1$ } if (StringUtils.isBlank(initialize)) { initialize = "true"; //$NON-NLS-1$ } if (StringUtils.isBlank(host)) { throw new RuntimeException("Missing client.host configuration for ESRegistry."); //$NON-NLS-1$ } synchronized (clients) { String clientKey = StringUtils.isNotBlank(indexName) ? "jest:" + host + ':' + port + '/' + indexName : null; if (clientKey != null && clients.containsKey(clientKey)) { return clients.get(clientKey); } else { String connectionUrl = protocol + "://" + host + ':' + port; Builder httpClientConfig = new HttpClientConfig.Builder(connectionUrl) .connTimeout(timeout) .readTimeout(timeout) .maxConnectionIdleTime(maxConnectionIdleTime,TimeUnit.MILLISECONDS) .maxTotalConnection(75) .defaultMaxTotalConnectionPerRoute(75) .multiThreaded(true); if (StringUtils.isNotBlank(username)) { httpClientConfig.defaultCredentials(username, password).setPreemptiveAuth(new HttpHost(connectionUrl, port, protocol)); } if ("https".equals(protocol)) { //$NON-NLS-1$ //$NON-NLS-2$ updateSslConfig(httpClientConfig, config); } JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(httpClientConfig.build()); JestClient client = factory.getObject(); if(clientKey != null) { clients.put(clientKey, client); if("true".equals(initialize)) { //$NON-NLS-1$ initializeClient(client, indexName, defaultIndexName); } } return client; } } }
Example 20
Source File: BeihuMutilElasticsearchJestAutoConfiguration.java From beihu-boot with Apache License 2.0 | 4 votes |
public JestClient buildJestClient(BeihuMutilElasticsearchJestProperties.Instances instance) { JestClientFactory factory = new JestClientFactory(); factory.setHttpClientConfig(createHttpClientConfig(instance)); return factory.getObject(); }