Hi Mikhail,

Adding a single nested child document isn't mentioned in the docs at all.
The ref guide for 8.11 has more elaborate examples, but doesn't show that
you can do this either. Even when only one child is added, the JSON
examples put it in an array. But it does work when you nest a JSON object
directly instead of in an array. And I do believe this behaviour is
intentional as it's part of the tests
in TestChildDocTransformerHierarchy.java.

What I'm looking for is a way to have it indexed identically with an XML
update request. Something like this seemed like a logical way to me (based
on how a single child is represented in the result with wt=xml):
<doc>
  <field name="id">1</field>
  <doc name="single_child">
    <field name="id">2</field>
  </doc>
  <field name="children">
    <doc>
      <field name="id">3</field>
    </doc>
    <doc>
      <field name="id">4</field>
    </doc>
  </field>
</doc>

When I do that, the name="single_child" is ignored (and a warning for an
invalid XML attr is logged). That doc is added as an anonymous child
instead.

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "q":"id:1",
      "fl":"id,single_child,children,[child]"}},
  "response":{"numFound":1,"start":0,"numFoundExact":true,"docs":[
      {
        "id":"1",
        "children":[
          {
            "id":"3"},

          {
            "id":"4"}]}]
  }}

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "q":"{!child of='id:1'}id:1",
      "fl":"id"}},
  "response":{"numFound":3,"start":0,"numFoundExact":true,"docs":[
      {
        "id":"2"},
      {
        "id":"3"},
      {
        "id":"4"}]
  }}

When I put only one child document in a field with the same name, it's
indexed as a "multivalued" child document.

<doc>
  <field name="id">1</field>
  <field name="single_child">
    <doc>
      <field name="id">2</field>
    </doc>
  </field>
  <field name="children">
    <doc>
      <field name="id">3</field>
    </doc>
    <doc>
      <field name="id">4</field>
    </doc>
  </field>
</doc>

{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"id:1",
      "fl":"id,single_child,children,[child]"}},
  "response":{"numFound":1,"start":0,"numFoundExact":true,"docs":[
      {
        "id":"1",
        "single_child":[
          {
            "id":"2"}],
        "children":[
          {
            "id":"3"},

          {
            "id":"4"}]}]
  }}

What I'm looking for is a way to add a single labelled child document in
XML the way you can do in JSON.

Regards,

Thomas

Op za 30 apr. 2022 om 15:29 schreef Mikhail Khludnev <m...@apache.org>:

> Hello Thomas.
>
> Isn't it covered here
>
> https://solr.apache.org/guide/8_4/indexing-nested-documents.html#xml-examples
> ?
>
> сб, 30 апр. 2022 г., 0:18 Thomas Corthals <tho...@klascement.net>:
>
> > Hi,
> >
> >
> > In a JSON request, you can add nested child documents as a single
> document
> > or an array of documents.
> >
> >
> > JSON data:
> >
> > {
> >   "id": "1",
> >   "single_child": {
> >     "id": "2"
> >   },
> >   "children": [{
> >     "id": "3"
> >   },
> >   {
> >     "id": "4"
> >   }]
> > }
> >
> >
> > Response:
> >
> > {
> >   "responseHeader":{
> >     "status":0,
> >     "QTime":1,
> >     "params":{
> >       "q":"id:1",
> >       "fl":"id,single_child,children,[child]"}},
> >   "response":{"numFound":1,"start":0,"numFoundExact":true,"docs":[
> >       {
> >         "id":"1",
> >         "single_child":
> >         {
> >           "id":"2"},
> >         "children":[
> >           {
> >             "id":"3"},
> >
> >           {
> >             "id":"4"}]}]
> >   }}
> >
> >
> > I'm trying to achieve the same with an XML request. What is the correct
> > syntax for adding that single child as a labelled nested document in XML?
> >
> >
> > Kind regards,
> >
> >
> > Thomas
> >
>

Reply via email to