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


Java Builder類代碼示例

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


Builder類屬於org.elasticsearch.common.settings.Settings包,在下文中一共展示了Builder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: indexRandomNumbers

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
private int indexRandomNumbers(String analyzer, int shards, boolean dummyDocs) throws Exception {
    Builder builder = Settings.builder().put(indexSettings());

    if (shards > 0) {
        builder.put(SETTING_NUMBER_OF_SHARDS, shards);
    }

    assertAcked(prepareCreate("test")
            .addMapping(
                    "type1",
                    jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1")
                            .field("analyzer", analyzer).field("type", "text").endObject().endObject().endObject().endObject())
            .setSettings(builder));
    int numDocs = randomIntBetween(100, 150);
    IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i));
    }

    indexRandom(true, dummyDocs, docs);
    ensureGreen();
    return numDocs;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:QueryRescorerIT.java

示例4: testFromSize

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
public void testFromSize() throws Exception {
    Builder settings = Settings.builder();
    settings.put(SETTING_NUMBER_OF_SHARDS, 1);
    settings.put(SETTING_NUMBER_OF_REPLICAS, 0);
    assertAcked(prepareCreate("test").setSettings(settings));
    for(int i=0;i<5;i++) {
        client().prepareIndex("test", "type", ""+i).setSource("text", "hello world").get();
    }
    refresh();

    SearchRequestBuilder request = client().prepareSearch();
    request.setQuery(QueryBuilders.termQuery("text", "hello"));
    request.setFrom(1);
    request.setSize(4);
    request.addRescorer(RescoreBuilder.queryRescorer(QueryBuilders.matchAllQuery()), 50);

    assertEquals(4, request.get().getHits().getHits().length);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:QueryRescorerIT.java

示例5: 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

示例6: testCorrectPositionIncrementSetting

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
public void testCorrectPositionIncrementSetting() throws IOException {
    Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop");
    if (random().nextBoolean()) {
        builder.put("index.analysis.filter.my_stop.version", Version.LATEST);
    } else {
        // don't specify
    }
    builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(builder.build());
    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("my_stop");
    assertThat(tokenFilter, instanceOf(StopTokenFilterFactory.class));
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader("foo bar"));
    TokenStream create = tokenFilter.create(tokenizer);
    assertThat(create, instanceOf(StopFilter.class));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:StopTokenFilterTests.java

示例7: setUp

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
public void setUp(final BiConsumer<Integer, Builder> consumer) throws Exception {
    clusterName = "es-idxproxy-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild((number, settingsBuilder) -> {
        settingsBuilder.put("http.cors.enabled", true);
        settingsBuilder.put("http.cors.allow-origin", "*");
        settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "127.0.0.1:9301-9310");
        consumer.accept(number, settingsBuilder);
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode)
            .pluginTypes("org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin"));

    // wait for yellow status
    runner.ensureYellow();
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:17,代碼來源:IndexingProxyPluginTest.java

示例8: 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

示例9: 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

示例10: cleanUpOnce

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
@BeforeClass
public static void cleanUpOnce() throws Exception {
    deleteDirectory("target/testcluster/");
    clusterName = "es-cl-run-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
        }
    }).build(
            newConfigs()
            .clusterName("testCluster")
            .numOfNode(3)
            .basePath("target/testcluster/")
            .useLogger());

    // wait for green status
    runner.ensureGreen();
    
    client = runner.client();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:26,代碼來源:ElasticsearchClusterBaseTest.java

示例11: applySettings

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
private Builder applySettings() {
    Builder settingsBuilder = Settings.builder();

    settingsBuilder.put("client.transport.ping_timeout", "15s");
    settingsBuilder.put("client.transport.nodes_sampler_interval", "5s");
    // YG: to ensure reliable connection & resolve NoNodeAvailableException
    settingsBuilder.put("client.transport.sniff", true);
    settingsBuilder.put("network.bind_host", 0);

    // YG: for supporting ES Auth with ES Shield
    Optional.ofNullable(config.getElastic().getAuth())
            .ifPresent(auth -> settingsBuilder.put("xpack.security.user", String.join(":", auth.getUser(), auth.getPwd())));

    if (Objects.nonNull(config.getElastic().getClusterName())) {
        settingsBuilder.put("cluster.name", config.getElastic().getClusterName());
    } else {
        settingsBuilder.put("client.transport.ignore_cluster_name", true);
    }
    return settingsBuilder;
}
 
開發者ID:ozlerhakan,項目名稱:mongolastic,代碼行數:21,代碼來源:ElasticConfiguration.java

示例12: setUp

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    clusterName = "es-analyzeapi-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode)
            .pluginTypes("org.codelibs.elasticsearch.analyze.AnalyzeApiPlugin,org.codelibs.elasticsearch.ja.JaPlugin"));

    // wait for yellow status
    runner.ensureYellow();
}
 
開發者ID:codelibs,項目名稱:elasticsearch-analyze-api,代碼行數:20,代碼來源:AnalyzeApiPluginTest.java

示例13: setUp

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    clusterName = "es-analysisja-" + System.currentTimeMillis();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.putList("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode)
            .pluginTypes("org.codelibs.elasticsearch.ja.JaPlugin,"
                    + "org.codelibs.elasticsearch.ja.kuromoji.plugin.analysis.kuromoji.AnalysisKuromojiPlugin"));

    userDictFiles = null;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-analysis-ja,代碼行數:18,代碼來源:JaPluginTest.java

示例14: setUp

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    clusterName = "es-langfield-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.putList("discovery.zen.ping.unicast.hosts",
                    "localhost:9301-9310");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(1).pluginTypes("org.codelibs.elasticsearch.langfield.LangFieldPlugin"));

    // wait for yellow status
    runner.ensureYellow();
}
 
開發者ID:codelibs,項目名稱:elasticsearch-langfield,代碼行數:20,代碼來源:LangFieldPluginTest.java

示例15: setUp

import org.elasticsearch.common.settings.Settings.Builder; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    clusterName = "es-kuromojineologd-" + System.currentTimeMillis();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.putList("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode)
            .pluginTypes("org.codelibs.elasticsearch.kuromoji.neologd.KuromojiNeologdPlugin"));

    userDictFiles = null;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-analysis-kuromoji-neologd,代碼行數:17,代碼來源:KuromojiNeologdPluginTest.java


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