use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project yyl_example by Relucent.
the class ElasticsearchTest method main.
public static void main(String[] args) throws Exception {
HttpHost[] hosts = { new HttpHost(HOST, PORT, SCHEME) };
try (RestClient client = RestClient.builder(hosts).build()) {
info(client);
catApi(client);
if (!existsIndices(client)) {
createIndex(client);
}
createDocument(client);
pause();
createDocumentPost(client);
pause();
getDocument(client);
pause();
queryByField(client);
pause();
deleteDocument(client);
pause();
queryAll(client);
pause();
deleteIndex(client);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project spring-boot by spring-projects.
the class ElasticsearchRestClientAutoConfigurationTests method configureUriWithUsernameAndEmptyPassword.
@Test
void configureUriWithUsernameAndEmptyPassword() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user:@localhost:9200").run((context) -> {
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString)).containsExactly("http://localhost:9200");
assertThat(client).extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class)).satisfies((credentialsProvider) -> {
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("localhost", 9200));
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
assertThat(credentials.getPassword()).isEmpty();
});
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project spring-boot by spring-projects.
the class ElasticsearchRestClientAutoConfigurationTests method configureUriWithUsernameOnly.
@Test
void configureUriWithUsernameOnly() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user@localhost:9200").run((context) -> {
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString)).containsExactly("http://localhost:9200");
assertThat(client).extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class)).satisfies((credentialsProvider) -> {
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("localhost", 9200));
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
assertThat(credentials.getPassword()).isNull();
});
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project spring-boot by spring-projects.
the class ElasticsearchRestClientAutoConfigurationTests method configureWhenBuilderCustomizerShouldApply.
@Test
void configureWhenBuilderCustomizerShouldApply() {
this.contextRunner.withUserConfiguration(BuilderCustomizerConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
org.elasticsearch.client.RestHighLevelClient restClient = context.getBean(org.elasticsearch.client.RestHighLevelClient.class);
RestClient lowLevelClient = restClient.getLowLevelClient();
assertThat(lowLevelClient).hasFieldOrPropertyWithValue("pathPrefix", "/test");
assertThat(lowLevelClient).extracting("client.connmgr.pool.maxTotal").isEqualTo(100);
assertThat(lowLevelClient).extracting("client.defaultConfig.cookieSpec").isEqualTo("rfc6265-lax");
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project graylog2-server by Graylog2.
the class FilteredElasticsearchNodesSniffer method create.
static FilteredElasticsearchNodesSniffer create(RestClient restClient, long sniffRequestTimeoutMillis, ElasticsearchNodesSniffer.Scheme scheme, String filter) {
final String attribute;
final String value;
if (!Strings.isNullOrEmpty(filter)) {
final String[] conditions = filter.split(":");
if (conditions.length < 2) {
throw new IllegalArgumentException("Invalid filter specified for ES node discovery: " + filter);
}
attribute = conditions[0].trim();
value = conditions[1].trim();
} else {
attribute = null;
value = null;
}
final NodesSniffer nodesSniffer = new ElasticsearchNodesSniffer(restClient, sniffRequestTimeoutMillis, scheme);
return new FilteredElasticsearchNodesSniffer(nodesSniffer, attribute, value);
}
Aggregations