I'm trying to run a solr query at the start of my tests to get a bunch of listings which I will then use in the test run.
If I make this request in Chrome I get the json response:
MYAPIDOMAIN/solr/listings/select?q=category:commercial+AND+property_type:office&fl=listing_id,listing_status&group=true&group.main=true&group.field=listing_status&group.limit=1&rows=100&wt=json&indent=on
In the tests I am using the Spring RestTemplate to make the call then I parse the JSON response, it works for some of my queries but for this one I just get an error back:
"responseHeader":{
"status":400,
"QTime":7,
"params":{
"q":"category:commercial%2BAND%2Bproperty_type:office",
"group.main":"true",
"indent":"on",
"fl":"listing_id,listing_status",
"group.limit":"1",
"rows":"100",
"wt":"json",
"group.field":"listing_status",
"group":"true"}},
"error":{
"msg":"org.apache.solr.search.SyntaxError: Cannot parse 'category:commercial%2BAND%2Bproperty_type:office': Encountered \" \":\" \": \"\" at line 1, column 41.\nWas expecting one of:\n <EOF> \n <AND> ...\n <OR> ...\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n \"^\" ...\n <QUOTED> ...\n <TERM> ...\n <FUZZY_SLOP> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <LPARAMS> ...\n <NUMBER> ...\n ",
"code":400}}
I don't know anything about solr queries I was just given them to use in the tests, obviously it's an encoding problem but I don't know where. I've tried using the URLEncoder, I've found some online url encoders but nothing seems to get this working.
Can someone please tell me what's wrong with this? I have another 5 queries I need to make so I really need a fix.
Thank you
I tried the same on my local and found the same error, it is due to the encoded value %2B -> + in your syntax. And it is breaking the parser.
So you could use the space instead of + which will change to %20. Then it should be working fine.