Spring anomaly of dynamic fields solr

I'm trying to make a query that retrieves one specific field from the document, I do not get a runtime error while the query is executing, but I do not get 3 fields that I have to extract from the query, only the date and origin, but not the variable that should return all of them are zero. How can I select the fields that I want to receive only in the request?

my query currently looks like this:

  @Query(value = "id:?0", fields = {"?1","date","origin"})
   List<Data> getRecord(String id,String field);
+4
source share
1 answer

Introduction

Reading your comments. I see that there is a bit of confusion as to what SolrJ and Spring Data are for Apache Solr .

SolrJ - Solr ( ).

SolrJ - API, Java Solr. SolrJ Solr Solr .

Spring Apache Solr Spring Data Apache Solr Search Server Spring ( Solr SolrJ).

Solr Spring Data ver. 1.2.0.RELEASE SolrJ 4.7.2, Solr 6.2.0 (, SolrCloud).

, Solr SolrJ (, , ).

, Solr v.6.2.1 SolrJ 6.2.1, , , Solr Spring 2.1.3.RELEASE( SolrJ 5.5.0).

<dependencies>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-solr</artifactId>
        <version>2.1.3.RELEASE</version>
    </dependency>
</dependencies>

, , , Solr Data .

, Solr Spring Data, Repository, RepositoryImpl, , SolrJ.

@Component
public class ProductsRepositoryImpl implements ProductsRepositoryCustom {

  @Autowired
  private SolrServer   solrServer;

  public ProductsRepositoryImpl() {};

  public ProductsRepositoryImpl(SolrServer solrServer) {
    this.solrServer = solrServer;
  }

  public List<Map<String, Object>> findFields(String id, List<String> fields)
  {
    SolrQuery solrQuery = new SolrQuery("id:" + id);
    solrQuery.setFields(fields.toArray(new String[0]));
    try {
      QueryResponse response = this.solrServer.query(solrQuery);
      return response.getResults()
              .stream()
              .map(d ->
                {
                  return d.entrySet()
                          .stream()
                          .filter(e -> fields.contains(e.getKey()))
                          .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                }).collect(Collectors.toList());
    } catch (SolrServerException e) {
      // TODO Auto-generated catch block
    }
    return Collections.emptyList();
  }

}
+7

Source: https://habr.com/ru/post/1678142/


All Articles