Skip to content

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

Closed
@amran99

Description

@amran99

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions