-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf($starter): integrate with spring-boot-starter-data-elasticsearch
- Loading branch information
1 parent
c1a57db
commit 0f4dff5
Showing
14 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/elasticsearch/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.jmsoftware.maf.springcloudstarter.elasticsearch; | ||
|
||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.elasticsearch.annotations.Document; | ||
import org.springframework.data.elasticsearch.annotations.Field; | ||
import org.springframework.data.elasticsearch.annotations.FieldType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* Description: Book, change description here. | ||
* | ||
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/20/2022 1:40 PM | ||
*/ | ||
@Data | ||
@Document(indexName = "books") | ||
public class Book { | ||
/** | ||
* The Id. | ||
*/ | ||
@Id | ||
private String id; | ||
/** | ||
* The Title. | ||
*/ | ||
@Field(type = FieldType.Text, name = "name") | ||
private String name; | ||
/** | ||
* The Summary. | ||
*/ | ||
@Field(type = FieldType.Text) | ||
private String summary; | ||
/** | ||
* The Publishing date. | ||
*/ | ||
@Field(type = FieldType.Date, name = "publishDate", format = {}, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") | ||
private LocalDateTime publishingDate; | ||
/** | ||
* The Price. | ||
*/ | ||
@Field(type = FieldType.Double, name = "price") | ||
private double price; | ||
} |
34 changes: 34 additions & 0 deletions
34
...ter/src/main/java/com/jmsoftware/maf/springcloudstarter/elasticsearch/BookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.jmsoftware.maf.springcloudstarter.elasticsearch; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.elasticsearch.annotations.Query; | ||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Description: BookRepository, change description here. | ||
* | ||
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/20/2022 2:06 PM | ||
**/ | ||
public interface BookRepository extends ElasticsearchRepository<Book, String> { | ||
/** | ||
* Find by name and price list. | ||
* | ||
* @param name the name | ||
* @param price the price | ||
* @return the list | ||
*/ | ||
List<Book> findByNameAndPrice(String name, Integer price); | ||
|
||
/** | ||
* Find by name page. | ||
* | ||
* @param name the name | ||
* @param pageable the pageable | ||
* @return the page | ||
*/ | ||
@Query("{\"match\": {\"name\": {\"query\": \"?0\"}}}") | ||
Page<Book> findByName(String name, Pageable pageable); | ||
} |
33 changes: 33 additions & 0 deletions
33
.../java/com/jmsoftware/maf/springcloudstarter/elasticsearch/ElasticsearchConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jmsoftware.maf.springcloudstarter.elasticsearch; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchProperties; | ||
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* Description: ElasticsearchConfiguration, change description here. | ||
* | ||
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/19/2022 11:38 PM | ||
* @see | ||
* <a href='https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/'>Spring Data Elasticsearch - Reference Documentation</a> | ||
* @see | ||
* <a href='https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.logging'>Client Logging</a> | ||
**/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@EnableElasticsearchRepositories | ||
@ConditionalOnClass({AbstractElasticsearchConfiguration.class, RestHighLevelClient.class}) | ||
public class ElasticsearchConfiguration { | ||
private final ElasticsearchProperties elasticsearchProperties; | ||
|
||
@PostConstruct | ||
public void init() { | ||
log.warn("ElasticsearchConfiguration init. URIs: {}", elasticsearchProperties.getUris()); | ||
} | ||
} |