solarium
solarium copied to clipboard
For labelled single nested child documents update functionality gives error for xml format
Solarium version(s) affected: 6.3.1 Solr version: 8.6.3 Solr mode: standalone / cloud
Description
For labelled single nested child documents if passed multidimension array for update functionality gives
missing required field
issues for xml format
Solr HTTP error: OK (400) { "responseHeader":{ "status":400, "QTime":183}, "error":{ "metadata":[ "error-class","org.apache.solr.common.SolrException", "root-error-class","org.apache.solr.common.SolrException"], "msg":"[doc=null] missing required field: title", "code":400}}
How to reproduce
If we try to update solr index with below data where title
is required field and have parent child relationship
$data = [
"id" => "parent1",
"title" => "Parent Document",
"children" => [
[
"id" => "child1",
"title" => "Child Document 1"
],
[
"id" => "child2",
"title" => "Child Document 2"
]
]
];
While executing update query it gives missing required field title
.
Possible Solution
} else {
$xml .= '<doc';
if ('_childDocuments_' !== $key) {
// labelled single nested child documents can't be indexed in XML, but
// we aim for forward compatibility with the proposed syntax in SOLR-16183
$xml .= ' name="'.$key.'"';
}
$xml .= '>';
foreach ($value as $k => $v) {
$xml .= $this->buildFieldsXml($k, $boost, $v, null);
}
$xml .= '</doc>';
}
Above code in src/QueryType/Update/RequestBuilder/Xml.php file line no. 306 will create xml output as follows
<doc>
<field name="id">parent1</field>
<field name="title">Parent Document</field>
<doc name="children">
<doc>
<field name="id">child1</field>
<field name="title">Child Document 1</field>
</doc>
<doc>
<field name="id">child2</field>
<field name="title">Child Document 2</field>
</doc>
<doc>
</doc>
<doc name="children">
is this section really needed?
Ideally xml should be like
<doc>
<field name="id">parent1</field>
<field name="title">Parent Document</field>
<doc>
<field name="id">child1</field>
<field name="title">Child Document 1</field>
</doc>
<doc>
<field name="id">child2</field>
<field name="title">Child Document 2</field>
</doc>
</doc>
I think, we should modify foreach loop in above code as below to fix this issue(just a suggestion)
foreach ($value as $multivalue) {
foreach ($multivalue as $k => $v) {
$xml .= $this->buildFieldsXml($k, $boost, $v, null);
}
}