org.elasticsearch.common.settings.ImmutableSettings Java Examples

The following examples show how to use org.elasticsearch.common.settings.ImmutableSettings. 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: ElasticSearchConfiguration.java    From Decision with Apache License 2.0 6 votes vote down vote up
@Bean
public Client elasticsearchClient(){

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("client.transport.ignore_cluster_name", true)
            .put("cluster.name", "elasticsearch")
            .build();
    TransportClient tc = new TransportClient(settings);

    for (String elasticSearchHost : configurationContext.getElasticSearchHosts()) {
        String[] elements = elasticSearchHost.split(":");
        tc.addTransportAddress(new InetSocketTransportAddress(elements[0], Integer.parseInt(elements[1])));
    }


    log.debug("Creating Spring Bean for elasticsearchClient");

    return  tc;

}
 
Example #2
Source File: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * インデックスを作成する.
 * @param index インデックス名
 * @param mappings マッピング情報
 * @return 非同期応答
 */
public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) {
    this.fireEvent(Event.creatingIndex, index);
    CreateIndexRequestBuilder cirb =
            new CreateIndexRequestBuilder(esTransportClient.admin().indices()).setIndex(index);

    // cjkアナライザ設定
    ImmutableSettings.Builder indexSettings = ImmutableSettings.settingsBuilder();
    indexSettings.put("analysis.analyzer.default.type", "cjk");
    cirb.setSettings(indexSettings);

    if (mappings != null) {
        for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) {
            cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString());
        }
    }
    return cirb.execute();
}
 
Example #3
Source File: ElasticSearchClient.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public Client start() {
    transportPort = elasticSearchFig.getTransportPort();
    httpPort = elasticSearchFig.getHttpPort();
    host = elasticSearchFig.getTransportHost();
    clusterName = elasticSearchFig.getClusterName();

    Settings settings = ImmutableSettings.settingsBuilder().put( "cluster.name", clusterName ).build();
    LOG.info( "Connecting Elasticsearch on {}", elasticSearchFig.getTransportHost() + ":" +
            elasticSearchFig.getTransportPort() );
    nodeList = getNodeList();
    TransportClient transportClient = new TransportClient( settings );
    for ( ElasticSearchNode elasticSearchNode : nodeList ) {
        LOG.debug( "Adding transport address with host {} and port {}", elasticSearchNode.getTransportHost()
                , elasticSearchNode.getTransportPort() );
        transportClient.addTransportAddress( new InetSocketTransportAddress( elasticSearchNode.getTransportHost(),
                elasticSearchNode.getTransportPort() ) );
    }

    client = transportClient;
    return client;
}
 
Example #4
Source File: EsRetryTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * テストケース共通の初期化処理. テスト用のElasticsearchのNodeを初期化する
 * @throws Exception 異常が発生した場合の例外
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    Settings settings = ImmutableSettings.settingsBuilder()
            // .put("node.http.enabled", false)
            .put("cluster.name", TESTING_CLUSTER)
            .put("node.name", "node1")
            .put("gateway.type", "none")
            .put("action.auto_create_index", "false")
            .put("index.store.type", "memory")
            .put("index.number_of_shards", 1)
            .put("index.number_of_replicas", 0)
            .put("transport.tcp.port", "9399")
            .build();
    node = NodeBuilder.nodeBuilder().settings(settings).node();

    esClient = new EsClient(TESTING_CLUSTER, TESTING_HOSTS);
}
 
Example #5
Source File: ElasticsearchContainer.java    From logstash with Apache License 2.0 6 votes vote down vote up
public Client createClient() {
    final AtomicReference<Client> elasticsearchClient = new AtomicReference<>();
    await().atMost(30, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
        Client c = new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", elasticsearchClusterName).build()).addTransportAddress(new InetSocketTransportAddress(getIpAddress(), 9300));
        try {
            c.admin().cluster().health(Requests.clusterHealthRequest("_all")).actionGet();
        } catch (ElasticsearchException e) {
            c.close();
            return false;
        }
        elasticsearchClient.set(c);
        return true;
    });
    assertEquals(elasticsearchClusterName, elasticsearchClient.get().admin().cluster().health(Requests.clusterHealthRequest("_all")).actionGet().getClusterName());
    return elasticsearchClient.get();
}
 
