From 57cdb0b6b24035bc7eef2fa89ebd88c619a47fda Mon Sep 17 00:00:00 2001 From: Ajmal Sali Date: Wed, 31 Jan 2024 23:11:10 +0530 Subject: [PATCH] feat: Support for post_filter --- src/elasticDSL/Query/Query.ts | 3 +++ src/elasticDSL/SearchBody.ts | 3 +++ src/resolvers/search.ts | 22 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/elasticDSL/Query/Query.ts b/src/elasticDSL/Query/Query.ts index f95c034..e02e48b 100644 --- a/src/elasticDSL/Query/Query.ts +++ b/src/elasticDSL/Query/Query.ts @@ -116,6 +116,9 @@ export function prepareQueryInResolve( if (query.bool) { query.bool = prepareBoolInResolve(query.bool, fieldMap); } + if (query.post_filter) { + query.post_filter = prepareQueryInResolve(query.post_filter, fieldMap); + } if (query.nested && query.nested.query && query.nested.path) { query.nested.path = query.nested.path.replace(/__/g, '.'); query.nested.query = prepareQueryInResolve(query.nested.query, fieldMap); diff --git a/src/elasticDSL/SearchBody.ts b/src/elasticDSL/SearchBody.ts index ce8242b..2a63b7d 100644 --- a/src/elasticDSL/SearchBody.ts +++ b/src/elasticDSL/SearchBody.ts @@ -46,6 +46,9 @@ export function getSearchBodyITC( export function prepareBodyInResolve(body: any, fieldMap: any): { [argName: string]: any } { /* eslint-disable no-param-reassign */ + if (body.post_filter) { + body.post_filter = prepareQueryInResolve(body.post_filter, fieldMap); + } if (body.query) { body.query = prepareQueryInResolve(body.query, fieldMap); } diff --git a/src/resolvers/search.ts b/src/resolvers/search.ts index 0057174..637b571 100644 --- a/src/resolvers/search.ts +++ b/src/resolvers/search.ts @@ -68,8 +68,21 @@ export default function createSearchResolver( argsConfigMap.sort = searchITC.getField('sort'); argsConfigMap.collapse = searchITC.getField('collapse'); argsConfigMap.highlight = searchITC.getField('highlight'); + argsConfigMap.post_filter = searchITC.getField('post_filter'); + + const topLevelArgs = [ + 'q', + 'query', + 'collapse', + 'sort', + 'limit', + 'skip', + 'aggs', + 'highlight', + 'opts', + 'post_filter', + ]; - const topLevelArgs = ['q', 'query', 'collapse', 'sort', 'limit', 'skip', 'aggs', 'highlight', 'opts']; argsConfigMap.opts = schemaComposer .createInputTC({ name: `${sourceTC.getTypeName()}Opts`, @@ -146,7 +159,12 @@ export default function createSearchResolver( args.body.query = args.query; delete args.query; } - + + if (args.post_filter) { + args.body.post_filter = args.post_filter; + delete args.post_filter; + } + if (args.collapse) { args.body.collapse = args.collapse; delete args.collapse;