Solr:没有明确设置默认值的字段的默认值是什么?
我正在使用 Solr 的 schema.xml,并且我知道我可以使用“default”属性来指定默认值,如果尚未提供给定字段的值,则使用该默认值。但是,假设我选择不设置“默认”属性,那么 Solr 会回退到哪个默认值?
我认为我用于给定字段的字段类型将具有将使用的默认值,但我没有成功找到有关此的任何详细信息。或者,我认为不提供值并且不有效地设置默认值就好像特定文档不存在该字段一样。
但是,我不确定,我想知道:-)
更新 1
据我所知,如果没有默认值,Solr 只是抛出一个错误并返回错误 400“错误请求”值已设置,但尚未为给定字段提供值。换句话说,如果未提供任何值且 schema.xml 中未设置默认值,Solr 似乎不会应用任何“后备”默认值。
更新2
我上面的更新似乎是错误的。如果没有为某个字段提供值,并且没有为该字段设置默认值,那么 Solr 只会将该字段视为该特定文档不存在。当然,如果该字段是必需的,则此行为不适用。
I'm working with Solr's schema.xml, and I know that I can use the 'default' attribute to specify a default value which is to be used if a value for a given field has not been provided. However, say that I choose not to set the 'default' attribute, which default value will Solr then fall back to?
I would think that the field type which I've used for the given field would have a default value which would be used, but I have had not success finding any details about this. Alternatively, I'd think that not providing a value and not setting a default value effectively would be as if that field does not exist for the particular document.
However, I'm not sure and I'd like to know :-)
UPDATE 1
As far as I can see, Solr just throws an error and returns an error 400 "Bad Request" if no default value has been set and no value has been provided for a given field. In other words, Solr does not seem to apply any "fallback" default values in case no value is provided and no default value has been set in schema.xml.
UPDATE 2
My above update seems to be wrong. If no value has been provided for a field and no default value has been set for that field, then Solr will just treat the field as if it does not exist for that particular document. This behaviour does, of course, not apply if the field is required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在索引期间不提供字段值,solr 将使用 schema.xml 文件中定义的默认值。如果未定义默认值,solr 会忽略该字段。如果在 schema.xml 中将字段标记为必填字段 - solr 将拒绝该文档并出现错误。
例子:
If you don't supply value for field during indexing, solr will use default value as defined in schema.xml file. If default is not defined, solr ignores this field. If field is marked as required in schema.xml - solr will reject this document with error.
Example:
根据我的经验,如果您在加载文档时未指定字段,那么 Solr 在索引文档时将忽略该字段,并且您的语句“未提供值且未有效设置默认值将如同该字段不存在一样”对于特定文档”是正确的。问题是您只需指定要为给定文档添加的字段。查看 Solr 发行版附带的 xml 示例文档,以查看包含不同字段集的文件的一些示例。
From my experience if you do not specify a field when loading documents, then Solr will just ignore that field when it indexes the document and your statement "not providing a value and not setting a default value effectively would be as if that field does not exist for the particular document" is true. The catch is that you need to only specify the fields that you want to add for the given document. Check out the xml exampledocs that come with the Solr Distribution to see some examples of files that contain differing field sets.
尽管您在名为
schema.xml
的文件中定义字段,但 Solr 文档实际上是无模式。这意味着 Solr 引擎(Lucene)内部没有每个文档必须具有的字段的任何定义。使用 Lucene,您可以轻松地将字段myCompletelyNewField
添加到任何文档,而不会影响其他文档。那么,schema.xml 的原因是什么? Solr/Lucene 中的每个字段都有多个属性,其中最著名的是
索引
和存储
属性。此外,所有字段都必须绑定到某些内部数据类型和处理单元。例如,id
字段必须存储为字符串,description
字段必须使用一些英语分析器进行分析,使用停用词过滤器进行清理等等。在add
请求中将所有这些信息传递给 Solr 非常不方便。由于您知道将使用哪些字段并且可以访问 Solr 服务器(至少在大多数情况下),因此将所有这些信息移动到单独的文件中要容易得多。这个文件是schema.xml。因此,现在您必须了解
schema.xml
定义了允许的字段,但不定义文档中必须存在的字段。required
和default
等其他修饰符只是在将文档添加到索引之前提供附加服务。即required
将强制 Solr 的“前端”检查新文档中是否存在指定字段。如果是,则进一步传递文档,否则拒绝新文档。default
会导致相同的检查,但如果字段不存在,则会添加默认值并进一步传递文档。至于您的“错误请求”错误,我猜您在其他地方有错误,例如,您在不允许的情况下添加了空字段(字段存在,但其值为“”),或者为该字段使用了不正确的值,或者有一些添加了与实际字段相矛盾的其他修饰符。
Though you define fields in file called
schema.xml
, Solr documents are in fact schemeless. That means that internally Solr engine (Lucene) doesn't have any definitions of fields each document must have. With Lucene you can easily add fieldmyCompletelyNewField
to any document without affecting other documents anyhow.So, what is the reason for
schema.xml
? Each field in Solr/Lucene has several properties, most known of them areindexed
andstored
properties. Moreover, all fields must be bound to some internal data type and processing units. For example,id
field must be stored as string, anddescription
field must be analyzed with some English analyzer, cleaned with stopwords filter and so on. Passing all this information in theadd
request to Solr is very inconvenient. Since you know what fields you will use and have access to Solr server (in most cases, at least), it is much easier to move all this info to separate file. And this file isschema.xml
.So, now you must understand that
schema.xml
define fields that are allowed, but not fields that must exist in document. Additional modifiers likerequired
anddefault
just provide additional services before adding documents to the index. I.e.required
will force Solr's "front-end" to check whether specified field exists in new document. If yes, it passes document further, otherwise it rejects new doc.default
causes same check, but if field is absent, it adds it with default values and passes document further.As for your "Bad Request" error, I guess you have error somewhere else, e.g. you add empty field (field exist, but its value is "") while it is not allowed, or use incorrect value for the field, or have some other modifiers that contradict actual field added.