Example #6
Source File: DefaultClientFactory.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
protected ShellNativeClient newTransportClient(TransportAddress... addresses) {

        Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", true).build();
        org.elasticsearch.client.transport.TransportClient client = new TransportClient(settings).addTransportAddresses(addresses);

        //if no connected node we can already close the (useless) client
        if (client.connectedNodes().size() == 0) {
            client.close();
            return null;
        }

        AbstractClient<TransportClient, JsonInput, JsonOutput> shellClient = clientWrapper.wrapEsTransportClient(client);
        resourceRegistry.registerResource(shellClient);
        ShellNativeClient shellNativeClient = clientWrapper.wrapShellClient(shellClient);
        clientScopeSynchronizerRunner.startSynchronizer(shellNativeClient);
        return shellNativeClient;
    }
 
Example #7
Source File: SrvDiscoveryIntegrationTest.java    From elasticsearch-srv-discovery with MIT License 6 votes vote down vote up
@Test
public void testClusterSrvDiscoveryWith5Nodes() throws Exception {
    ImmutableSettings.Builder b = settingsBuilder()
        .put("node.mode", "network")
        .put("discovery.zen.ping.multicast.enabled", "false")
        .put("discovery.type", "srvtest")
        .put(SrvUnicastHostsProvider.DISCOVERY_SRV_QUERY, Constants.TEST_QUERY);

    assertEquals(cluster().size(), 0);

    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_0_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_1_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_2_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_3_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_4_TRANSPORT_TCP_PORT)).build());

    assertEquals(cluster().size(), 5);
}
 
Example #8
Source File: AbstractEsSink.java    From test-data-generator with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Map<String, String> props) {
    String host = props.get(PropConst.HOST);
    if (host == null) {
        throw new IllegalArgumentException("Host does not specified");
    }
    String port = props.get(PropConst.PORT);
    if (port == null) {
        throw new IllegalArgumentException("Port does not specified");
    }
    String clusterName = props.get(PropConst.CLUSTER_NAME);
    if (clusterName == null) {
        throw new IllegalArgumentException("Cluster name does not specified");
    }
    client = (new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build()))
            .addTransportAddress(new InetSocketTransportAddress(host, Integer.valueOf(port)));
}
 
Example #9
Source File: IkESPluginTest.java    From es-ik with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultsIcuAnalysis() {
    Index index = new Index("test");

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("path.home", "none")
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, settings),
            new IndexNameModule(index),
            new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor()))
            .createChildInjector(parentInjector);

    AnalysisService analysisService = injector.getInstance(AnalysisService.class);

    TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer");
    MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class));


}
 
Example #10
Source File: ElasticSearchIndex.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * If ES already contains this instance's target index, then do nothing.
 * Otherwise, create the index, then wait {@link #CREATE_SLEEP}.
 * <p>
 * The {@code client} field must point to a live, connected client.
 * The {@code indexName} field must be non-null and point to the name
 * of the index to check for existence or create.
 *
 * @param config the config for this ElasticSearchIndex
 * @throws java.lang.IllegalArgumentException if the index could not be created
 */
private void checkForOrCreateIndex(Configuration config) {
    Preconditions.checkState(null != client);

    //Create index if it does not already exist
    IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
    if (!response.isExists()) {

        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();

        ElasticSearchSetup.applySettingsFromTitanConf(settings, config, ES_CREATE_EXTRAS_NS);

        CreateIndexResponse create = client.admin().indices().prepareCreate(indexName)
                .setSettings(settings.build()).execute().actionGet();
        try {
            final long sleep = config.get(CREATE_SLEEP);
            log.debug("Sleeping {} ms after {} index creation returned from actionGet()", sleep, indexName);
            Thread.sleep(sleep);
        } catch (InterruptedException e) {
            throw new TitanException("Interrupted while waiting for index to settle in", e);
        }
        if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName);
    }
}
 
