multi values are getting stored in solr document by default in 5.x

大城市里の小女人 提交于 2019-12-18 09:52:14

问题


I am quite new to Solr and I have a schema.xml file where i have defined all the fields. But the problem here is the fields are storing as multiple values. I have tried the same in Solr 4.x and everything is working as expected. Am I missing something here?

<schema name="aem-solr" version="1.5">
<field name="body" type="text_general" indexed="true" stored="true" />
<field name="description" type="text_general" indexed="true" stored="true" />
<field name="contentType" type="text_general" indexed="true" stored="true" />
<field name="lastModified" type="date" indexed="true" stored="true" />
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true" />
<field name="title" type="text_general" indexed="true" stored="true" />
<field name="url" type="text_general" indexed="true" stored="true" />
<field name="publishDate" type="tdate" indexed="true" stored="true" />
<field name="sling_resource_type" type="string" indexed="true" stored="true" multiValued="true" />
<field name="tags" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true" />

Though i am using schema version 1.5 everything is storing as a multivalues as shown below

 {
    "id": "/content/geometrixx/en/company/bod",
    "title": [
      "Board of Directors"
    ],
    "url": [
      "/content/geometrixx/en/company/bod.html"
    ],
    "lastModified": [
      "2010-11-312T06:17:30Z"
    ],
    "contentType": [
      "page"
    ],
    "tags": [
      "Investor",
      "Business"
    ],
    "_version_": 1536322934890561500
  }

I tried to add multiValued= false attribute to fields but still no luck. I am using SolrJ api for connection and creating documents in Solr server.


回答1:


This might be caused by 5.x using Managed Schema by default - if the correct schema.xml file wasn't present when you started Solr for the first time, the created schema will be close to (if not) a Schemaless mode.

When a is not explicitly declared in a solrconfig.xml file, Solr implicitly uses a ManagedIndexSchemaFactory, which is by default "mutable" and keeps schema information in a managed-schema file.

You can revert to the old behavior by changing the Schema Factory back to (or add a definition for) ClassicIndexSchemaFactory in solrconfig.xml. The link also contains instruction on how you can make Solr import the old schema if you want to use the new Managed Schema factory instead:

If you have an existing Solr collection that uses ClassicIndexSchemaFactory, and you wish to convert to use a managed schema, you can simplify modify the solrconfig.xml to specify the use of the ManagedIndexSchemaFactory. Once Solr is restarted and it detects that a schema.xml file exists, but the managedSchemaResourceName file (ie: "managed-schema") does not exist, the existing schema.xml file will be renamed to schema.xml.bak and the contents are re-written to the managed schema file.



来源:https://stackoverflow.com/questions/37645464/multi-values-are-getting-stored-in-solr-document-by-default-in-5-x

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