Only in AWS Lambda: Json_parse_exception Illegal character CTRL-CHAR code 31

Hi all,

I'm using the python Elasticsearch library to query an index. When I run the search on AWS Lambda I get this json_parse_execption:

"errorMessage": "TransportError(500, 'json_parse_exception', 'Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\\\r, \\\\n, \\\\t) is allowed between tokens\\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@2841b17e; line: 1, column: 2]')",
"errorType": "TransportError"

However, when I run the code locally, the same body argument works perfectly. Additionally, I can use this syntax in Kibana and get correct results.

        posts = {
            "aggs": {
                "id": {
                    "terms": {
                        "field": "content.id"
                    },
                    "aggregations": {
                        "eng_avg": {
                            "avg": {
                                "field": "content.engagement"
                            }
                        },
                        "fol_avg": {
                            "avg": {
                                "field": "content.followers"
                            }
                        }
                    }
                }
            },
            "query": {
                "range": {
                    "content.timestamp": {
                        "gte": "now-90d"
                    }
                }
            }, "size": 0
        }

es_results = es_client.search(index="social_posts", body=posts)

I've been staring at this Json body for a while and can't see any issues with it... maybe I missed something?

When I test the code in AWS Lambda without any body=<json> results are returned... so the ES client seems to be talking to the Custer.

Any thoughts would be lovely. Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.