Example #11
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * テストケース共通の初期化処理. テスト用のElasticsearchのNodeを初期化する
 * @throws Exception 異常が発生した場合の例外
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    Settings settings = ImmutableSettings.settingsBuilder()
            .put("node.http.enabled", true)
            .put("cluster.name", TESTING_CLUSTER)
            .put("node.name", "node1")
            .put("gateway.type", "none")
            .put("action.auto_create_index", "false")
            .put("index.store.type", "memory")
            .put("index.number_of_shards", 1)
            .put("index.number_of_replicas", 0)
            .put("transport.tcp.port", "9399")
            .build();
    node = NodeBuilder.nodeBuilder().settings(settings).node();

    esClient = new EsClient(TESTING_CLUSTER, TESTING_HOSTS);
}
 
Example #12
Source File: StoreLocalClientProvider.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
protected Settings buildNodeSettings() {
    // Build settings
    ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
            .put("node.name", "node-test-" + System.currentTimeMillis())
            .put("node.data", true)
            .put("cluster.name", "cluster-test-" + NetworkUtils.getLocalAddress().getHostName())
            .put("path.data", "./target/elasticsearch-test/data")
            .put("path.work", "./target/elasticsearch-test/work")
            .put("path.logs", "./target/elasticsearch-test/logs")
            .put("index.number_of_shards", "1")
            .put("index.number_of_replicas", "0")
            .put("cluster.routing.schedule", "50ms")
            .put("node.local", true);

    if (settings != null) {
        builder.put(settings);
    }

    return builder.build();
}
 
Example #13
Source File: EsRetryTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * テストケース共通の初期化処理. テスト用のElasticsearchのNodeを初期化する
 * @throws Exception 異常が発生した場合の例外
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    Settings settings = ImmutableSettings.settingsBuilder()
            // .put("node.http.enabled", false)
            .put("cluster.name", TESTING_CLUSTER)
            .put("node.name", "node1")
            .put("gateway.type", "none")
            .put("action.auto_create_index", "false")
            .put("index.store.type", "memory")
            .put("index.number_of_shards", 1)
            .put("index.number_of_replicas", 0)
            .put("transport.tcp.port", "9399")
            .build();
    node = NodeBuilder.nodeBuilder().settings(settings).node();

    esClient = new EsClient(TESTING_CLUSTER, TESTING_HOSTS);
}
 
Example #14
Source File: KafkaRiverConfigTest.java    From elasticsearch-river-kafka with Apache License 2.0 6 votes vote down vote up
public void testDefaults()
{
	Map<String, Object> map = new HashMap<>();		
	RiverSettings settings = new RiverSettings(
		ImmutableSettings.settingsBuilder().build(), 
		map);
	KafkaRiverConfig c = new KafkaRiverConfig(settings);
	
	assertEquals("localhost", c.brokerHost);
	assertEquals(9092, c.brokerPort);
	assertEquals("localhost", c.zookeeper);
	assertEquals(10485760, c.bulkSize);
	assertEquals(0, c.partition);
	assertEquals("default_topic", c.topic);
	assertEquals(10000, c.bulkTimeout.millis());
	
	assertEquals("org.elasticsearch.river.kafka.JsonMessageHandlerFactory", c.factoryClass);
	
	assertEquals(-1, c.statsdPort);
	assertNull(c.statsdHost);
	assertNull(c.statsdPrefix);
	
}
 
