Search code examples
solrpojosolrj

solrj: using a POJO with non-string fields


I'm brand-new to solr and solrj, and investigating them as a potential platform for a search-oriented app.

We have a lot of data in a MongoDB instance, with pojos defined in Java. I'd like to migrate the data over to solr using my existing MongoDB POJOs, by adding solrj @Field annotations.

This seems to work fine for String fields, but not so much for ints:

org.apache.solr.common.SolrException: ERRORunknown_field_downloadsCount

Is there a simple way to get solrj to automatically map ints (and potentially other non-string types) to String?

I guess I could just alter my class with something like:

@Field("downloadCount")
String getDownloadCountAsString() { return Integer.toString(downloadCount); }

But I was wondering if there was a more robust solution.


Solution

  • The error suggests that you don't have a 'downloadsCount' field in the Solr schema. Check your schema.xml.