當前位置: 首頁>>代碼示例>>Java>>正文


Java Builder.build方法代碼示例

本文整理匯總了Java中org.elasticsearch.common.settings.Settings.Builder.build方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.build方法的具體用法?Java Builder.build怎麽用?Java Builder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.common.settings.Settings.Builder的用法示例。


在下文中一共展示了Builder.build方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initESClient

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
@Bean
public TransportClient initESClient() throws NumberFormatException, UnknownHostException{
	String ip = env.getProperty("spring.es.ip");
	String port = env.getProperty("spring.es.port");
	String clusterName = env.getProperty("spring.es.cluster_name");
	
	Builder builder = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", true);
	Settings esSettings = builder.build();
	TransportClient client = new PreBuiltTransportClient(esSettings);
	client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.parseInt(port)));
	logger.info("ES Client 初始化成功, ip : {}, port : {}, cluster_name : {}", ip, port, clusterName);
	return client;
}
 
開發者ID:SnailFastGo,項目名稱:springboot_op,代碼行數:14,代碼來源:ElasticsearchConfiguration.java

示例2: getSettings

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) {
    Builder builder = Settings.builder().put(defaultSettings)
        .put(getRandomNodeSettings(nodeSeed));
    Settings settings = nodeConfigurationSource.nodeSettings(nodeOrdinal);
    if (settings != null) {
        if (settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) != null) {
            throw new IllegalStateException("Tests must not set a '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "' as a node setting set '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "': [" + settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) + "]");
        }
        builder.put(settings);
    }
    if (others != null) {
        builder.put(others);
    }
    builder.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName);
    return builder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:InternalTestCluster.java

