Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit d959301

Browse files
committed
fix(elasticsearch): use configutation values for source fields
1 parent c333ce9 commit d959301

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/api/catalog.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import bodybuilder from 'bodybuilder'
99
import loadCustomFilters from '../helpers/loadCustomFilters'
1010
import { elasticsearch, SearchQuery } from 'storefront-query-builder'
1111
import { apiError } from '../lib/util'
12+
import querystring from 'querystring'
1213

1314
async 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

Comments
 (0)