org.elasticsearch.common.settings.Settings.builder()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(314)

本文整理了Java中org.elasticsearch.common.settings.Settings.builder()方法的一些代码示例,展示了Settings.builder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Settings.builder()方法的具体详情如下:
包路径:org.elasticsearch.common.settings.Settings
类名称:Settings
方法名:builder

Settings.builder介绍

[英]Returns a builder to be used in order to build settings.
[中]返回用于生成设置的生成器。

代码示例

代码示例来源:origin: alibaba/jstorm

Settings getSettings() {
 return Settings.builder().put("cluster.name", clusterName)
   .put(additionalConfiguration).build();
}

代码示例来源:origin: SonarSource/sonarqube

static Settings.Builder defaults() {
  Settings.Builder builder = Settings.builder()
   .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
   .put("index.refresh_interval", "30s")
   .put("index.mapper.dynamic", false);

  Arrays.stream(DefaultIndexSettingsElement.values())
   .map(DefaultIndexSettingsElement::settings)
   .forEach(builder::put);

  return builder;
 }
}

代码示例来源:origin: Netflix/conductor

private Settings getSettings(String clusterName, String host, int port) throws IOException {
  dataDir = Files.createTempDirectory(clusterName + "_" + System.currentTimeMillis() + "data").toFile();
  File homeDir = Files.createTempDirectory(clusterName + "_" + System.currentTimeMillis() + "-home").toFile();
  Settings.Builder settingsBuilder = Settings.builder()
      .put("cluster.name", clusterName)
      .put("http.host", host)
      .put("http.port", port)
      .put("transport.tcp.port", port + 100)
      .put(ElasticSearchConfiguration.EMBEDDED_DATA_PATH_DEFAULT_VALUE, dataDir.getAbsolutePath())
      .put(ElasticSearchConfiguration.EMBEDDED_HOME_PATH_DEFAULT_VALUE, homeDir.getAbsolutePath())
      .put("http.enabled", true)
      .put("script.inline", true)
      .put("script.stored", true)
      .put("node.data", true)
      .put("http.enabled", true)
      .put("http.type", "netty4")
      .put("transport.type", "netty4");
  return settingsBuilder.build();
}

代码示例来源:origin: SonarSource/sonarqube

private TransportClient buildTransportClient() {
 Settings.Builder esSettings = Settings.builder();
 // mandatory property defined by bootstrap process
 esSettings.put("cluster.name", clusterName);
 TransportClient nativeClient = new MinimalTransportClient(esSettings.build(), hostAndPorts);
 if (LOG.isDebugEnabled()) {
  LOG.debug("Connected to Elasticsearch node: [{}]", displayedAddresses(nativeClient));
 }
 return nativeClient;
}

代码示例来源:origin: floragunncom/search-guard

@Override
public Settings additionalSettings() {
  if(disabled) {
    return Settings.EMPTY;
  }
  final Settings.Builder builder = Settings.builder();
  builder.put(super.additionalSettings());
  if(!sslOnly){
   builder.put(NetworkModule.TRANSPORT_TYPE_KEY, "com.floragunn.searchguard.ssl.http.netty.SearchGuardSSLNettyTransport");
   builder.put(NetworkModule.HTTP_TYPE_KEY, "com.floragunn.searchguard.http.SearchGuardHttpServerTransport");
  }
  return builder.build();
}
@Override

代码示例来源:origin: apache/incubator-gobblin

private TransportClient createTransportClient(Config config) throws UnknownHostException {
  TransportClient transportClient;

  // Set TransportClient settings
  Settings.Builder settingsBuilder = Settings.builder();
  if (config.hasPath(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_SETTINGS)) {
   settingsBuilder.put(ConfigUtils.configToProperties(config,
       ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_SETTINGS));
  }
  settingsBuilder.put("client.transport.ignore_cluster_name",true);
  settingsBuilder.put("client.transport.sniff", true);
  transportClient = new PreBuiltTransportClient(settingsBuilder.build());
  this.hostAddresses.forEach(transportClient::addTransportAddress);
  return transportClient;
 }
}

