Spring solr dynamic fields anotation

Viewed 1367

I'm trying to do a query like that retrieves one specific field from the document, i don't a get runtime error when executing the query but i don't get the 3 fields i'm supposed to retrieve from the query, just date and origin, but no the variable, the one that is supposed to return all of them are nulls. How i can select the fields i only want to retrieve in a query?

currently my query looks like this:

  @Query(value = "id:?0", fields = {"?1","date","origin"})
   List<Data> getRecord(String id,String field);
2 Answers

Yes you can do this using SimpleQuery Object and Criteria respectively.

Create a Custom implementation class for the method you want to query from the repository interface and do as follows .

https://www.petrikainulainen.net/programming/solr/spring-data-solr-tutorial-dynamic-queries/

  @Resource private SolrTemplate solrTemplate; // Create a SolrTemplate Bean


String QueryString = "*:*"; // all search query
String[] fields = {"Flight", "Hotel", "Car", "Bike"};
SimpleQuery query = new SimpleQuery(QueryString , new SolrPageRequest(0,10));
query.addProjectionOnFields(fields);
FilterQuery fq = new SimpleFilterQuery(new Criteria("Car").is(“Ford”)); // any Filter or criteria to build
query.addFilterQuery(fq);
Page<SolrDocumentPojo> resultPage= solrTemplate.query("CoreName ",queryString,Model.class);
Related