1

I was working on the POC of accessing the solr via the microservices using spring boot. I am using the Rest template to connect the solr . My query is can we customize the response that solr returns ?.

For Example:

solrUri="http://localhost:8983/solr/microServicesPOC/select?q=:&wt=json"

When we access the above url, the response solr returns has the docuemnts of fields. I need to get the results in the format of my Product pojo.

Snippet:

resEntity = solrConfig.getRestTemplate().exchange(solrUri,HttpMethod.POST,entity , Product.class);

To achieve from the above way of rest template, I need the solr to return response in Product format. Is it possible from SOlr?

I am not using the solrTemplate or the solrJ. I want the customization from the solr side not on the service side .

Tried customizing the searchHandler ,Writing DocTransformer but none of the methods worked .

  • How does Solr know what your Product type looks like? – MatsLindh Dec 23 '18 at 08:08
  • I want to customize the search response the solr returns. – Syed Ghouse Habib Dec 23 '18 at 08:19
  • Why do you use rest directly. Have you ever had a look at the spring data solr documentation: https://docs.spring.io/spring-data/solr/docs/4.0.3.RELEASE/reference/html/ – Simon Martinelli Dec 23 '18 at 11:30
  • Yes I had tried that, but our current inplementation has the approach of above way. – Syed Ghouse Habib Dec 23 '18 at 16:11
  • You could do that if you could write your own custom ResponseWriter but I would insist that it's a bad choice for several reasons - supportability, complicated deployment to name a few. Prefer to go for custom layer between that will do a transformation – Mysterion Dec 23 '18 at 16:34

0 Answers0