代码示例来源:origin: apache/flink

@Override
public TransportClient createClient(Map<String, String> clientConfig) {
  Settings settings = Settings.builder().put(clientConfig)
    .put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
    .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
    .build();
  TransportClient transportClient = new PreBuiltTransportClient(settings);
  for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
    transportClient.addTransportAddress(transport);
  }
  // verify that we actually are connected to a cluster
  if (transportClient.connectedNodes().isEmpty()) {
    // close the transportClient here
    IOUtils.closeQuietly(transportClient);
    throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!");
  }
  if (LOG.isInfoEnabled()) {
    LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes());
  }
  return transportClient;
}

代码示例来源:origin: NLPchina/elasticsearch-sql

@Override
public Connection createPhysicalConnection(String url, Properties info) throws SQLException {
  if (client == null) {
    synchronized (this) {
      if (client == null) {
        Settings.Builder builder = Settings.builder();
        info.forEach((k, v) -> builder.put(k.toString(), v.toString()));
        String[] hostAndPortArray = url.split("/")[2].split(",");
        int length = hostAndPortArray.length;
        TransportAddress[] addresses = new TransportAddress[length];
        try {
          String[] hostAndPortArr;
          for (int i = 0; i < length; ++i) {
            hostAndPortArr = hostAndPortArray[i].split(":");
            addresses[i] = new TransportAddress(InetAddress.getByName(hostAndPortArr[0]), Integer.parseInt(hostAndPortArr[1]));
          }
        } catch (UnknownHostException e) {
          throw new SQLException(e);
        }
        client = new PreBuiltXPackTransportClient(builder.build()).addTransportAddresses(addresses);
      }
    }
  }
  Connection conn = new ElasticSearchConnection(client);
  createCount.incrementAndGet();
  return conn;
}

代码示例来源:origin: Netflix/conductor

@Override
  public Client get() {

    Settings settings = Settings.builder()
        .put("client.transport.ignore_cluster_name", true)
        .put("client.transport.sniff", true)
        .build();

    TransportClient tc = new PreBuiltTransportClient(settings);

    List<URI> clusterAddresses = configuration.getURIs();

    if (clusterAddresses.isEmpty()) {
      logger.warn(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME +
          " is not set.  Indexing will remain DISABLED.");
    }
    for (URI hostAddress : clusterAddresses) {
      int port = Optional.ofNullable(hostAddress.getPort()).orElse(9200);
      try {
        tc.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAddress.getHost()), port));
      } catch (UnknownHostException uhe){
        throw new ProvisionException("Invalid host" + hostAddress.getHost(), uhe);
      }
    }
    return tc;
  }
}

代码示例来源:origin: loklak/loklak_server

public void createIndexIfNotExists(String indexName, final int shards, final int replicas) {
  // create an index if not existent
  if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) {
    Settings.Builder settings = Settings.builder()
        .put("number_of_shards", shards)
        .put("number_of_replicas", replicas);
    this.elasticsearchClient.admin().indices().prepareCreate(indexName)
      .setSettings(settings)
      .setUpdateAllTypes(true)
      .execute().actionGet();
  } else {
    //LOGGER.debug("Index with name {} already exists", indexName);
  }
}

代码示例来源:origin: prestodb/presto

