On 1/8/2018 10:23 AM, Deepak Goel wrote: > *I am trying to search for documents in my collection (Shakespeare). The > code is as follows:* > > SolrClient client = new HttpSolrClient.Builder(" > http://localhost:8983/solr/shakespeare").build(); > > SolrDocument doc = client.getById("2"); > *However this does not return any document. What mistake am I making?*
The getById method accesses the handler named "/get", normally defined with the RealTimeGetHandler class. In recent Solr versions, the /get handler is defined implicitly and does not have to be configured, but in older versions (not sure which ones) you do need to have it in solrconfig.xml. I didn't expect your code to work because getById method returns a SolrDocumentList and you have SolrDocument, but apparently this actually does work. I have tried code very similar to yours against the techproducts example in version 7.1, and it works perfectly. I will share the exact code I tried and what results I got below. What code have you tried after the code you've shared? How are you determining that no document is returned? Are there any error messages logged by the client code or Solr? If there are, can you share them? Do you have a document in the shakespeare index that has the value "2" in whatever field is the uniqueKey? Does the schema have a uniqueKey defined? Can you find the entry in solr.log that logs the query and share that entire log entry? Code: public static void main(String[] args) throws SolrServerException, IOException { String baseUrl = "http://localhost:8983/solr/techproducts"; SolrClient client = new HttpSolrClient.Builder(baseUrl).build(); SolrDocument doc = client.getById("SP2514N"); System.out.println(doc.getFieldValue("name")); } Console log from that code: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133 Including the collection/core name in the URL is an older way of writing SolrJ code. It works well, but multiple collections can be accessed through one client object if you change it and your SolrJ version is new enough. Thanks, Shawn