Example #15
Source File: AbstractElasticSearchSinkTest.java    From ingestion with Apache License 2.0 6 votes vote down vote up
void createNodes() throws Exception {
  Settings settings = ImmutableSettings
      .settingsBuilder()
      .put("number_of_shards", 1)
      .put("number_of_replicas", 0)
      .put("routing.hash.type", "simple")
      .put("gateway.type", "none")
      .put("path.data", "target/es-test")
      .build();

  node = NodeBuilder.nodeBuilder().settings(settings).local(true).node();
  client = node.client();

  client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute()
      .actionGet();
}
 
Example #16
Source File: ElasticsearchEmitter.java    From amazon-kinesis-connectors with Apache License 2.0 6 votes vote down vote up
public ElasticsearchEmitter(KinesisConnectorConfiguration configuration) {
    Settings settings =
            ImmutableSettings.settingsBuilder()
                    .put(ELASTICSEARCH_CLUSTER_NAME_KEY, configuration.ELASTICSEARCH_CLUSTER_NAME)
                    .put(ELASTICSEARCH_CLIENT_TRANSPORT_SNIFF_KEY, configuration.ELASTICSEARCH_TRANSPORT_SNIFF)
                    .put(ELASTICSEARCH_CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME_KEY,
                            configuration.ELASTICSEARCH_IGNORE_CLUSTER_NAME)
                    .put(ELASTICSEARCH_CLIENT_TRANSPORT_PING_TIMEOUT_KEY, configuration.ELASTICSEARCH_PING_TIMEOUT)
                    .put(ELASTICSEARCH_CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL_KEY,
                            configuration.ELASTICSEARCH_NODE_SAMPLER_INTERVAL)
                    .build();
    elasticsearchEndpoint = configuration.ELASTICSEARCH_ENDPOINT;
    elasticsearchPort = configuration.ELASTICSEARCH_PORT;
    LOG.info("ElasticsearchEmitter using elasticsearch endpoint " + elasticsearchEndpoint + ":" + elasticsearchPort);
    elasticsearchClient = new TransportClient(settings);
    elasticsearchClient.addTransportAddress(new InetSocketTransportAddress(elasticsearchEndpoint, elasticsearchPort));
}
 
Example #17
Source File: ElasticSearchTransportClient.java    From ingestion with Apache License 2.0 6 votes vote down vote up
/**
 * Open client to elaticsearch cluster
 * 
 * @param clusterName
 */
private void openClient(String clusterName) {
  logger.info("Using ElasticSearch hostnames: {} ",
      Arrays.toString(serverAddresses));
  Settings settings = ImmutableSettings.settingsBuilder()
      .put("cluster.name", clusterName).build();

  TransportClient transportClient = new TransportClient(settings);
  for (InetSocketTransportAddress host : serverAddresses) {
    transportClient.addTransportAddress(host);
  }
  if (client != null) {
    client.close();
  }
  client = transportClient;
}
 
Example #18
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop1OneShard() {
    client.admin().indices().prepareCreate("topk-0").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    client.prepareIndex("topk-0", "type0", "doc0").setSource("field0", "foo").execute().actionGet();
    client.prepareIndex("topk-0", "type0", "doc1").setSource("field0", "foo").execute().actionGet();
    client.prepareIndex("topk-0", "type0", "doc2").setSource("field0", "bar").setRefresh(true).execute().actionGet();
   
    SearchResponse searchResponse = client.prepareSearch("topk-0")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(1))
            .execute().actionGet();
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(1, buckets.size());
    assertEquals("foo", buckets.get(0).getKey());
    assertEquals(2, buckets.get(0).getDocCount());
}
 
Example #19
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop1BooleanOneShard() {
    client.admin().indices().prepareCreate("topk-0b").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    client.prepareIndex("topk-0b", "type0", "doc0").setSource("field0", true).execute().actionGet();
    client.prepareIndex("topk-0b", "type0", "doc1").setSource("field0", true).execute().actionGet();
    client.prepareIndex("topk-0b", "type0", "doc2").setSource("field0", false).setRefresh(true).execute().actionGet();
   
    SearchResponse searchResponse = client.prepareSearch("topk-0b")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(1))
            .execute().actionGet();
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(1, buckets.size());
    assertEquals("T", buckets.get(0).getKey());
    assertEquals(2, buckets.get(0).getDocCount());
}
 
