On 5/3/2018 9:07 AM, Arturas Mazeika wrote: > Short question: > > How can I systematically explore the solrj functionality/API?
As Erick said, there is not an extensive programming guide. The javadocs for SolrJ classes are pretty decent, but figuring out precisely what the response objects actually contain does require experimentation. > final NamedList<Object> cluster = (NamedList<Object>) > response.get("cluster"); > final ArrayList<Object> nodes = (ArrayList<Object>) > cluster.get("live_nodes"); > final NamedList<Object> cols = (NamedList<Object>) > cluster.get("collections"); > final LinkedHashMap<String, Object> tph = (LinkedHashMap<String, Object>) > cols.get("tph"); It's possible to replace all this code with one line: LinkedHashMap<String, Object> tph = (LinkedHashMap<String, Object>) response.findRecursive("cluster", "collections", "tph"); I *did* make sure this really does work with a 7.3 cloud example, so use with confidence! > and then looking at what the keys names are, etc. Things are becoming more > difficult here, as (1) lots of functionality hides behind generic "get" > methods and (2) The containers that are returned vary from NamedList, to > anything possible (arraylist, string, hashmap, etc.) SolrJ (and Solr itself, because SolrJ is an integral part of the server) uses the NamedList object for a LOT of things. It's useful for encoding a wide range of responses and configuration information. It can, as you noticed, hold any type of object, including additional NamedList instances. There is typically a NamedList object in all response objects which contains the *entire* response. Some of the information in a response is ALSO available via sugar methods which translate parts of the full response to other data types. For instance, you can get numFound out of a query response without ripping the NamedList apart: SolrQuery q = new SolrQuery("*:*"); QueryResponse r = client.query(q); long numFound = r.getResults().getNumFound(); This value is also available from the NamedList object, but the code to obtain it is very ugly: long numF = ((SolrDocumentList) r.getResponse().get("response")).getNumFound(); If you make requests manually (possibly in a browser) with wt=json&indent=true, it only takes a little practice before you'll be able to translate what you see into the NamedList structure that the SolrJ response object will contain. You can also print the output of the toString() method on the NamedList to see the structure, but that output usually doesn't include the object types, only their values. Javadocs are a primary source of information. Exploring the responses fills in the holes. Using wt=xml instead of wt=json in manual requests actually yields more information, but json is easier to read. Thanks, Shawn