diff --git a/pom.xml b/pom.xml index 8fc355c23bd489f3fd81739afa5651267f084f9e..0ed2f637399d9cc0cf18d6065c42d7ddec1e66e8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.elasticsearch.client elasticsearch-rest-high-level-client - 7.12.0 + 7.3.0 org.elasticsearch @@ -26,7 +26,7 @@ org.elasticsearch elasticsearch - 7.12.0 + 7.3.0 org.springframework.boot diff --git a/src/main/java/com/kwan/shuyu/controller/ContentController.java b/src/main/java/com/kwan/shuyu/controller/ContentController.java index accb6d4d65e041be72b542c3ec5a16c78f445ca5..602e7ceac057678ba4a06ceb79cd2bd5e8da7657 100644 --- a/src/main/java/com/kwan/shuyu/controller/ContentController.java +++ b/src/main/java/com/kwan/shuyu/controller/ContentController.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.io.IOException; @@ -24,9 +25,9 @@ public class ContentController { * @return * @throws Exception */ - @GetMapping("/parse/{keyword}") + @GetMapping("/parse") @ResponseBody - public Boolean parse(@PathVariable String keyword) throws Exception { + public Boolean parse(@RequestParam(value = "keyword") String keyword) throws Exception { return contentService.parseContent(keyword); } diff --git a/src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java b/src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java index 3e8104fa5575d05dd534509369ad35821b491faa..daa0059d3b82d9a973b7649fe91cc0b228e43cd0 100644 --- a/src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java +++ b/src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java @@ -29,22 +29,28 @@ import java.util.concurrent.TimeUnit; @Service public class ContentServiceImpl implements ContentService { - @Autowired - private RestHighLevelClient restHighLevelClient; @Autowired private HtmlParseUtil htmlParseUtil; + @Autowired + private RestHighLevelClient restHighLevelClient; - //1.解析数据放入es索引中 + /** + * 解析数据放入es索引中 + * + * @param keywords + * @return + * @throws Exception + */ @Override public Boolean parseContent(String keywords) throws Exception { List contents = htmlParseUtil.parseJD(keywords); //把查询出来的数据放入es里面 BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.timeout("2m"); + bulkRequest.timeout(TimeValue.timeValueMinutes(120)); for (int i = 0; i < contents.size(); i++) { System.out.println(contents.get(i)); bulkRequest.add( - new IndexRequest("jd_goods_2", keywords + "") + new IndexRequest("jd_goods" + keywords, keywords + "") .source(JSON.toJSONString(contents.get(i)), XContentType.JSON)); } BulkResponse bulk = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 54701633e169f86754fbd583dd70403dd97c1c70..bd3a7d500218aa2bb936d15aaeeaa5849adbb209 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 40100 + port: 8888 spring: application: diff --git a/src/test/java/es_02_index/TestIndex_08_close.java b/src/test/java/es_02_index/TestIndex_08_close.java index 34350640be24b005fa5b9c6c46f53becf6789cee..6e9243f7b1389a935bf2345e55fc519246873a3e 100644 --- a/src/test/java/es_02_index/TestIndex_08_close.java +++ b/src/test/java/es_02_index/TestIndex_08_close.java @@ -1,10 +1,10 @@ package es_02_index; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.indices.CloseIndexRequest; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/es_04_agg/TestAggs_05.java b/src/test/java/es_04_agg/TestAggs_05.java index 76ee50e8485dc6c8942ef2aa35d57e67697ebd11..6b61dca814da11cc3428c22dff5cf7e8292a1d94 100644 --- a/src/test/java/es_04_agg/TestAggs_05.java +++ b/src/test/java/es_04_agg/TestAggs_05.java @@ -68,7 +68,8 @@ public class TestAggs_05 { searchSourceBuilder.size(0); searchSourceBuilder.query(QueryBuilders.matchAllQuery()); DateHistogramAggregationBuilder dateHistogramAggregationBuilder = AggregationBuilders.dateHistogram("date_histogram").field("sold_date").calendarInterval(DateHistogramInterval.QUARTER) - .format("yyyy-MM-dd").minDocCount(0).extendedBounds(new ExtendedBounds("2019-01-01", "2020-12-31")); + .format("yyyy-MM-dd").minDocCount(0) + .extendedBounds(new ExtendedBounds("2019-01-01", "2020-12-31")); SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum("income").field("price"); dateHistogramAggregationBuilder.subAggregation(sumAggregationBuilder); searchSourceBuilder.aggregation(dateHistogramAggregationBuilder);