@@ -9,6 +9,7 @@ import bodybuilder from 'bodybuilder'
99import loadCustomFilters from '../helpers/loadCustomFilters'
1010import { elasticsearch , SearchQuery } from 'storefront-query-builder'
1111import { apiError } from '../lib/util'
12+ import querystring from 'querystring'
1213
1314async function _cacheStorageHandler ( config , result , hash , tags ) {
1415 if ( config . server . useOutputCache && cache ) {
@@ -84,7 +85,7 @@ export default ({config, db}) => async function (req, res, body) {
8485 }
8586
8687 // pass the request to elasticsearch
87- const elasticBackendUrl = adjustBackendProxyUrl ( req , indexName , entityType , config )
88+ let elasticBackendUrl = adjustBackendProxyUrl ( req , indexName , entityType , config )
8889 const userToken = requestBody . groupToken
8990
9091 // Decode token and get group id
@@ -110,6 +111,17 @@ export default ({config, db}) => async function (req, res, body) {
110111 const s = Date . now ( )
111112 const reqHash = sha3_224 ( `${ JSON . stringify ( requestBody ) } ${ req . url } ` )
112113 const dynamicRequestHandler = ( ) => {
114+ if ( typeof config . entities [ entityType ] === 'object' ) {
115+ const urlParts = elasticBackendUrl . split ( '?' )
116+ const { includeFields, excludeFields } = config . entities [ entityType ]
117+ const urlParams = {
118+ ...req . query ,
119+ _source_include : includeFields ,
120+ _source_exclude : excludeFields
121+ }
122+ elasticBackendUrl = `${ urlParts [ 0 ] } ?${ querystring . stringify ( urlParams ) } `
123+ }
124+
113125 request ( { // do the elasticsearch request
114126 uri : elasticBackendUrl ,
115127 method : req . method ,
0 commit comments