Search code examples
solrsolrj

SolrJ: SolrQuery.setFields method for dynamic field


I have a SOLR schema with 50+ fields and 5 of them are dynamic fields.
One of the dynamic fields is "skuForSize_*" and I need to retrieve this dynamic field along with other static fields.
I am using setFields() method of SolrQuery class. It works fine with static fields but could not fetch dynamic fields. Is there any other way to fetch dynamic fields?


Solution

  • skuForSize_* mask any field that matches your prefix. In example you could save a document with a field skuForSize_myField1 that is not present in the schema.xml and it will work. For query you need to explicitly enumerate the fields skuForSize_field1,skuForSize_field2 ... or just use a copy field in ex: textSkuForSize and search on it.