示例3: testBackwardsCompatibilityEdgeNgramTokenFilter

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception {
    int iters = scaledRandomIntBetween(20, 100);
    for (int i = 0; i < iters; i++) {
        final Index index = new Index("test", "_na_");
        final String name = "ngr";
        Version v = randomVersion(random());
        Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3);
        boolean reverse = random().nextBoolean();
        if (reverse) {
            builder.put("side", "back");
        }
        Settings settings = builder.build();
        Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build();
        Tokenizer tokenizer = new MockTokenizer();
        tokenizer.setReader(new StringReader("foo bar"));
        TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create(tokenizer);
        if (reverse) {
            assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class));
        } else {
            assertThat(edgeNGramTokenFilter, instanceOf(EdgeNGramTokenFilter.class));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:NGramTokenizerFactoryTests.java

示例4: ElasticNamespaceDAO

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public ElasticNamespaceDAO(ElasticDAOConfig config) {
	try {
		Builder builder = Settings.builder();
		// Check for new hosts within the cluster
		builder.put(CLIENT_SNIFFING_CONFIG, true);
		// specify cluster name
		if (config.getClusterName() != null) {
			builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
		}
		Settings settings = builder.build();
		// create client
		elasticClient = new PreBuiltTransportClient(settings);
		// add hosts
		for (String elasticHost : config.getHosts()) {
			elasticClient.addTransportAddress(
					new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
		}
	} catch (UnknownHostException e) {
		throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage());
	}
}
 
開發者ID:carone1,項目名稱:ecs-dashboard,代碼行數:22,代碼來源:ElasticNamespaceDAO.java

示例5: ElasticVdcDAO

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public ElasticVdcDAO(ElasticDAOConfig config) {
	try {
		Builder builder = Settings.builder();
		// Check for new hosts within the cluster
		builder.put(CLIENT_SNIFFING_CONFIG, true);
		// specify cluster name
		if (config.getClusterName() != null) {
			builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
		}
		Settings settings = builder.build();
		// create client
		elasticClient = new PreBuiltTransportClient(settings);
		// add hosts
		for (String elasticHost : config.getHosts()) {
			elasticClient.addTransportAddress(
					new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
		}
	} catch (UnknownHostException e) {
		throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage());
	}
}
 
開發者ID:carone1,項目名稱:ecs-dashboard,代碼行數:22,代碼來源:ElasticVdcDAO.java

示例6: testPositionIncrementSetting

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public void testPositionIncrementSetting() throws IOException {
    Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop")
            .put("index.analysis.filter.my_stop.enable_position_increments", false);
    if (random().nextBoolean()) {
        builder.put("index.analysis.filter.my_stop.version", "5.0");
    }
    builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
    Settings settings = builder.build();
    try {
        AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("enable_position_increments is not supported anymore"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:StopTokenFilterTests.java

示例7: createClient

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
/**
   * This method will create the client instance for elastic search.
   * @param clusterName String
   * @param host  List<String>
   * @param port List<Integer>
   * @return boolean
   * @throws Exception
   */
private static boolean createClient(String clusterName, List<String> host, List<Integer> port) throws Exception {
	Builder builder = Settings.builder();
	if (clusterName != null && !"".equals(clusterName)) {
		builder = builder.put("cluster.name", clusterName);
	}
	builder = builder.put("client.transport.sniff", true);
	builder = builder.put("client.transport.ignore_cluster_name", true);
	client = new PreBuiltTransportClient(builder.build());
	for (int i = 0; i < host.size(); i++) {
		client.addTransportAddress(
				new InetSocketTransportAddress(InetAddress.getByName(host.get(i)), ports.get(i)));
	}
	return true;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:23,代碼來源:ConnectionManager.java

示例8: ElasticBillingDAO

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public ElasticBillingDAO(ElasticDAOConfig config) {
	
	try {
		
		Builder builder = Settings.builder();
		
		// Check for new hosts within the cluster
		builder.put(CLIENT_SNIFFING_CONFIG, true);
		
		// specify cluster name
		if( config.getClusterName() != null ) {
			builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
		}
		
		Settings settings = builder.build();
		
		// create client
		elasticClient = new PreBuiltTransportClient(settings);
		
		// add hosts
		for( String elasticHost : config.getHosts()) {
			elasticClient.addTransportAddress(
					new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));				
		}
		
	} catch (UnknownHostException e) {
		throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage() );
	}				
}
 
開發者ID:carone1,項目名稱:ecs-dashboard,代碼行數:30,代碼來源:ElasticBillingDAO.java

示例9: startElasticNode

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
private void startElasticNode() throws InterruptedException, ExecutionException, IOException {

		Builder builder = Settings.builder()//
				.put("node.master", true)//
				.put("node.data", true)//
				.put("cluster.name", CLUSTER_NAME)//
				// disable automatic index creation
				.put("action.auto_create_index", false)//
				// disable dynamic indexing
				.put("index.mapper.dynamic", false)//
				// disable rebalance to avoid automatic rebalance
				// when a temporary second node appears
				.put("cluster.routing.rebalance.enable", "none")//
				.put("http.enabled", //
						config.isElasticHttpEnabled())//
				.put("network.host", //
						config.elasticNetworkHost())//
				.put("path.home", //
						config.homePath().toAbsolutePath().toString())
				.put("path.data", //
						config.elasticDataPath().toAbsolutePath().toString());

		if (config.snapshotsPath().isPresent())
			builder.put("path.repo", //
					config.snapshotsPath().get().toAbsolutePath().toString());

		elasticNode = new ElasticNode(builder.build(), //
				DeleteByQueryPlugin.class, //
				CloudAwsPlugin.class);

		elasticNode.start();
		setElasticClient(elasticNode.client());

		// wait for cluster to fully initialize and turn asynchronously from
		// RED status to GREEN before to initialize anything else
		// wait for 60 seconds maximum
		elastic.ensureAllIndicesGreen();
	}
 
開發者ID:spacedog-io,項目名稱:spacedog-server,代碼行數:39,代碼來源:Start.java

示例10: getRandomNodeSettings

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
private Settings getRandomNodeSettings(long seed) {
    Random random = new Random(seed);
    Builder builder = Settings.builder();
    builder.put(Transport.TRANSPORT_TCP_COMPRESS.getKey(), rarely(random));
    if (random.nextBoolean()) {
        builder.put("cache.recycler.page.type", RandomPicks.randomFrom(random, PageCacheRecycler.Type.values()));
    }
    if (random.nextInt(10) == 0) { // 10% of the nodes have a very frequent check interval
        builder.put(SearchService.KEEPALIVE_INTERVAL_SETTING.getKey(), TimeValue.timeValueMillis(10 + random.nextInt(2000)).getStringRep());
    } else if (random.nextInt(10) != 0) { // 90% of the time - 10% of the time we don't set anything
        builder.put(SearchService.KEEPALIVE_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(10 + random.nextInt(5 * 60)).getStringRep());
    }
    if (random.nextBoolean()) { // sometimes set a
        builder.put(SearchService.DEFAULT_KEEPALIVE_SETTING.getKey(), TimeValue.timeValueSeconds(100 + random.nextInt(5 * 60)).getStringRep());
    }

    builder.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1 + random.nextInt(3));
    if (random.nextBoolean()) {
        if (random.nextBoolean()) {
            builder.put("indices.fielddata.cache.size", 1 + random.nextInt(1000), ByteSizeUnit.MB);
        }
    }

    // randomize tcp settings
    if (random.nextBoolean()) {
        builder.put(TcpTransport.CONNECTIONS_PER_NODE_RECOVERY.getKey(), random.nextInt(2) + 1);
        builder.put(TcpTransport.CONNECTIONS_PER_NODE_BULK.getKey(), random.nextInt(3) + 1);
        builder.put(TcpTransport.CONNECTIONS_PER_NODE_REG.getKey(), random.nextInt(6) + 1);
    }

    if (random.nextBoolean()) {
        builder.put(MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING.getKey(), new TimeValue(RandomNumbers.randomIntBetween(random, 10, 30), TimeUnit.SECONDS));
    }

    if (random.nextInt(10) == 0) {
        builder.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop");
        builder.put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop");
    }

    if (random.nextBoolean()) {
        if (random.nextInt(10) == 0) { // do something crazy slow here
            builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 10), ByteSizeUnit.MB));
        } else {
            builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 10, 200), ByteSizeUnit.MB));
        }
    }

    if (random.nextBoolean()) {
        builder.put(TcpTransport.PING_SCHEDULE.getKey(), RandomNumbers.randomIntBetween(random, 100, 2000) + "ms");
    }

    if (random.nextBoolean()) {
        builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), RandomNumbers.randomIntBetween(random, 0, 2000));
    }
    if (random.nextBoolean()) {
        builder.put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getKey(), TimeValue.timeValueMillis(RandomNumbers.randomIntBetween(random, 750, 10000000)).getStringRep());
    }

    return builder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:61,代碼來源:InternalTestCluster.java