Example #20
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop10of3OneShard() {
    client.admin().indices().prepareCreate("topk-1").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    client.prepareIndex("topk-1", "type0", "doc0").setSource("field0", "foo").execute().actionGet();
    client.prepareIndex("topk-1", "type0", "doc1").setSource("field0", "foo").execute().actionGet();
    client.prepareIndex("topk-1", "type0", "doc2").setSource("field0", "bar").setRefresh(true).execute().actionGet();
   
    SearchResponse searchResponse = client.prepareSearch("topk-1")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10))
            .execute().actionGet();
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(2, buckets.size());
    assertEquals("foo", buckets.get(0).getKey());
    assertEquals(2, buckets.get(0).getDocCount());
    assertEquals("bar", buckets.get(1).getKey());
    assertEquals(1, buckets.get(1).getDocCount());
}
 
Example #21
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop10of50OneShard() {
    client.admin().indices().prepareCreate("topk-2").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    for (int i = 0; i < 50; ++i) { // 50 values
        client.prepareIndex("topk-2", "type0", "doc" + i).setSource("field0", "foo" + i).execute().actionGet();
    }
    client.prepareIndex("topk-2", "type0", "doc50").setSource("field0", "foo0").setRefresh(true).execute().actionGet(); // foo0 twice
   
    SearchResponse searchResponse = client.prepareSearch("topk-2")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10))
            .execute().actionGet();
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(10, buckets.size());
    assertEquals("foo0", buckets.get(0).getKey());
    assertEquals(2, buckets.get(0).getDocCount());
    for (int i = 1; i < 10; ++i) {
        assertEquals(1, buckets.get(i).getDocCount());
    }
}
 
Example #22
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop10of50TwoShard() {
    client.admin().indices().prepareCreate("topk-3").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2)).execute().actionGet();
    
    for (int i = 0; i < 50; ++i) { // 50 values
        client.prepareIndex("topk-3", "type0", "doc" + i).setSource("field0", "foo" + i).setRefresh(true).execute().actionGet();
    }
    for (int i = 50; i < 100; ++i) { // 50 same values
        client.prepareIndex("topk-3", "type0", "doc" + i).setSource("field0", "foo0").setRefresh(true).execute().actionGet();
    }
   
    SearchResponse searchResponse = client.prepareSearch("topk-3")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10))
            .execute().actionGet();
    assertEquals(100, searchResponse.getHits().getTotalHits());
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(10, buckets.size());
    assertEquals("foo0", buckets.get(0).getKey());
    assertEquals(51, buckets.get(0).getDocCount());
}
 
Example #23
Source File: DocTest.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    if (interp == null) {
        resetInterpreter();
    }
    Settings s1 = ImmutableSettings.settingsBuilder()
            .put("cluster.name", "a")
            .put("node.local", false)
            .build();

    esSetup = new StoreEsSetup(s1);
    esSetup.execute(deleteAll(), createIndex("users").withSettings(
            fromClassPath("essetup/settings/test_a.json")).withMapping("d",
            fromClassPath("essetup/mappings/test_a.json")).withData(
            fromClassPath("essetup/data/test_a.json")));
    esSetup.client().admin().indices().prepareRefresh("users").execute().actionGet();

    Settings s2 = ImmutableSettings.settingsBuilder()
            .put("cluster.name", "b")
            .put("node.local", false)
            .build();
    esSetup2 = new StoreEsSetup(s2);
    esSetup2.execute(deleteAll());
}
 
