Search code examples
javasolrsolrj

Why does Solrj SolrDocumentList (SolrDocument) hold data items as Arrays (ArrayList<>)


I am using Solrj 6.2.0 to access a local Solr core.

Everything works fine. I can search and find all the data I require.

I have one issue in that the QueryResponse getResults() method returns a SolrDocumentList, which is a collection of SolrDocument.

Each of the SolrDocument hold a single data item as an array, when I retrieve each data item I receive an ArrayList.

I have to loop through the ArrayLists single entry and return a String.

What am I doing wrong?

Is there any way to get SolrJ to return SolrDocument that holds a data item as a Non Array?


Solution

  • If you are sure the field is a single value (or you need just the first value of the collection), you can use the getFirstValue(String name) method of the SolrDocument.