示例11: main

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public static void main(String[] args) {

		try {
			Builder builder = Settings.builder();
			//builder.put("client.transport.sniff", true);
			builder.put("cluster.name", "elasticsearch");

			Settings settings = builder.build();
			
			String stringQuery = "{\"match_all\" : {  }}";
			String q = QueryParser.escape(stringQuery);
			System.out.println(q);
			//System.out.println(new MatchAllQueryBuilder());
			Client esClient = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
			
			
					
			
			QueryBuilder  queryBuilder= QueryBuilders.wrapperQuery(stringQuery);
			
			String[] fields = new String[2];
			fields[0]="name";
			fields[1]="name1";
			SearchResponse scrollResp  = esClient.prepareSearch("test")
			        .setTypes("test")			        
			        .setQuery(queryBuilder).setFetchSource(fields, null)
			        .setSize(250)//.addSort("name", SortOrder.ASC)
			        .get();
			
			SearchHit[] searchHits = scrollResp.getHits().getHits();
			for(SearchHit searchHit:searchHits){
				System.out.println(searchHit.getSourceAsMap());
			}
			
			/*int i=0;
			while (true) {
				System.out.println(scrollResp);
				System.out.println(scrollResp.getHits().totalHits());
	//System.out.println(scrollResp.getHits().getHits().length);
			    //for (SearchHit hit : scrollResp.getHits().getHits()) {
//System.out.println(hit.sourceAsMap());
			    	//System.out.println(i++);

			   // }
			    scrollResp = esClient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
			    if (scrollResp.getHits().getHits().length == 0) {
			        break;
			    }
			}*/

		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

	}
 
開發者ID:raghavendar-ts,項目名稱:ElasticTab-Elasticsearch-to-Excel-Report,代碼行數:56,代碼來源:Test.java

示例12: ElasticS3ObjectDAO

import org.elasticsearch.common.settings.Settings.Builder; //導入方法依賴的package包/類
public ElasticS3ObjectDAO( ElasticDAOConfig config ) {
	
	try {
		this.config = config;
		
		
		Builder builder = Settings.builder();
		
		// Check for new hosts within the cluster
		builder.put(CLIENT_SNIFFING_CONFIG, true);
		
		// specify cluster name
		if( config.getClusterName() != null ) {
			builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
		}
		
		Settings settings = builder.build();
		
		// create client
		elasticClient = new PreBuiltTransportClient(settings);
		
		
		// add hosts
		for( String elasticHost : config.getHosts()) {
			elasticClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));				
		}
		
		
	} catch (UnknownHostException e) {
		throw new RuntimeException(e.getLocalizedMessage());
	}				
}
 
開發者ID:carone1,項目名稱:ecs-dashboard,代碼行數:33,代碼來源:ElasticS3ObjectDAO.java


注:本文中的org.elasticsearch.common.settings.Settings.Builder.build方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。