EmbeddedElasticsearchNode()
{
  try {
    elasticsearchDirectory = File.createTempFile("elasticsearch", "test");
    elasticsearchDirectory.delete();
    elasticsearchDirectory.mkdir();
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
  Settings setting = Settings.builder()
      .put("cluster.name", "test")
      .put("path.home", elasticsearchDirectory.getPath())
      .put("path.data", new File(elasticsearchDirectory, "data").getAbsolutePath())
      .put("path.logs", new File(elasticsearchDirectory, "logs").getAbsolutePath())
      .put("transport.type.default", "local")
      .put("transport.type", "netty4")
      .put("http.type", "netty4")
      .put("http.enabled", "true")
      .put("path.home", "elasticsearch-test-data")
      .build();
  node = new ElasticsearchNode(setting, ImmutableList.of(Netty4Plugin.class));
}

代码示例来源:origin: prestodb/presto

@Inject
public ElasticsearchClient(ElasticsearchTableDescriptionProvider descriptions, ElasticsearchConnectorConfig config)
    throws IOException
{
  tableDescriptions = requireNonNull(descriptions, "description is null");
  ElasticsearchConnectorConfig configuration = requireNonNull(config, "config is null");
  requestTimeout = configuration.getRequestTimeout();
  maxAttempts = configuration.getMaxRequestRetries();
  maxRetryTime = configuration.getMaxRetryTime();
  for (ElasticsearchTableDescription tableDescription : tableDescriptions.getAllTableDescriptions()) {
    if (!clients.containsKey(tableDescription.getClusterName())) {
      Settings settings = Settings.builder().put("cluster.name", tableDescription.getClusterName()).build();
      TransportAddress address = new TransportAddress(InetAddress.getByName(tableDescription.getHost()), tableDescription.getPort());
      TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(address);
      clients.put(tableDescription.getClusterName(), client);
    }
  }
  this.columnMetadataCache = CacheBuilder.newBuilder()
      .expireAfterWrite(30, MINUTES)
      .refreshAfterWrite(15, MINUTES)
      .maximumSize(500)
      .build(asyncReloading(CacheLoader.from(this::loadColumns), executor));
}

代码示例来源:origin: pentaho/pentaho-kettle

private void initClient() throws UnknownHostException {
 Settings.Builder settingsBuilder = Settings.builder();
 settingsBuilder.put( Settings.Builder.EMPTY_SETTINGS );
 meta.getSettingsMap().entrySet().stream().forEach( ( s ) -> settingsBuilder.put( s.getKey(),
     environmentSubstitute( s.getValue() ) ) );
 PreBuiltTransportClient tClient = new PreBuiltTransportClient( settingsBuilder.build() );
 for ( Server server : meta.getServers() ) {
  tClient.addTransportAddress( new TransportAddress(
      InetAddress.getByName( environmentSubstitute( server.getAddress() ) ),
      server.getPort() ) );
 }
 client = tClient;
 /** With the upgrade to elasticsearch 6.3.0, removed the NodeBuilder,
  *  which was removed from the elasticsearch 5.0 API, see:
  *  https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_java_api_changes
  *  .html#_nodebuilder_removed
  */
}

代码示例来源:origin: floragunncom/search-guard

private static Settings checkAndAddNodeName(final Settings settings) {
    if(!settings.hasValue("node.name")) {
      return Settings.builder().put(settings).put("node.name", "auto_node_name_"+System.currentTimeMillis()+"_"+ new Random().nextInt()).build();
    }
    
    return settings;
    
  }
}

代码示例来源:origin: loklak/loklak_server

/**
 * create a elasticsearch transport client (remote elasticsearch)
 * @param addresses an array of host:port addresses
 * @param clusterName
 */
public ElasticsearchClient(final String[] addresses, final String clusterName) {
  // create default settings and add cluster name
  Settings.Builder settings = Settings.builder()
      .put("cluster.name", clusterName)
      .put("cluster.routing.allocation.enable", "all")
      .put("cluster.routing.allocation.allow_rebalance", "true");
  // create a client
  TransportClient tc = TransportClient.builder()
      .settings(settings.build())
      .build();
  for (String address: addresses) {
    String a = address.trim();
    int p = a.indexOf(':');
    if (p >= 0) try {
      InetAddress i = InetAddress.getByName(a.substring(0, p));
      int port = Integer.parseInt(a.substring(p + 1));
      tc.addTransportAddress(new InetSocketTransportAddress(i, port));
    } catch (UnknownHostException e) {
      DAO.severe(e);
    }
  }
  this.elasticsearchClient = tc;
}

