NEW

Pulse 2025 Product Roundup: From Monitoring to AI-Native Control Plane

Elasticsearch Parsing Exception - Common Causes & Fixes

parsing_exception (also surfaced as x_content_parse_exception and json_parse_exception) is returned with 400 Bad Request when Elasticsearch cannot parse the body of an API request - either because the JSON is malformed, the query DSL structure is invalid, or a field name in the body does not match what the API expects at that position. No index state is changed; the cluster is unaffected.

What This Error Means

Elasticsearch parses request bodies in two passes: first as JSON (or YAML/CBOR/Smile if specified), then as a structured object specific to the API. A parsing_exception from the first pass is a syntactic JSON error - missing comma, unmatched brace, unquoted key. From the second pass, it is a semantic error in query DSL or settings shape - using match_phrase where match is expected, putting fields at the wrong nesting level, or referencing a query type that does not exist.

The error message names the position in the body (line, column, or JSON pointer) and the parser's complaint.

Common Causes

  1. Malformed JSON (trailing comma, unquoted key, unescaped quote). How to confirm: pipe the body through jq . or python -m json.tool - parse errors localize the syntax problem.
  2. Wrong query DSL shape - e.g., { "query": { "match": "value" } } instead of { "query": { "match": { "field": "value" } } }. How to confirm: error contains "expected START_OBJECT but found VALUE_STRING" or similar XContent message.
  3. Unknown query type (typo or removed query). How to confirm: error reads unknown query [<name>]; check the Query DSL reference for the running version.
  4. Wrong nesting level for a parameter (e.g., from inside query instead of at the search body root). How to confirm: error reads unknown field [<name>].
  5. Reserved characters in field names (., [, control characters). How to confirm: error reads field name cannot contain '.' or similar.

How to Fix Parsing Exception

  1. Validate JSON syntax outside Elasticsearch:

    echo '{...}' | jq .
    

    jq reports the first syntax error with a line and column.

  2. Compare your request to the Query DSL reference. The reference shows the exact body shape for each query type.

  3. Use Kibana Dev Tools instead of hand-crafted curl calls; it autocompletes parameter names and highlights structural errors before submission.

  4. Bisect complex requests. Strip out optional clauses (aggregations, sort, highlight) until the parsing error stops, then add them back one at a time.

  5. For bulk operations, the parsing error response includes the index of the failed action. The bulk body is line-delimited JSON; a single malformed line stops parsing at that line.

  6. For field-naming issues, rename fields to avoid ., [, and control characters. Field names are restricted to ensure they map cleanly to dotted-path access.

  7. Check the breaking changes page for the running version if a query that worked previously now fails. Several query types and parameters were removed in 7.x and 8.x.

Resolve parsing_exception Automatically with Pulse

Pulse is an AI DBA for Elasticsearch and OpenSearch. When parsing_exception (or its x_content_parse_exception / json_parse_exception variants) returns 400, Pulse:

  • Captures the failing request body and parser position (line, column, or JSON pointer), distinguishes a first-pass JSON syntax error from a second-pass XContent semantics error, and attributes the request to its source client via User-Agent and source IP correlation
  • Identifies which of the five causes applies: malformed JSON (trailing comma, unquoted key), wrong query DSL shape (match taking a string instead of a { field: value } object), unknown query type, parameter at the wrong nesting level, or reserved characters in field names
  • Generates the exact remediation: the corrected JSON validated against jq, the rewritten query DSL block matching the version-specific Query DSL reference, or the field-name rename to avoid . and [
  • Groups identical failure shapes by client so the fix ships to the right service repo as a one-click PR rather than a generic "queries are broken" ticket

Pulse highlights newly-rejected query shapes immediately after a major version upgrade, which catches client codepaths that have been silently broken since query.filtered, _type, or other removed constructs disappeared.

Start a free trial to connect your cluster.

Frequently Asked Questions

Q: Can a parsing_exception cause data loss or affect other queries?
A: No. Parsing happens before any work is dispatched to shards. The failed request returns 400; no index state changes. Other queries are unaffected.

Q: How do I find which character or line caused a parsing_exception?
A: The error message includes a line and column or a JSON pointer. Pipe the request body through jq . for pure-JSON errors. For DSL-shape errors, the message names the unexpected token type (e.g., "expected START_OBJECT but found VALUE_STRING") and the path within the body.

Q: Why does my search query work in Kibana but fail with a parsing_exception in my app?
A: Most often, the app is sending a different body shape - extra escaping, missing fields, or sending strings where Elasticsearch expects objects. Capture the exact body the app sends (HTTP request log) and diff against the Kibana version.

Q: Are parsing_exception errors version-dependent?
A: Yes. Major versions remove deprecated query types and parameters; minor versions sometimes tighten validation. Always check the breaking-changes page for the source and target versions when upgrading.

Q: How do I handle parsing errors in bulk operations?
A: The bulk API uses newline-delimited JSON. A parse error on one line aborts processing at that line. The response names the line index. Repair the line and retry; previously-successful actions in earlier lines have already been applied.

Q: Can I get Elasticsearch to be more lenient about JSON parsing?
A: No, and you should not want it. Strict parsing prevents silent data corruption. Fix the malformed request instead.

Q: What's the fastest way to diagnose parsing_exception in production?
A: Pulse, the AI DBA for Elasticsearch and OpenSearch, captures the failing body and parser position, separates JSON syntax errors from query DSL shape errors, and attributes the request to the responsible client. It proposes the corrected body and ships the fix to the right service repo - faster than diffing a Kibana-working query against the app's actual outbound HTTP body.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.