如何在 Spring Boot 项目中在 ElasticSearch 中进行源过滤? [英] How to do source filtering in ElasticSearch in spring boot project?

查看:99
本文介绍了如何在 Spring Boot 项目中在 ElasticSearch 中进行源过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 spring-data-elasticsearch 使 Elastic 搜索查询仅返回 spring boot 项目中的特定字段?我们正在使用最新版本的 spring boot 和弹性搜索.使用elasticsearchtemplate或elasticsearchresttemplate哪个模板以及它们与java高级rest客户端有何不同?

how to make Elastic search query return only particular fields in spring boot project using spring-data-elasticsearch? we are using most recent versions of spring boot and elastic search. Which template to use elasticsearchtemplate or elasticsearchresttemplate and how both of them are different from java high level rest client?

推荐答案

如果您使用的是 ElasticsearchOperations 接口(其中 ElasticsearchTemplateElasticsearchRestTemplate实现),用于定义要执行的查询的 Query 接口有一个 addSourceFilter 方法,您可以在其中添加一个 FetchSourceFilter 来定义要从 Elasticsearch 中检索的字段,其他字段将为空.

If you are using the ElasticsearchOperations interface (which ElasticsearchTemplate and ElasticsearchRestTemplate implement), the Query interface that is used to define the query to execute has a method addSourceFilter where you can add a FetchSourceFilter which defines the fields to be retrieved from Elasticsearch, the other fields will be null.

这篇关于如何在 Spring Boot 项目中在 ElasticSearch 中进行源过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