Example #24
Source File: ESJavaRDDFT.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
@BeforeSuite
public static void init() throws IOException, ExecutionException, InterruptedException, ParseException {

    File file = new File(DB_FOLDER_NAME);
    FileUtils.deleteDirectory(file);

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("path.logs", "")
            .put("path.data", DB_FOLDER_NAME)
            .build();

    node = nodeBuilder().settings(settings).data(true).local(true).clusterName(HOST).node();
    client = node.client();

    LOG.info("Started local node at " + DB_FOLDER_NAME + " settings " + node.settings().getAsMap());

}
 
Example #25
Source File: AbstractElasticSearchSinkTest.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
void createNodes() throws Exception {
  Settings settings = ImmutableSettings
      .settingsBuilder()
      .put("number_of_shards", 1)
      .put("number_of_replicas", 0)
      .put("routing.hash.type", "simple")
      .put("gateway.type", "none")
      .put("path.data", "target/es-test")
      .build();

  node = NodeBuilder.nodeBuilder().settings(settings).local(true).node();
  client = node.client();

  client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute()
      .actionGet();
}
 
Example #26
Source File: SearchClientServiceImpl.java    From searchanalytics-bigdata with MIT License 6 votes vote down vote up
protected Client createClient() {
	if (client == null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Creating client for Search!");
		}
		// Try starting search client at context loading
		try {
			final Settings settings = ImmutableSettings
					.settingsBuilder()
					.put(ElasticSearchReservedWords.CLUSTER_NAME.getText(),
							searchServerClusterName).build();
			TransportClient transportClient = new TransportClient(settings);
			transportClient = transportClient
					.addTransportAddress(new InetSocketTransportAddress(
							"localhost", 9300));
			if (transportClient.connectedNodes().size() == 0) {
				logger.error("There are no active nodes available for the transport, it will be automatically added once nodes are live!");
			}
			client = transportClient;
		} catch (final Exception ex) {
			// ignore any exception, dont want to stop context loading
			logger.error("Error occured while creating search client!", ex);
		}
	}
	return client;
}
 
Example #27
Source File: TransportClient.java    From elasticsearch-jest-example with MIT License 6 votes vote down vote up
/**
	 * 创建TransportClient
	 * @return
	 */
	private static Client createTransportClient() {
		//创建settings
		Settings settings = ImmutableSettings.settingsBuilder()
			.put("cluster.name", "elasticsearch")//设置集群名称
//		    .put("shield.user", "admin:sysadmin")
			.build();
		Client client = null;
		try {
			client = new org.elasticsearch.client.transport.TransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return client;
	}
 
Example #28
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void assertTop1NumericalOneShard() {
    client.admin().indices().prepareCreate("topk-0n").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    client.prepareIndex("topk-0n", "type0", "doc0").setSource("field0", 42).execute().actionGet();
    client.prepareIndex("topk-0n", "type0", "doc1").setSource("field0", 42).execute().actionGet();
    client.prepareIndex("topk-0n", "type0", "doc2").setSource("field0", 51).setRefresh(true).execute().actionGet();
   
    SearchResponse searchResponse = client.prepareSearch("topk-0n")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(1))
            .execute().actionGet();
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(1, buckets.size());
    assertEquals("42", buckets.get(0).getKey());
    assertEquals(2, buckets.get(0).getDocCount());
}
 
Example #29
Source File: TestElasticSearchSink.java    From suro with Apache License 2.0 5 votes vote down vote up
@Override
protected Settings nodeSettings(int nodeOrdinal) {
    return ImmutableSettings.settingsBuilder()
        .put("index.number_of_shards", 1)
        .put("index.number_of_replicas", 1)
        .put(super.nodeSettings(nodeOrdinal)).build();
}
 
Example #30
Source File: OLSOntologyUpdateIntegrationTests.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
protected Settings nodeSettings(int nodeOrdinal) {
	return ImmutableSettings.builder()
			.put(super.nodeSettings(nodeOrdinal))
			.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true)
			.build();
}