Jest ElasticSearch Search API命中映射 [英] Jest ElasticSearch Search API Hits mapping
问题描述
我对弹性搜索非常陌生
我正在尝试理解以下代码:
I'm trying to understanding the below code :
List<Hit<Talk, Void>> hits = result.getHits(Talk.class);
for (Hit<Talk, Void> hit: hits) {
Talk talk = hit.source;
log.info(talk.getTitle());
}
这直接来自: https://www.elastic.co/blog/found-java-clients-for-elasticsearch
我的问题是,Java如何知道将哪个字段映射到什么变量.
My question is , how does Java know what field to map to what variable.
从本质上讲,Java如何知道将属性"title"与Talk类的成员变量"title"进行匹配.
Essentially , how does Java know , say to match the property "title" to the member variable "title" of the Talk class.
欢呼
推荐答案
在页面中,它提到 Talk
类是一个Bean.Bean实现 Serializable
.调用 result.getHits
时,请注意如何将 Talk.class
对象传递到方法中.这意味着您基本上会将匹配内容反序列化为 Talk
实例.通过JEST Hit
类的结构,这就是从Elastisearch响应中反序列化 Talk
实例后如何访问它们的方式.
In the page it mentions that the Talk
class is a Bean. Beans implement Serializable
. When result.getHits
is called, notice how Talk.class
object is passed into the method. That means you are basically deserializing the hits into Talk
instances. With how the JEST Hit
class is structured, that is how you access the Talk
instances after they are deserialized from the Elastisearch response.
有关Bean的更多信息,请参见此处:什么是JavaBean?
For more information on Beans, see here: What is a JavaBean exactly?
这篇关于Jest ElasticSearch Search API命中映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!