Commit 5a6b7adc authored by shiyu's avatar shiyu

es索引配置

parent c46648bd
......@@ -40,13 +40,13 @@ public class ElasticSearchConfig {
/**
* 多个ip用逗号隔开
*/
@Value("${spring.elasticsearch.jest.uris}")
@Value("${spring.elasticsearch.rest.uris}")
private String elasticsearchUris;
@Value("${spring.elasticsearch.jest.username}")
@Value("${spring.elasticsearch.rest.username}")
private String username;
@Value("${spring.elasticsearch.jest.password}")
@Value("${spring.elasticsearch.rest.password}")
private String password;
private final static String crtName = "za-test.crt";
......
......@@ -161,10 +161,11 @@ spring:
database: 0
elasticsearch:
jest:
uris: 172.16.122.190:9200
rest:
uris: 172.16.122.190:9200
username: elastic
password: changeme
index: quanku_dev
jackson:
date-format: yyyy-MM-dd HH:mm:ss
......
......@@ -165,11 +165,11 @@ spring:
database: 0
elasticsearch:
jest:
rest:
uris: 172.16.122.190:9200
username: elastic
password: changeme
index: quanku_new
server:
servlet:
session:
......
......@@ -93,4 +93,5 @@ public class CoinRequestDto extends BaseRequestDto implements Entity {
* 用于同步数据到es
*/
private Date startUpdateTime;
}
......@@ -15,6 +15,7 @@ import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
......@@ -28,7 +29,8 @@ public class ItemEsDao {
private static final Logger logger = LoggerFactory.getLogger(ItemEsDao.class);
private final static String INDEX = "quanku_new";
@Value("${spring.elasticsearch.rest.index}")
private String INDEX;
//商品来源是中国,所对应的编码
private final static List<String> CHINESE_SOURCE_LIST = Arrays.asList("1", "2", "3", "7", "11", "1000");
......@@ -160,6 +162,23 @@ public class ItemEsDao {
}
public Boolean isExised(Long id) {
try {
CountRequest.Builder builder = new CountRequest.Builder();
builder.index(INDEX);
Query termQuery = TermQuery.of(t -> t.field("id").value(id))._toQuery();
builder.query(termQuery);
CountRequest countRequest = builder.build();
CountResponse countResponse = elasticsearchClient.count(countRequest);
long num = countResponse.count();
return num > 0;
} catch (Exception e) {
logger.error("查询es是否存在id为 {} 的数据出错", id);
}
return null;
}
public void update(Item item) {
String id = String.valueOf(item.getId());
try {
......@@ -167,6 +186,7 @@ public class ItemEsDao {
Map<String, Object> map = new HashMap<>();
map.put("images", item.getImages());
UpdateResponse<Item> updateResponse = elasticsearchClient.update(e -> e.index(INDEX).id(id).doc(map), Item.class);
logger.info("updateResponse = {}", updateResponse);
logger.info("ES修改数据成功, id:{}, 修改内容: {} ", id, map);
} catch (Exception e) {
logger.error("修改es数据出错 id: {}", id, e);
......@@ -189,7 +209,7 @@ public class ItemEsDao {
List<Hit<ItemOfEs>> hitList = searchResponse.hits().hits();
if (!CollectionUtils.isEmpty(hitList)) {
Date time = hitList.get(0).source().getUpdateTime();
logger.info(">>>>>>>>>>>> 查询出的最大更新时间: {}", DateUtils.toString(time));
logger.info(">>>>>>>>>>>> es查询出的最大更新时间: {}", DateUtils.toString(time));
return time;
}
} catch (Exception e) {
......
......@@ -65,7 +65,11 @@ public class ItemDaoImpl implements ItemDao {
public List<Item> findListByPage(CoinRequestDto coinRequestDto) {
ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria();
example.setOrderByClause("create_time asc");
if (StringUtils.hasLength(coinRequestDto.getSortColumn())) {
example.setOrderByClause(coinRequestDto.getSortColumn() + " asc");
} else {
example.setOrderByClause("create_time asc");
}
JdbcHelper.ifPresent(coinRequestDto.getStartUpdateTime(), criteria::andUpdateTimeGreaterThan);
PageHelper.startPage(coinRequestDto.getPage(), coinRequestDto.getLimit());
return itemMapper.selectByExampleWithBLOBs(example);
......
......@@ -5,8 +5,8 @@ spring:
encoding: UTF-8
servlet:
multipart:
max-file-size: 50Mb
max-request-size: 80Mb
max-file-size: 50MB
max-request-size: 50MB
location: /tmp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment