Jest ElasticSearch Search API Hits mapping

这一生的挚爱 提交于 2019-12-25 18:13:19

问题


I'm extremely new to elastic search

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());
        }

This is directly taken from : https://www.elastic.co/blog/found-java-clients-for-elasticsearch

My question is , how does Java know what field to map to what variable.

Essentially , how does Java know , say to match the property "title" to the member variable "title" of the Talk class.

Cheers


回答1:


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.

For more information on Beans, see here: What is a JavaBean exactly?



来源:https://stackoverflow.com/questions/44557382/jest-elasticsearch-search-api-hits-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!