mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 21:52:07 +08:00
1、es单挑数据删除search+deleteById替换DeleteByQueryRequest;2、springboot升级redis配置变化同步;
This commit is contained in:
@@ -63,6 +63,7 @@ spring:
|
|||||||
password: root
|
password: root
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.1.205 # 地址
|
host: 192.168.1.205 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ spring:
|
|||||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
+24
-37
@@ -192,8 +192,7 @@ public class OrderInputProcessor {
|
|||||||
throw new ServiceException(500, "未知异常");
|
throw new ServiceException(500, "未知异常");
|
||||||
}
|
}
|
||||||
} catch (IOException | ElasticsearchException e) {
|
} catch (IOException | ElasticsearchException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,50 +216,38 @@ public class OrderInputProcessor {
|
|||||||
throw new ServiceException(500, "未知异常");
|
throw new ServiceException(500, "未知异常");
|
||||||
}
|
}
|
||||||
} catch (IOException | ElasticsearchException e) {
|
} catch (IOException | ElasticsearchException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生产单id查询文档id
|
* 生产单Id删除
|
||||||
*/
|
|
||||||
public List<String> buildRespByOrderId(Long orderId, String index, Integer size) {
|
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.size(size);
|
|
||||||
builder.query(q -> q.term(b -> b.field(FIELD_ORDER_ID).value(orderId)));
|
|
||||||
|
|
||||||
builder.source(s -> s.fetch(false));
|
|
||||||
|
|
||||||
try {
|
|
||||||
SearchResponse<?> search = elasticsearchClient.search(builder.build(), Object.class);
|
|
||||||
List<? extends Hit<?>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
return hits.stream().map(Hit::id).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生产单Id批量删除
|
|
||||||
*/
|
*/
|
||||||
public void deleteByOrderId(Long orderId, String index) {
|
public void deleteByOrderId(Long orderId, String index) {
|
||||||
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.query(q -> q.term(t -> t.field(FIELD_ORDER_ID).value(orderId)));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
|
// 查文档_id
|
||||||
log.info("Deleted {} documents with planId {}", response.deleted(), orderId);
|
SearchResponse<Void> search = elasticsearchClient.search(s -> s
|
||||||
|
.index(index)
|
||||||
|
.size(1) // 只取一条
|
||||||
|
.query(q -> q.term(t -> t.field("orderId").value(orderId)))
|
||||||
|
.source(src -> src.fetch(false)), // 不拉取 _source
|
||||||
|
Void.class
|
||||||
|
);
|
||||||
|
List<Hit<Void>> hits = search.hits().hits();
|
||||||
|
if (hits.isEmpty()) {
|
||||||
|
log.warn("No document found for orderId: {}", orderId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String docId = hits.get(0).id();
|
||||||
|
|
||||||
|
// 按 _id 删除
|
||||||
|
elasticsearchClient.delete(d -> d.index(index).id(docId));
|
||||||
|
log.info("Successfully deleted document with orderId={} (docId={})", orderId, docId);
|
||||||
} catch (IOException | ElasticsearchException e) {
|
} catch (IOException | ElasticsearchException e) {
|
||||||
log.error("Error deleting documents with planId {}: {}", orderId, e.getMessage());
|
log.error("Error deleting documents with orderId {}: {}", orderId, e);
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,7 +267,7 @@ public class OrderInputProcessor {
|
|||||||
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
|
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
|
||||||
log.info("Deleted {} documents with planId {}", response.deleted(), orderIds);
|
log.info("Deleted {} documents with planId {}", response.deleted(), orderIds);
|
||||||
} catch (IOException | ElasticsearchException e) {
|
} catch (IOException | ElasticsearchException e) {
|
||||||
log.error("Error deleting documents with planId {}: {}", orderIds, e.getMessage());
|
log.error("Error deleting documents with planId {}: {}", orderIds, e);
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -63,6 +63,7 @@ spring:
|
|||||||
password: root
|
password: root
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.1.205 # 地址
|
host: 192.168.1.205 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
+1
@@ -80,6 +80,7 @@ spring:
|
|||||||
password: root
|
password: root
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ spring:
|
|||||||
password: root
|
password: root
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.1.205 # 地址
|
host: 192.168.1.205 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ spring:
|
|||||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ spring:
|
|||||||
|
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.1.205 # 地址
|
host: 192.168.1.205 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ spring:
|
|||||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ spring:
|
|||||||
password: root
|
password: root
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.1.205 # 地址
|
host: 192.168.1.205 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ spring:
|
|||||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||||
|
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 6379 # 端口
|
port: 6379 # 端口
|
||||||
|
|||||||
Reference in New Issue
Block a user