Skip to content

Commit a471749

Browse files
committed
ES 示例和文档
1 parent ad820ba commit a471749

36 files changed

+1647
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
version: '2.2'
2+
services:
3+
cerebro:
4+
image: lmenezes/cerebro:0.8.3
5+
container_name: hwc_cerebro
6+
ports:
7+
- "9000:9000"
8+
command:
9+
- -Dhosts.0.host=http://elasticsearch:9200
10+
networks:
11+
- hwc_es7net
12+
kibana:
13+
image: docker.elastic.co/kibana/kibana:7.1.0
14+
container_name: hwc_kibana7
15+
environment:
16+
#- I18N_LOCALE=zh-CN
17+
- XPACK_GRAPH_ENABLED=true
18+
- TIMELION_ENABLED=true
19+
- XPACK_MONITORING_COLLECTION_ENABLED="true"
20+
ports:
21+
- "5601:5601"
22+
networks:
23+
- hwc_es7net
24+
elasticsearch:
25+
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
26+
container_name: es7_hot
27+
environment:
28+
- cluster.name=geektime-hwc
29+
- node.name=es7_hot
30+
- node.attr.box_type=hot
31+
- bootstrap.memory_lock=true
32+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
33+
- discovery.seed_hosts=es7_hot,es7_warm,es7_cold
34+
- cluster.initial_master_nodes=es7_hot,es7_warm,es7_cold
35+
ulimits:
36+
memlock:
37+
soft: -1
38+
hard: -1
39+
volumes:
40+
- hwc_es7data_hot:/usr/share/elasticsearch/data
41+
ports:
42+
- 9200:9200
43+
networks:
44+
- hwc_es7net
45+
elasticsearch2:
46+
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
47+
container_name: es7_warm
48+
environment:
49+
- cluster.name=geektime-hwc
50+
- node.name=es7_warm
51+
- node.attr.box_type=warm
52+
- bootstrap.memory_lock=true
53+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
54+
- discovery.seed_hosts=es7_hot,es7_warm,es7_cold
55+
- cluster.initial_master_nodes=es7_hot,es7_warm,es7_cold
56+
ulimits:
57+
memlock:
58+
soft: -1
59+
hard: -1
60+
volumes:
61+
- hwc_es7data_warm:/usr/share/elasticsearch/data
62+
networks:
63+
- hwc_es7net
64+
elasticsearch3:
65+
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
66+
container_name: es7_cold
67+
environment:
68+
- cluster.name=geektime-hwc
69+
- node.name=es7_cold
70+
- node.attr.box_type=cold
71+
- bootstrap.memory_lock=true
72+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
73+
- discovery.seed_hosts=es7_hot,es7_warm,es7_cold
74+
- cluster.initial_master_nodes=es7_hot,es7_warm,es7_cold
75+
ulimits:
76+
memlock:
77+
soft: -1
78+
hard: -1
79+
volumes:
80+
- hwc_es7data_cold:/usr/share/elasticsearch/data
81+
networks:
82+
- hwc_es7net
83+
84+
85+
volumes:
86+
hwc_es7data_hot:
87+
driver: local
88+
hwc_es7data_warm:
89+
driver: local
90+
hwc_es7data_cold:
91+
driver: local
92+
93+
networks:
94+
hwc_es7net:
95+
driver: bridge
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.6.3</version>
10+
</parent>
11+
12+
<groupId>io.github.dunwu</groupId>
13+
<artifactId>javadb-elasticsearch</artifactId>
14+
<version>1.0.0</version>
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<elasticsearch.version>7.16.3</elasticsearch.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-json</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.projectlombok</groupId>
38+
<artifactId>lombok</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>cn.hutool</groupId>
42+
<artifactId>hutool-all</artifactId>
43+
<version>5.7.20</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>co.elastic.clients</groupId>
48+
<artifactId>elasticsearch-java</artifactId>
49+
<version>7.16.3</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.elasticsearch.client</groupId>
54+
<artifactId>elasticsearch-rest-client</artifactId>
55+
<version>${elasticsearch.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.elasticsearch.client</groupId>
59+
<artifactId>elasticsearch-rest-high-level-client</artifactId>
60+
<version>${elasticsearch.version}</version>
61+
</dependency>
62+
</dependencies>
63+
64+
<dependencyManagement>
65+
<dependencies>
66+
<dependency>
67+
<groupId>com.fasterxml.jackson.core</groupId>
68+
<artifactId>jackson-databind</artifactId>
69+
<version>2.12.3</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.fasterxml.jackson.core</groupId>
73+
<artifactId>jackson-core</artifactId>
74+
<version>2.12.3</version>
75+
</dependency>
76+
</dependencies>
77+
</dependencyManagement>
78+
79+
<build>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.springframework.boot</groupId>
83+
<artifactId>spring-boot-maven-plugin</artifactId>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.github.dunwu.javadb.elasticsearch.springboot;
2+
3+
import io.github.dunwu.javadb.elasticsearch.springboot.repositories.UserRepository;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.elasticsearch.client.RestHighLevelClient;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.CommandLineRunner;
8+
import org.springframework.boot.SpringApplication;
9+
import org.springframework.boot.autoconfigure.SpringBootApplication;
10+
11+
/**
12+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
13+
* @date 2022-02-23
14+
*/
15+
@Slf4j
16+
@SpringBootApplication
17+
public class SpringBootDataElasticsearchApplication implements CommandLineRunner {
18+
19+
@Autowired
20+
private RestHighLevelClient restHighLevelClient;
21+
@Autowired
22+
private UserRepository repository;
23+
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(SpringBootDataElasticsearchApplication.class);
27+
}
28+
29+
@Override
30+
public void run(String... args) {
31+
System.out.println("[index = user] 的文档数:" + repository.count());
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.dunwu.javadb.elasticsearch.springboot.constant;
2+
3+
/**
4+
* 关键字命名策略枚举
5+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
6+
* @since 2019-12-18
7+
*/
8+
public enum NamingStrategy {
9+
/**
10+
* 默认命名
11+
*/
12+
DEFAULT,
13+
/**
14+
* 驼峰命名。例:namingStrategy
15+
*/
16+
CAMEL,
17+
/**
18+
* 全小写字母用下划线拼接。例:naming_strategy
19+
*/
20+
LOWER_UNDERLINE,
21+
/**
22+
* 全大写字母用下划线拼接。例:NAMING_STRATEGY
23+
*/
24+
UPPER_UNDERLINE,
25+
/**
26+
* 全小写字母用分割线拼接。例:naming-strategy
27+
*/
28+
LOWER_DASHED,
29+
/**
30+
* 全小写字母用分割线拼接。例:NAMING-STRATEGY
31+
*/
32+
UPPER_DASHED,
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.github.dunwu.javadb.elasticsearch.springboot.constant;
2+
3+
import java.util.Locale;
4+
import java.util.Optional;
5+
6+
/**
7+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
8+
* @since 2019-12-17
9+
*/
10+
public enum OrderType {
11+
12+
ASC,
13+
DESC;
14+
15+
/**
16+
* Returns the {@link OrderType} enum for the given {@link String} or null if it cannot be parsed into an enum
17+
* value.
18+
* @param value
19+
* @return
20+
*/
21+
public static Optional<OrderType> fromOptionalString(String value) {
22+
23+
try {
24+
return Optional.of(fromString(value));
25+
} catch (IllegalArgumentException e) {
26+
return Optional.empty();
27+
}
28+
}
29+
30+
/**
31+
* Returns the {@link OrderType} enum for the given {@link String} value.
32+
* @param value
33+
* @return
34+
* @throws IllegalArgumentException in case the given value cannot be parsed into an enum value.
35+
*/
36+
public static OrderType fromString(String value) {
37+
38+
try {
39+
return OrderType.valueOf(value.toUpperCase(Locale.US));
40+
} catch (Exception e) {
41+
throw new IllegalArgumentException(String.format(
42+
"Invalid value '%s' for orders given! Has to be either 'desc' or 'asc' (case insensitive).", value), e);
43+
}
44+
}
45+
46+
/**
47+
* Returns whether the direction is ascending.
48+
* @return
49+
* @since 1.13
50+
*/
51+
public boolean isAscending() {
52+
return this.equals(ASC);
53+
}
54+
55+
/**
56+
* Returns whether the direction is descending.
57+
* @return
58+
* @since 1.13
59+
*/
60+
public boolean isDescending() {
61+
return this.equals(DESC);
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.dunwu.javadb.elasticsearch.springboot.constant;
2+
3+
/**
4+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
5+
* @since 2019-12-17
6+
*/
7+
public enum QueryJudgeType {
8+
Equals,
9+
NotEquals,
10+
Like,
11+
NotLike,
12+
In,
13+
NotIn,
14+
IsNull,
15+
IsNotNull,
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.github.dunwu.javadb.elasticsearch.springboot.constant;
2+
3+
/**
4+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
5+
* @since 2019-12-17
6+
*/
7+
public enum QueryLogicType {
8+
AND,
9+
OR,
10+
NOT
11+
}

0 commit comments

Comments
 (0)