Commit 5a6b7adc authored by shiyu's avatar shiyu

es索引配置

parent c46648bd
...@@ -40,13 +40,13 @@ public class ElasticSearchConfig { ...@@ -40,13 +40,13 @@ public class ElasticSearchConfig {
/** /**
* 多个ip用逗号隔开 * 多个ip用逗号隔开
*/ */
@Value("${spring.elasticsearch.jest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String elasticsearchUris; private String elasticsearchUris;
@Value("${spring.elasticsearch.jest.username}") @Value("${spring.elasticsearch.rest.username}")
private String username; private String username;
@Value("${spring.elasticsearch.jest.password}") @Value("${spring.elasticsearch.rest.password}")
private String password; private String password;
private final static String crtName = "za-test.crt"; private final static String crtName = "za-test.crt";
......
...@@ -161,10 +161,11 @@ spring: ...@@ -161,10 +161,11 @@ spring:
database: 0 database: 0
elasticsearch: elasticsearch:
jest: rest:
uris: 172.16.122.190:9200 uris: 172.16.122.190:9200
username: elastic username: elastic
password: changeme password: changeme
index: quanku_dev
jackson: jackson:
date-format: yyyy-MM-dd HH:mm:ss date-format: yyyy-MM-dd HH:mm:ss
......
...@@ -165,11 +165,11 @@ spring: ...@@ -165,11 +165,11 @@ spring:
database: 0 database: 0
elasticsearch: elasticsearch:
jest: rest:
uris: 172.16.122.190:9200 uris: 172.16.122.190:9200
username: elastic username: elastic
password: changeme password: changeme
index: quanku_new
server: server:
servlet: servlet:
session: session:
......
...@@ -93,4 +93,5 @@ public class CoinRequestDto extends BaseRequestDto implements Entity { ...@@ -93,4 +93,5 @@ public class CoinRequestDto extends BaseRequestDto implements Entity {
* 用于同步数据到es * 用于同步数据到es
*/ */
private Date startUpdateTime; private Date startUpdateTime;
} }
...@@ -15,6 +15,7 @@ import com.xxdxxs.utils.DateUtils; ...@@ -15,6 +15,7 @@ import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.StringUtils; import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -28,7 +29,8 @@ public class ItemEsDao { ...@@ -28,7 +29,8 @@ public class ItemEsDao {
private static final Logger logger = LoggerFactory.getLogger(ItemEsDao.class); 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"); private final static List<String> CHINESE_SOURCE_LIST = Arrays.asList("1", "2", "3", "7", "11", "1000");
...@@ -160,6 +162,23 @@ public class ItemEsDao { ...@@ -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) { public void update(Item item) {
String id = String.valueOf(item.getId()); String id = String.valueOf(item.getId());
try { try {
...@@ -167,6 +186,7 @@ public class ItemEsDao { ...@@ -167,6 +186,7 @@ public class ItemEsDao {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("images", item.getImages()); map.put("images", item.getImages());
UpdateResponse<Item> updateResponse = elasticsearchClient.update(e -> e.index(INDEX).id(id).doc(map), Item.class); 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); logger.info("ES修改数据成功, id:{}, 修改内容: {} ", id, map);
} catch (Exception e) { } catch (Exception e) {
logger.error("修改es数据出错 id: {}", id, e); logger.error("修改es数据出错 id: {}", id, e);
...@@ -189,7 +209,7 @@ public class ItemEsDao { ...@@ -189,7 +209,7 @@ public class ItemEsDao {
List<Hit<ItemOfEs>> hitList = searchResponse.hits().hits(); List<Hit<ItemOfEs>> hitList = searchResponse.hits().hits();
if (!CollectionUtils.isEmpty(hitList)) { if (!CollectionUtils.isEmpty(hitList)) {
Date time = hitList.get(0).source().getUpdateTime(); Date time = hitList.get(0).source().getUpdateTime();
logger.info(">>>>>>>>>>>> 查询出的最大更新时间: {}", DateUtils.toString(time)); logger.info(">>>>>>>>>>>> es查询出的最大更新时间: {}", DateUtils.toString(time));
return time; return time;
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -65,7 +65,11 @@ public class ItemDaoImpl implements ItemDao { ...@@ -65,7 +65,11 @@ public class ItemDaoImpl implements ItemDao {
public List<Item> findListByPage(CoinRequestDto coinRequestDto) { public List<Item> findListByPage(CoinRequestDto coinRequestDto) {
ItemExample example = new ItemExample(); ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria(); ItemExample.Criteria criteria = example.createCriteria();
if (StringUtils.hasLength(coinRequestDto.getSortColumn())) {
example.setOrderByClause(coinRequestDto.getSortColumn() + " asc");
} else {
example.setOrderByClause("create_time asc"); example.setOrderByClause("create_time asc");
}
JdbcHelper.ifPresent(coinRequestDto.getStartUpdateTime(), criteria::andUpdateTimeGreaterThan); JdbcHelper.ifPresent(coinRequestDto.getStartUpdateTime(), criteria::andUpdateTimeGreaterThan);
PageHelper.startPage(coinRequestDto.getPage(), coinRequestDto.getLimit()); PageHelper.startPage(coinRequestDto.getPage(), coinRequestDto.getLimit());
return itemMapper.selectByExampleWithBLOBs(example); return itemMapper.selectByExampleWithBLOBs(example);
......
...@@ -5,8 +5,8 @@ spring: ...@@ -5,8 +5,8 @@ spring:
encoding: UTF-8 encoding: UTF-8
servlet: servlet:
multipart: multipart:
max-file-size: 50Mb max-file-size: 50MB
max-request-size: 80Mb max-request-size: 50MB
location: /tmp 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