ParseException — Cannot Parse Query Syntax Error in Solr Search

Errors
Solr Error Guide

ParseException — Cannot Parse Query

Your search query has a typo or formatting mistake that Solr cannot understand. This guide shows you exactly what went wrong, how to spot it, and how to fix it — with real examples.


What Happened?

The Error: Cannot parse '...': Encountered " ":" ": "" at line 1, column N

You sent a search query to Solr that contains a syntax mistake. Solr tried to read your query like a sentence, but hit a character (like a :) that doesn't make sense in that position. It's like writing "Find me all blue AND" — the sentence just stops mid-thought.

Key difference: This error happens when searching (querying), not when adding data. It's your search request that's broken, not your data.


Real-World Example

Here's an actual broken query from a real Solr log:

The broken query Solr received:ss_bundle:url_builderORfq=ss_bundle:tocWhat went wrong:ss_bundle:url_builderORfq=ss_bundle:tocA missing space turned " OR fq=..." into the word "ORfq=..."The second : in "ORfq=ss_bundle:toc" confused the parser.

The application code was supposed to send two separate things: a query q=ss_bundle:url_builder and a filter fq=ss_bundle:toc. But due to a bug, they got glued together into one broken string.


Common Causes

Missing Spaces Around Operators

Solr operators like AND, OR, NOT need spaces on both sides. catANDdog is one word to Solr, not a boolean search.

: Unescaped Special Characters

Characters like : ( ) [ ] + - have special meaning in Solr queries. If user input contains them, they must be escaped with a backslash: \:

String Concatenation Bugs

Application code that builds query URLs by concatenating strings often forgets the & separator between parameters, mashing q= and fq= into one broken value.

() Unbalanced Parentheses or Quotes

Every ( needs a matching ), and every " needs a closing ". A query like (title:hello without a closing parenthesis will fail.


How to Read the Error Message

The error message tells you exactly where it broke. Let's decode it:

Decoding the Error MessageCannot parse 'ss_bundle:url_builderORfq=ss_bundle:toc': Encountered " ":" at column 35Cannot parse '...'Shows you the EXACT query string that failed — look at it carefully!Encountered " ":" The character that confused Solr — here it's a colon : in an unexpected positionat line 1, column 35Count 35 characters into your query — that's where the problem is


How to Fix It

Step 1
Read the error message
Step 2
Find it in your code
Step 3
Fix the query builder
Step 4
Test the query

Fix 1 — Properly Separate Query Parameters

If your query and filter query got concatenated, they need to be separate URL parameters:

// WRONG — parameters mashed together
/solr/myindex/select?q=ss_bundle:url_builderORfq=ss_bundle:toc

// CORRECT — separate q and fq parameters with &
/solr/myindex/select?q=ss_bundle:url_builder&fq=ss_bundle:toc

Fix 2 — Add Spaces Around Boolean Operators

// WRONG — no spaces around OR
q=title:helloORtitle:world

// CORRECT — spaces around OR
q=title:hello OR title:world

Fix 3 — Escape Special Characters in User Input

If your users type search terms that contain colons, parentheses, or other special characters, you must escape them before sending to Solr:

// Special characters that need escaping in Solr queries:
// + - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

// PHP example — escape user input:
$userQuery = preg_replace(
    '/([+\-!(){}\[\]^"~*?:\\\\/]|&&|\|\|)/',
    '\\\\$1',
    $userQuery
);
# Python example:
import re
user_query = re.sub(r'([+\-!(){}\[\]^"~*?:\\/]|&&|\|\|)', r'\\\1', user_query)

Fix 4 — Balance Your Parentheses and Quotes

// WRONG — unclosed parenthesis
q=(title:hello OR title:world

// CORRECT — balanced parentheses
q=(title:hello OR title:world)

// WRONG — unclosed quote
q=title:"hello world

// CORRECT — balanced quotes
q=title:"hello world"

Solr Special Characters Cheat Sheet

Character Meaning in Solr To Use Literally
: Field separator (field:value) \:
( ) Grouping \( \)
" " Exact phrase search \"
+ - Required / excluded terms \+ \-
* ? Wildcard characters \* \?
[ ] Range queries \[ \]
~ Fuzzy / proximity search \~

How to Prevent This

Use a Solr Client Library

Libraries like SolrJ (Java), Solarium (PHP), or pysolr (Python) handle query escaping and parameter building for you. Don't build raw query URLs by hand.

Always Escape User Input

Never put raw user search terms directly into a Solr query. Always escape special characters first, or use the eDisMax query parser which is more forgiving with user input.

Log and Test Your Queries

Log the full query URL your app sends to Solr. When errors happen, check the Error Audit dashboard — it shows the exact query that failed, so you can spot the mistake immediately.


Need More Help?

Check your Error Audit for the exact query that failed, or reach out to the Opensolr team.