代码示例来源:origin: alibaba/canal

Settings.Builder settingBuilder = Settings.builder();
properties.forEach(settingBuilder::put);
Settings settings = settingBuilder.build();
transportClient = new PreBuiltTransportClient(settings);
String[] hostArray = configuration.getHosts().split(",");

代码示例来源:origin: prestodb/presto

public ElasticsearchQueryBuilder(List<ElasticsearchColumnHandle> columnHandles, ElasticsearchConnectorConfig config, ElasticsearchSplit split)
{
  requireNonNull(columnHandles, "columnHandles is null");
  requireNonNull(config, "config is null");
  requireNonNull(split, "split is null");
  columns = columnHandles;
  tupleDomain = split.getTupleDomain();
  index = split.getIndex();
  shard = split.getShard();
  type = split.getType();
  Settings settings = Settings.builder()
      .put("client.transport.ignore_cluster_name", true)
      .build();
  try {
    InetAddress address = InetAddress.getByName(split.getSearchNode());
    client = new PreBuiltTransportClient(settings)
        .addTransportAddress(new TransportAddress(address, split.getPort()));
  }
  catch (UnknownHostException e) {
    throw new PrestoException(ELASTICSEARCH_CONNECTION_ERROR, format("Error connecting to search node (%s:%d)", split.getSearchNode(), split.getPort()), e);
  }
  scrollTimeout = config.getScrollTimeout();
  scrollSize = config.getScrollSize();
}

代码示例来源:origin: floragunncom/search-guard

private Settings.Builder getMinimumNonSgNodeSettingsBuilder(final int nodenum, final boolean masterNode,
    final boolean dataNode, final boolean tribeNode, int nodeCount, int masterCount, SortedSet<Integer> tcpPorts, int tcpPort, int httpPort) {
  return Settings.builder()
      .put("node.name", "node_"+clustername+ "_num" + nodenum)
      .put("node.data", dataNode)
      .put("node.master", masterNode)
      .put("cluster.name", clustername)
      .put("path.data", "data/"+clustername+"/data")
      .put("path.logs", "data/"+clustername+"/logs")
      .put("node.max_local_storage_nodes", nodeCount)
      .put("discovery.zen.minimum_master_nodes", minMasterNodes(masterCount))
      .put("discovery.zen.no_master_block", "all")
      .put("discovery.zen.fd.ping_timeout", "5s")
      .put("discovery.initial_state_timeout","8s")
      .putList("discovery.zen.ping.unicast.hosts", tcpPorts.stream().map(s->"127.0.0.1:"+s).collect(Collectors.toList()))
      .put("transport.tcp.port", tcpPort)
      .put("http.port", httpPort)
      .put("http.enabled", true)
      .put("cluster.routing.allocation.disk.threshold_enabled", false)
      .put("http.cors.enabled", true)
      .put("path.home", ".");
}
// @formatter:on

代码示例来源:origin: brianfrankcooper/YCSB

final Builder settings = Settings.builder().put("cluster.name", DEFAULT_CLUSTER_NAME);
  final String key = (String) e.getKey();
  if (key.startsWith("es.setting.")) {
   settings.put(key.substring("es.setting.".length()), e.getValue());
settings.put("client.transport.sniff", true)
    .put("client.transport.ignore_cluster_name", false)
    .put("client.transport.ping_timeout", "30s")
client = new PreBuiltTransportClient(settings.build());
for (String h : nodeList) {
 String[] nodes = h.split(":");
   new CreateIndexRequest(indexKey)
     .settings(
       Settings.builder()
         .put("index.number_of_shards", numberOfShards)
         .put("index.number_of_replicas", numberOfReplicas)

代码示例来源:origin: floragunncom/search-guard

private Settings crossClusterNodeSettings(ClusterInfo remote) {
  Settings.Builder builder = Settings.builder()
      .putList("search.remote.cross_cluster_two.seeds", remote.nodeHost+":"+remote.nodePort);
  return builder.build();
}

相关文章