feat(商城): 添加elasticsearch
parent
2ce28d853a
commit
605a86ac22
@ -0,0 +1,46 @@
|
|||||||
|
package com.wayn.admin.api.controller.shop;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wayn.admin.framework.manager.elastic.service.BaseElasticService;
|
||||||
|
import com.wayn.common.base.ElasticEntity;
|
||||||
|
import com.wayn.common.util.R;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("elastic")
|
||||||
|
public class ElasticController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BaseElasticService baseElasticService;
|
||||||
|
|
||||||
|
@GetMapping("insert")
|
||||||
|
public R insert() {
|
||||||
|
ElasticEntity elasticEntity = new ElasticEntity();
|
||||||
|
elasticEntity.setId("2");
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("name", "书本2");
|
||||||
|
map.put("price", 1000D);
|
||||||
|
map.put("date", new Date());
|
||||||
|
elasticEntity.setData(map);
|
||||||
|
baseElasticService.insertOrUpdateOne("store", elasticEntity);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("search")
|
||||||
|
public R search() {
|
||||||
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
|
searchSourceBuilder.query(QueryBuilders.matchQuery("name", "沃尔玛"));
|
||||||
|
List<Object> list = baseElasticService.search("store", searchSourceBuilder, Object.class);
|
||||||
|
return R.success().add("data", list);
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
package com.wayn.admin.api.controller.shop;
|
|
||||||
|
|
||||||
|
|
||||||
import com.wayn.common.base.BaseElasticService;
|
|
||||||
import com.wayn.common.util.R;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("test")
|
|
||||||
public class TestController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BaseElasticService baseElasticService;
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public R test() {
|
|
||||||
baseElasticService.createIndex("2", "");
|
|
||||||
return R.success();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue