org.springframework.data.elasticsearch.client.RestClients Java Examples

The following examples show how to use org.springframework.data.elasticsearch.client.RestClients. 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: SearchConfig.java    From openvsx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RestHighLevelClient elasticsearchClient() {
    ClientConfiguration config;
    if (Strings.isNullOrEmpty(searchHost)) {
        config = ClientConfiguration.localhost();
    } else {
        config = ClientConfiguration.create(searchHost);
    }
    return RestClients.create(config).rest();
}
 
Example #2
Source File: ApplicationConfiguration.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void insertDataSample() {

	try {
		RestClients.create(ClientConfiguration.localhost()).rest().indices()
				.create(new CreateIndexRequest("conference-index"), RequestOptions.DEFAULT);
	} catch (IOException | ElasticsearchStatusException e) {
		// just ignore it
	}

	// Remove all documents
	repository.deleteAll().subscribe();

	// Save data sample
	repository
			.save(Conference.builder().date("2014-11-06").name("Spring eXchange 2014 - London")
					.keywords(Arrays.asList("java", "spring")).location(new GeoPoint(51.500152D, -0.126236D)).build())
			.then().as(StepVerifier::create).verifyComplete();
	repository
			.save(Conference.builder().date("2014-12-07").name("Scala eXchange 2014 - London")
					.keywords(Arrays.asList("scala", "play", "java")).location(new GeoPoint(51.500152D, -0.126236D)).build())
			.then().as(StepVerifier::create).verifyComplete();
	repository.save(Conference.builder().date("2014-11-20").name("Elasticsearch 2014 - Berlin")
			.keywords(Arrays.asList("java", "elasticsearch", "kibana")).location(new GeoPoint(52.5234051D, 13.4113999))
			.build()).then().as(StepVerifier::create).verifyComplete();
	repository.save(Conference.builder().date("2014-11-12").name("AWS London 2014")
			.keywords(Arrays.asList("cloud", "aws")).location(new GeoPoint(51.500152D, -0.126236D)).build()).then()
			.as(StepVerifier::create).verifyComplete();
	repository.save(Conference.builder().date("2014-10-04").name("JDD14 - Cracow")
			.keywords(Arrays.asList("java", "spring")).location(new GeoPoint(50.0646501D, 19.9449799)).build()).then()
			.as(StepVerifier::create).verifyComplete();
}
 
Example #3
Source File: Config.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
RestHighLevelClient client() {
    ClientConfiguration clientConfiguration = ClientConfiguration.builder()
        .connectedTo("localhost:9200")
        .build();

    return RestClients.create(clientConfiguration)
        .rest();
}
 
Example #4
Source File: ElasticSearchManualTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setUp() throws UnknownHostException {
    Person person1 = new Person(10, "John Doe", new Date());
    Person person2 = new Person(25, "Janette Doe", new Date());
    listOfPersons.add(person1);
    listOfPersons.add(person2);

    ClientConfiguration clientConfiguration = ClientConfiguration.builder()
        .connectedTo("localhost:9200")
        .build();
    client = RestClients.create(clientConfiguration)
        .rest();
}