I am trying to index and search documents from a Solr core using SolrJ. Solr core is running on schemaless mode.
I have the following bean to index:
public class Product {
@Field("id")
private String id;
@Field(value="name")
private String name;
@Field(value="category")
private String category;
@Field(value="description")
private String description;
...
}
When indexing the document it creates multiValued
field strings
in managed schema:
Product p = new Product();
p.setId("0001");
p.setName("Cat 1");
p.setDescription("Description");
SolrClient client = new
HttpSolrClient("http://localhost:8983/solr/product");
client.addBean(p);
client.commit();
Which dynamically creates mult-valued set of fields in managed-schema
:
<field name="category" type="strings"/>
<field name="description" type="strings"/>
<field name="name" type="strings"/>
And when trying to get the beans after searching it throws exception:
SolrQuery query = new SolrQuery();
query.set("q", "*:*");
QueryResponse response = client.query(query);
List<Product> products = response.getBeans(Product.class);
Exception:
java.lang.IllegalArgumentException:
Can not set java.lang.String field Product.name to java.util.ArrayList
How can I resolve this and make Solr to create single valued fields?
I am using solr-6.2.1
and solr-solrj-5.5.0.jar
.