Solr Schemaless Mode creating fields as MultiValued

╄→гoц情女王★ 提交于 2019-12-08 06:51:11

问题


I'm using Solr 6.1 in Schemaless Mode. After creating a collection and indexing a sample data the fields created were all set to have MultiValued = true, except for unique id.

The problem is when querying this data using SolrNet it wouldn't map the result to the model correctly. The queried results is returned as an array and require all my properties in the model to be updated to ICollection type.

Is there anyway we can set these field to MultiValued = false when indexing the sample data?

An example to illustrate the problem:

1) Index a sample of the following model in Schemaless Mode:

public class TestModel
{
    [SolrUniqueKey("id")]
    public int Id { get; set; }

    [SolrField("guid")]
    public Guid Guid { get; set; }
}

2) Solr's managed-schema file will be added with the following fields

  <field name="guid" type="strings"/>
  <field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>

3) Error during querying / mapping of the model

Object of type 'System.Collections.ArrayList' cannot be converted to type

回答1:


The schemaless mode makes everything multiValued as it does not know if you have single values followed by multivalued values for the same field. So it makes all fields multivalued and also upgrades numeric types to the largest.

This is easily adjustable if you know your domain well. The whole mapping chain is defined in the solrconfig.xml's update request processor chain (add-unknown-fields-to-the-schema) and you can change the type mapping from multivalued type to an equivalent single valued type. For strings, you change the value in the defaultFieldType.



来源:https://stackoverflow.com/questions/38730035/solr-schemaless-mode-creating-fields-as-multivalued

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!