Comments (6)
You can try the logger approach suggested in this stackoverflow post (second answer)
https://stackoverflow.com/questions/60849887/log-json-queries-built-through-elasticsearch-high-level-java-client-for-debuggin
I have tried this approach with below version of ES client, and it works.
co.elastic.clients
elasticsearch-java
7.16.1
from elasticsearch-java.
Part of my code
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>7.16.2</version>
</dependency>
search test
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.tingfeng.vo.IndexProductVo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class EsTest {
@Autowired
private ElasticsearchClient client;
@Test
public void search() throws Exception {
SearchRequest searchRequest = SearchRequest.of(s -> s
.index("demo")
.query(q -> q
.term(t -> t
.field("goodsId")
.value(v -> v.stringValue("1"))
)));
System.out.println("--- DSL query---:"); // How do I print DSL here??
SearchResponse<IndexProductVo> search = client.search(searchRequest, IndexProductVo.class);
for (Hit<IndexProductVo> hit : search.hits().hits()) {
System.out.println(hit.source()); // Have the results
}
}
}
"elasticsearch-java.jar" How do I print DSL here?
from elasticsearch-java.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonGenerator generator = transport.jsonpMapper().jsonProvider().createGenerator(baos);
searchRequest.serialize(generator, transport.jsonpMapper());
generator.close();
System.out.println(baos);
from elasticsearch-java.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); JsonGenerator generator = transport.jsonpMapper().jsonProvider().createGenerator(baos); searchRequest.serialize(generator, transport.jsonpMapper()); generator.close(); System.out.println(baos);
Thank's
from elasticsearch-java.
hi,
before used "elasticsearch-rest-high-level-client.jar", in SearchSourceBuilder.java can print the DSL query
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(boolQuery); ... logger.info("=====DSL====="+searchSourceBuilder.toString());
I‘m trying "elasticsearch-java.jar" , please tell me how to print the DSL SearchRequest query?
SearchRequest searchRequest = SearchRequest.of(s -> s .index(indexName) .query(q -> q .term(t -> t .field("goodsId") .value(v -> v.stringValue("1")) )));
i',m debugging. no found the record。 please help!
The toString() method is overwritten in the "elasticsearch-rest-high-level-client" version, but not in the "elasticsearch-java (8.2.2)" version. As a result, it is not easy to print DSL statements in the development test. I see that this issue is now being optimized and look forward to a new release that addresses this issue.
from elasticsearch-java.
hello @swallez
I also had this issue on "elasticsearch-java (8.1)" version.
could you please help? thank you
from elasticsearch-java.
Related Issues (20)
- The DateHistogramAggregation fails when adding the field 'name' HOT 2
- {"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406} HOT 1
- sourcesIncludes and sourcesExcludes is missing on SearchRequest HOT 2
- Required parameter K in KnnQuery HOT 6
- Inconsistent type for IndexTemplate priority HOT 2
- UpdateOperation didn't serialize the script into the request body. HOT 2
- Allow custom SpanQuery HOT 3
- I can't provide a set of synonyms when creating the analyzer HOT 7
- On the issue of termvectors queries
- Regarding termvectors query related issues HOT 1
- PutSynonymResponse: Failed to decode response HOT 2
- TermsBucketBase: doc_count_error should be doc_count_error_upper_bound HOT 1
- Read By Id: Failed to decode response
- Assign a tokenizer to a field when creating an index. 8.6.0 HOT 1
- co.elastic.clients.elasticsearch.ElasticsearchClient.delete responce nullpointerexception HOT 2
- Creating aggregation from json via supplied reader HOT 1
- Building a zero result response declares missing properties as mandatory which should be optional HOT 1
- `field_masking_span` is deprecated in ES8.0+ but still used in java client HOT 4
- Cannot parse DynamicTemplate mapping with unknown field HOT 5
- Encountering NoSuchMethodError when Creating Elasticsearch Client
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-java.