您的位置:首页 > 健康 > 美食 > h5在线制作免费版_纯字母logo设计_百度爱采购客服电话_seo排名点击器

h5在线制作免费版_纯字母logo设计_百度爱采购客服电话_seo排名点击器

2025/4/18 18:58:03 来源:https://blog.csdn.net/haohaounique/article/details/145890860  浏览:    关键词:h5在线制作免费版_纯字母logo设计_百度爱采购客服电话_seo排名点击器
h5在线制作免费版_纯字母logo设计_百度爱采购客服电话_seo排名点击器

看了一下官网版本已经来到了8.17

正常打印似乎不行,突破的地方则是 藏在@JsonpDeserializable 这个注解上;

@JsonpDeserializable
public class SearchRequest

因此只有反序列化出来之后才能打印,似乎就这么简单,看源码或许能更快的解决问题

方法一 查询打印

SearchRequest.Builder builder = new SearchRequest.Builder();
builder.query(q -> q.bool(boolQuery));
SearchRequest build = builder.build();
log.info("search request:【{}】", searchDSL(build));
    public String searchDSL(SearchRequest searchRequest) {// 创建 JSON 生成器和 JSON 映射器try (StringWriter writer = new StringWriter();JsonGenerator generator = Json.createGenerator(writer)) {JsonpMapper mapper = new JacksonJsonpMapper();searchRequest.serialize(generator, mapper);generator.close();return writer.toString();} catch (Exception e) {log.error("search exception", e);}return null;}

打印es请求日志,在application.properties中添加 或者放到yaml 文件中

logging.level.org.elasticsearch.client.RestClient=DEBUG

效果

2025-02-26T22:59:26.458+08:00  INFO 35528 --- [unique-search] [nio-8080-exec-4] c.u.framework.common.utils.EsClient      : search request:【{"query":{"bool":{"must":[{"term":{"id":{"value":"1"}}},{"term":{"edition":{"value":"工信部出版社"}}},{"fuzzy":{"bookName":{"value":"我"}}}]}}}】
2025-02-26T22:59:26.594+08:00 DEBUG 35528 --- [unique-search] [nio-8080-exec-4] org.elasticsearch.client.RestClient      : request [POST https://localhost:9200/textbook/_search?typed_keys=true] returned [HTTP/1.1 200 OK]

方式二 AOP打印

使用aop对调用的方法进行处理;

import co.elastic.clients.elasticsearch.core.SearchRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
@Slf4j
public class WebLogAspect {@Pointcut("execution(public * co.elastic.clients.elasticsearch.ElasticsearchClient.search(..))")public void before() {}@Before("before()")public void logRequest(JoinPoint joinPoint) {Object[] args = joinPoint.getArgs();if (args.length > 0 && args[0] instanceof SearchRequest) {SearchRequest searchRequest = (SearchRequest) args[0];log.info("请求参数: {}", searchRequest);}}
}

效果

2025-03-01T18:23:02.180+08:00  INFO 30812 --- [unique-search] [nio-8080-exec-4] c.u.framework.common.aop.WebLogAspect    : 请求参数: SearchRequest: POST /textbook/_search?typed_keys=true {"from":0,"query":{"bool":{"must":[{"wildcard":{"email":{"value":"*qq.com"}}}]}},"size":10,"sort":[{"id":{"order":"desc"}}]}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com