Hector
Hector

Reputation: 5418

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?

Upvotes: 1

Views: 584

Answers (1)

Jozef Chocholacek
Jozef Chocholacek

Reputation: 2924

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.

Upvotes: 3

Related Questions