graphql-compose / graphql-compose-elasticsearch

Hide Elastic Search REST API behind GraphQL.
https://graphql-compose.herokuapp.com/elasticsearch/
MIT License
583 stars 77 forks source link

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

Closed amran99 closed 2 years ago

amran99 commented 2 years ago

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 commented 2 years ago

Could you please open Pull Request with proposed changes