0

I'm new on lucence, solr queries, I have doubts about how to make a query to nested documents.

I have nested document indexed, as below

[
  {
    "id": "1",
    "title": "Solr1",
    "_childDocuments_": [
      {
        "id": "2",
        "title": "Solr2",
        "_childDocuments_": [
          {
            "id": "3",
            "title": "Solr3",
            "_childDocuments_": [
              {
                "id": "4",
                "title": "SolrCloud supports it"
              }
            ],
            "something_else":"irrelevant"
          }
        ],
        "something_else":"irrelevant"
      }
    ],
    "something_else":"irrelevant"
  },
  {
    "id": "5",
    "title": Solr5",
    "_childDocuments_": [
      {
        "id": "6",
        "title": "SolrCloud here as well"
      }
    ]
  }
]

How do I search title:SolrCloud, and listed all children's parents? Such as

[
  {
    "id": "1",
    "title": "Solr1",
    "_childDocuments_": [
      {
        "id": "2",
        "title": "Solr2",
        "_childDocuments_": [
          {
            "id": "3",
            "title": "Solr3",
            "_childDocuments_": [
              {
                "id": "4",
                "title": "SolrCloud supports it"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "id": "5",
    "title": Solr5",
    "_childDocuments_": [
      {
        "id": "6",
        "title": "SolrCloud here as well"
      }
    ]
  }
]

which listed all parents of document 4(Sorl1, Solr2, Solr3) and document 6(Solr5). And the depth of documents is not constants.

Neil
  • 2,714
  • 11
  • 29
  • 45

1 Answers1

0

My current solution is that massaging data, add trace into original data, so I will know document come from. such as

[
  {
    "id": "1",
    "title": "Solr1",
    "_childDocuments_": [
      {
        "id": "2",
        "title": "Solr2",
        **"parent_id":"1",**
        **"trace":"Solr1",**
        "_childDocuments_": [
          {
            "id": "3",
            "title": "Solr3",
            **"parent_id":"2",**
            **"trace":"Solr1/Solr2",**
            "_childDocuments_": [
              {
                "id": "4",
                "title": "SolrCloud supports it"
                **"parent_id":"3",**
                **"trace":"Solr1/Solr2/Solr3",**
              }
            ],
            "something_else":"irrelevant"
          }
        ],
        "something_else":"irrelevant"
      }
    ],
    "something_else":"irrelevant"
  },
  {
    "id": "5",
    "title": Solr5",
    "_childDocuments_": [
      {
        "id": "6",
        **"parent_id":"5",**
        **"trace":"Solr5",**
        "title": "SolrCloud here as well"
      }
    ]
  }
]

So after indexed, I could know who's parent document from result.

Could someone agree on this? Looking for better solution than this.

Neil
  • 2,714
  • 11
  • 29
  • 45