We have documents in the range 50k-100k. We are using the ElasticsearchOperations
interface of spring-data-elasticsearch and using NativeSearchQueryBuilder()
s withSourceFilter(new FetchSourceFilter(includeFields, excludeFields))
method to return only required fields. We wanted to know whether this source filtering have any performance impact? Even if we are using simple elasticsearch query which returns all the records but having source filtering, will performance be affected? Or is it better to return all the fields? we have chosen to not to return all the fields as some of the fields can be larger in size i.e some of the fields can be list/array containing thousands of items.
Yes its actually a good idea to exclude the fields which your don't need in response as it can greatly reduce the bandwidth required to transfer the data especially when you have large fields to return.
You can also follow this discuss link to get more info, Please note it incur cost to filter it, so you may want to set store:false
options for the fields which you don't need to retrieve to further speed up filtering and it saves your disk space and reduce index time as well.
Refer store for more info.