yegang 2 years ago
parent
commit
ec5a4220dc

+ 39 - 0
pom.xml

@@ -17,6 +17,7 @@
     <description>口罩秒杀</description>
     <properties>
         <java.version>1.8</java.version>
+        <docker.image.prefix>mask</docker.image.prefix>
 <!--        <elasticsearch.version>8.0.1</elasticsearch.version>-->
     </properties>
     <dependencies>
@@ -116,6 +117,44 @@
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <version>2.6.0</version>
             </plugin>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>1.0.0</version>
+                <configuration>
+                    <!-- 镜像名称 guoweixin/exam-->
+                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
+                    <!--指定标签-->
+                    <imageTags>
+                        <imageTag>latest</imageTag>
+                    </imageTags>
+                    <!-- 基础镜像jdk 1.8-->
+                    <baseImage>java</baseImage>
+                    <!-- 制作者提供本人信息 -->
+                    <maintainer>yegang</maintainer>
+                    <!--切换到/ROOT目录 -->
+                    <workdir>/ROOT</workdir>
+                    <cmd>["java", "-version"]</cmd>
+                    <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint>
+                    <!-- 指定 Dockerfile 路径
+                    <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
+                    -->
+                    <!--指定远程 docker api地址-->
+                    <dockerHost>http://192.168.20.87:2375</dockerHost>
+                    <!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
+                    <resources>
+                        <resource>
+                            <targetPath>/ROOT</targetPath>
+                            <!--用于指定需要复制的根目录,${project.build.directory}表示target目录-->
+                            <directory>${project.build.directory}</directory>
+                            <!--用于指定需要复制的文件。${project.build.finalName}.jar指的是打包后的jar
+                            包文件。-->
+                            <include>${project.build.finalName}.jar</include>
+                        </resource>
+                    </resources>
+                </configuration>
+            </plugin>
+
         </plugins>
     </build>
 

+ 1 - 1
src/main/java/com/sw/domain/po/EsProduct.java

@@ -23,7 +23,7 @@ public class EsProduct {
     @Id  //主键
     private Integer id;
     //FieldType.Auto根据字段类型自动注入,例如这里是String
-    @Field(type = FieldType.Auto)
+    @Field(type = FieldType.Keyword)
     private String name;
     //FieldType.Auto根据字段类型自动注入,例如这里是String
     @Field(type = FieldType.Auto)

+ 7 - 3
src/main/resources/application.yml

@@ -36,9 +36,13 @@ spring:
     pub-sub-domain: false
   activemq:
     user: admin    # 连接用户名
-    password: admin   # 连接密码
+    pass  word: admin   # 连接密码
     broker-url: tcp://192.168.20.76:28085 # 消息组件的连接主机信息
-#    broker-url: tcp://localhost:61616 # 消息组件的连接主机信息
+  # elasticsearch 配置
+  elasticsearch:
+    rest:
+      # ip是服务器ip地址
+      uris: http://192.168.20.85:9200
 queuename: mask
 amount: 5
 
@@ -61,4 +65,4 @@ mybatis-plus:
     variables:
       nextTermDays: 90
       #mybatis-plus配置控制台打印完整带参数SQL语句
-#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 5 - 3
src/test/java/com/sw/EsDocTests.java

@@ -84,7 +84,7 @@ public class EsDocTests {
      */
     public  void putbatchTest() throws IOException {
         //创建数据对象
-        List<EsProduct> list = ParseHtml.parse("大数据");
+        List<EsProduct> list = ParseHtml.parse("java");
         BulkRequest bulkRequest = new BulkRequest();
         bulkRequest.timeout("2m");
         for(EsProduct esProduct :list){
@@ -212,19 +212,21 @@ public class EsDocTests {
         searchSourceBuilder.sort("num",SortOrder.DESC);
         //模糊查询
         BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
+
         boolQueryBuilder.must(QueryBuilders.matchQuery("name","java"));
         boolQueryBuilder.must(QueryBuilders.rangeQuery("price").gt("100").lt("200"));
         searchSourceBuilder.query(boolQueryBuilder);
         //设置超时
         searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
         //设置起始位置
-        searchSourceBuilder.from(1);
+        searchSourceBuilder.from(10);
         //设置页大小
-        searchSourceBuilder.size(30);
+        searchSourceBuilder.size(10);
         //绑定build
         searchRequest.source(searchSourceBuilder);
         //执行搜索
         SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
+        System.out.println(searchResponse.getHits().getTotalHits());
         //遍历hits
         for (SearchHit hit : searchResponse.getHits().getHits()) {
             Map<String, Object> sourceAsMap = hit.getSourceAsMap();