我正在使用 7.4 ElasticSearchClient 并查询 Elasticsearch。 我在个人资料对象中收到如下响应
"profile": {
"shards": [
{
"id": "[GArOi1iwQHGY2qpSalRgHw][hbs-search-3][0]",
"searches": [
{
"query": ["rewrite_time": 2061901,
"collector": [
{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time_in_nanos": 30527860
}
]
}
],
"aggregations": ,
"fetch": {
"type": "fetch",
"description": "",
"time_in_nanos": 2716234862,
"breakdown": {
"load_stored_fields": 4382099,
"load_source": 13298,
"load_stored_fields_count": 50,
"next_reader_count": 8,
"load_source_count": 50,
"next_reader": 96419
},
"debug": {
"stored_fields": [
"_id",
"_routing",
"_source"
]
},
"children": [
{
"type": "ExplainPhase",
"description": "",
"time_in_nanos": 2487325658,
"breakdown": {
"process_count": 50,
"process": 2487313600,
并使用 java 服务中的 co.elastic.clients.elasticsearch.SearchResponse 类来获取解析的响应,但如上述响应值“process”所示:2487313600 超出了 int 值范围,因为 SearchResponse 类具有相同类型 int 的变量
@Nullable
private final Integer process;
我尝试在客户端级别进行解析器更改
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.USE_LONG_FOR_INTS, true);
JacksonJsonpMapper jacksonJsonpMapper= new JacksonJsonpMapper(mapper);
ElasticsearchTransport transport = new RestClientTransport(restClient, jacksonJsonpMapper);
ElasticsearchClient client = new ElasticsearchClient(transport);
success = true;
return client;
需要添加任何东西才能获得该值,或者以毫秒为单位的配置文件时间
您使用的是新的 Elasticsearch Java API 客户端,并且与 Elasticsearch 8 和 8+ 兼容。这是文档:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/getting-started-java.html
对于 Elasticsearch 7.4,您应该使用旧的(已弃用)Java High Level Rest Client。这是文档:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
但在 7.15.0 版本中已弃用。
我建议使用新的 Java 客户端,这是比旧的更好的选择。它们是完全不同的库,但好消息是您不在新库中使用 ObjectMapper。您可以直接将您的课程映射到您的回复。