Skip to content

Arrays of strings in aggs get converted to arrays of objects #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amran99 opened this issue Sep 29, 2022 · 1 comment
Closed

Arrays of strings in aggs get converted to arrays of objects #145

amran99 opened this issue Sep 29, 2022 · 1 comment

Comments

@amran99
Copy link
Contributor

amran99 commented Sep 29, 2022

Here are 2 examples of aggregations that this issue applies to:

{ terms: { field: 'source__keyword', exclude: ['Other', 'unknown'] } }

{ filter: { query_string: { query, fields: ['title', 'body'], } } }

In both cases we get an error like this: x_content_parse_exception: [parse_exception] Reason: Array elements in include/exclude clauses should be string values, Location: undefined, Path: undefined

I managed to trace the problem to \node_modules\graphql-compose-elasticsearch\lib\elasticDSL\Aggs\Aggs.js convertAggsRules

This function converts the strings in the first example to this:
{ terms: { field: 'source__keyword', exclude: [{0: 'O', 1: 't', 2: 'h', 3: 'e', 4: 'r'}, {0: 'u', 1: 'n', 2: 'k', 3: 'n', 4: 'o', 5: 'w', 6: 'n'}] } }

We are on node version 16.16.0.

Adding this line at the start of the convertAggsRules function fixes the problem: if (typeof rules === 'string') return rules;

@nodkz
Copy link
Member

nodkz commented Sep 29, 2022

Could you please open Pull Request with proposed changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants