Search query with java rest client


(Ankur Singla) #1

I am using rest client api for search query but in response i am getting exception of invalid character exception. I am looking for examples to check my format but did not find any.
My code is -

    String body = "{" +
    					 "\"query\":"+"\"{"+"\"prefix"+  
    					 "\":\"{"+"\"search\":"+ 
    					 "\"{"+"\"value\"ank"+"\"}"+        		        
    	       		     "\"}"+"\"}"+"\"}";
    		
    		queryBody.append(body);
    		
    		HttpEntity entity = new NStringEntity(queryBody.toString(), ContentType.APPLICATION_JSON);

    		Response restResponse = client.performRequest("GET", "/searchable/_search?pretty-d"+body, Collections.emptyMap());

Exception
illegal character in query at index 28: /searchable/_search?pretty-d{"query":"{"prefix":"{"search":"{"value"ank"}"}"}"}

Help me out I have an emergency!!!!!!


(David Pilato) #2

Remove ?pretty-d


(Val Crettaz) #3

With GET he still needs to pass the JSON query with the source query string parameter

and he has one too many double quote in "value"ank"


(Ankur Singla) #4

still i am getting same exception

java.net.URISyntaxException: Illegal character in path at index 19: /searchable/_search{"query":"{"prefix":"{"search":"{"value"ank"}"}"}"}


(Ankur Singla) #5

I think i missed the colon ":"

I added but still same exception do i need to remove double quotes too?

Illegal character in query at index 28: /searchable/_search?pretty-d{"query":"{"prefix":"{"search":"{"value":"ank"}"}"}"}


(Ankur Singla) #6

Changed my format as

{"query":{"prefix":{"search":{"value":"ank"}}}}

but still same error do i need to change anything else

Caused by: java.net.URISyntaxException: Illegal character in path at index 21: /searchable/_search-d{"query":{"prefix":{"search":{"value":"ank"}}}}


(system) #7

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