Get all non-full fields in ElasticsearchRepository's findAll method in Spring Data Elasticsearch

亡梦爱人 提交于 2020-07-14 12:20:23

问题


We are using we're using spring-data-elasticsearch 3.2.6.RELEASE and here is our repository :

@Repository
public interface IRepository extends ElasticsearchRepository<User, Integer> {
    List<User> findAll();
}

and here is the sample response:

[{
        "idDl": null,
        "clientName": null,
        "Address": null
    },
    {
        "idDl": 19810008,
        "clientName": "ABC",
        "Address": "NYC"
        
    }]

And we have our own custom implementation to return all values excluding certain fields, as follows: It is exposed as separate REST point. Here is the interface method

public interface IUserService {
    List<User> getFilteredUsers();
}

and it's implementation is like :

 String[] includeFields = new String[]{"idDl", "clientName"};
 String[] excludeFields = new String[]{"Address"};
 Query searchQuery = new NativeSearchQueryBuilder()
                 .withQuery(existsQuery("idDl"))
                 .withSourceFilter(new FetchSourceFilter(includeFields, excludeFields))
                 .build();
return elasticsearchRestTemplate.queryForList(searchQuery, User.class);

I want to know whether this is interfering with ElasticsearchRepository's findAll() method in any way. If not then what is the root cause.

来源:https://stackoverflow.com/questions/62771342/get-all-non-full-fields-in-elasticsearchrepositorys-findall-method-in-spring-da

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