/** * 打印SearchRequest请求DSL * * @param transport transport * @param searchRequest searchRequest * @return ByteArrayOutputStream */ public static ByteArrayOutputStream printDSL(ElasticsearchTransport transport, SearchRequest searchRequest){ try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); JsonGenerator generator = transport.jsonpMapper().jsonProvider().createGenerator(baos)) { searchRequest.serialize(generator, transport.jsonpMapper()); return baos; } catch (Exception e) { log.error("print SearchRequest DSL error: {}", e.getMessage(), e); } return null; }
调用方式:
builder.index(indexList).allowNoIndices(true); SearchRequest searchRequest = builder.build(); SearchResponseresponse = esClient.search(searchRequest, HashMap.class);
EsUtils.printSearchRequestDSL(esClient._transport(), searchRequest)