quoted format json from Solrj

爱⌒轻易说出口 提交于 2019-12-08 05:42:00

问题


It looks like the QueryResponse from Solrj has no mean to give you a quoted Json string with wt=on or not. All I received is something like this

{responseHeader={status=0,QTime=2,params= {fl=id,productName,imageFront,priceEng,priceEngExp...

Question:

1) Am I missing something here ? Or there is no way to get the json response properly from the Solr server by Solrj.

2) Now on my client, if I convert the non-quoted json string from Solrj, does it mean it was done two times, once in server time and one in the Solrj client time ?

|improve this question

回答1:


You can get JSON response by setting wt=json to the Solr query. Example URL is shown below :

localhost:8983/solr/select/?q=:&rows=10&indent=on&wt=json

You can't get JSON response using Solrj. You don't need to use Solrj for this purpose.By sending HTTP requests to the URL above, you can get json response.




回答2:


With newer versions of Solr (starting with 4.7.0) it is possible to return the query response directly in json-format. This can be done with the NoOpResponseParser.

SolrQuery query = new SolrQuery();
QueryRequest req = new QueryRequest(query);

NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser();
rawJsonResponseParser.setWriterType("json");
req.setResponseParser(rawJsonResponseParser);

NamedList<Object> resp = mySolrClient.request(req);
String jsonResponse = (String) resp.get("response");

System.out.println(jsonResponse );


来源:https://stackoverflow.com/questions/11618937/quoted-format-json-from-solrj

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!