graphql-compose / graphql-compose-elasticsearch

Hide Elastic Search REST API behind GraphQL.

Home Page:https://graphql-compose.herokuapp.com/elasticsearch/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arrays of strings in aggs get converted to arrays of objects

amran99 opened this issue · comments

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;

Could you please open Pull Request with proposed changes