Skip to content

Commit c79525b

Browse files
author
Batuhan Apaydın
committed
changes about elasticsearch and operations
1 parent 65db21f commit c79525b

File tree

4 files changed

+51
-74
lines changed

4 files changed

+51
-74
lines changed

pom.xml

+46-61
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,51 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
6-
<groupId>com.spring.data.com.elastic.data.elastic</groupId>
7-
<artifactId>spring-data-elasticsearch</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
<packaging>jar</packaging>
10-
11-
<name>spring-data-elasticsearch</name>
12-
<description>Demo project for Spring Boot using Spring Data ElasticSearch</description>
13-
14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.0.0.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
19-
</parent>
20-
21-
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
25-
</properties>
26-
27-
<dependencies>
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
31-
</dependency>
32-
33-
<dependency>
34-
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-starter-test</artifactId>
36-
<scope>test</scope>
37-
</dependency>
38-
39-
<dependency>
40-
<groupId>org.elasticsearch.client</groupId>
41-
<artifactId>transport</artifactId>
42-
<version>5.0.0</version>
43-
</dependency>
44-
<dependency>
45-
<groupId>org.apache.logging.log4j</groupId>
46-
<artifactId>log4j-to-slf4j</artifactId>
47-
<version>2.7</version>
48-
</dependency>
49-
<dependency>
50-
<groupId>ch.qos.logback</groupId>
51-
<artifactId>logback-classic</artifactId>
52-
<version>1.1.7</version>
53-
</dependency>
54-
</dependencies>
55-
56-
<build>
57-
<plugins>
58-
<plugin>
59-
<groupId>org.springframework.boot</groupId>
60-
<artifactId>spring-boot-maven-plugin</artifactId>
61-
</plugin>
62-
</plugins>
63-
</build>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.spring.data.com.elastic.data.elastic</groupId>
7+
<artifactId>spring-data-elasticsearch</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-data-elasticsearch</name>
12+
<description>Demo project for Spring Boot using Spring Data ElasticSearch</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.0.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-maven-plugin</artifactId>
46+
</plugin>
47+
</plugins>
48+
</build>
6449

6550

6651
</project>

src/main/java/com/elastic/data/boot/ApplicationRunner.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.elastic.data.document.Book;
44
import com.elastic.data.elastic.data.service.BookService;
5-
import org.elasticsearch.client.Client;
65
import org.springframework.boot.CommandLineRunner;
76
import org.springframework.data.domain.Page;
87
import org.springframework.data.domain.PageRequest;
@@ -13,8 +12,8 @@
1312
@Component
1413
public class ApplicationRunner implements CommandLineRunner {
1514

16-
private BookService bookService;
17-
private ElasticsearchOperations elasticsearchOperations;
15+
private final BookService bookService;
16+
private final ElasticsearchOperations elasticsearchOperations;
1817

1918
public ApplicationRunner(BookService bookService, ElasticsearchOperations elasticsearchOperations) {
2019
this.bookService = bookService;
@@ -29,16 +28,8 @@ public void run(String... args) {
2928

3029
elasticsearchOperations.refresh(Book.class);
3130

32-
System.out.println("Settings about Elastic Search");
33-
Client client = elasticsearchOperations.getClient();
34-
client
35-
.settings()
36-
.getAsMap()
37-
.forEach((key, value) -> System.out.println(String.format("Key : %s Value: %s", key, value)));
38-
System.out.println("End Information");
3931

40-
41-
bookService.save(new Book("1001", "Elasticsearch Basics", "Rambabu Posa", "23-FEB-2017"));
32+
Book saved = bookService.save(new Book(null, "Elasticsearch Basics", "Rambabu Posa", "23-FEB-2017"));
4233
bookService.save(new Book("1002", "Apache Lucene Basics", "Rambabu Posa", "13-MAR-2017"));
4334
bookService.save(new Book("1003", "Apache Solr Basics", "Rambabu Posa", "21-MAR-2017"));
4435

src/main/java/com/elastic/data/document/Book.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.util.Objects;
88

9-
@Document(indexName = "devquy", type = "books")
9+
@Document(indexName = "book", type = "books")
1010
public class Book {
1111

1212
@Id

src/test/java/com/elastic/data/elastic/data/service/BookServiceTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void should_field_equals_after_save_operation_success() {
5151
Book book = new Book("1001", "Elasticsearch Basics", "Rambabu Posa", "23-FEB-2017");
5252
//when
5353
when(bookRepository.save(book)).thenReturn(book);
54+
5455
Book testBook = bookService.save(book);
5556
//then
5657
assertThat(book.getId()).isEqualTo(testBook.getId());

0 commit comments

Comments
 (0)