0

I am using Nested Document structure to index document in Solr 8.11.1. I have some of the documents which has not any child. I want a count or documents which have no nested child, how can I get it ?

ex.
{
    {
      id: "1",
      name: "my Name",
      type: "book",
      review: {
        id: "11",
        comment: "my comment1",
        type: "review"
      },
      {
        id: "12",
        comment: "my comment2",
        type: "review"
      }
    },
    {
      id: "2",
      name: "my Name2",
      type: "book",
      review: {
        id: "11",
        comment: "my comment3",
        type: "review"
      }
    },
    {
      id: "3",
      name: "my Name3",
      type: "book"
    }
}

Here expecting result document count 1 or response with document id:3.(Their is no child for id 3)

I was trying with facet query but only getting buckets.

http://localhost:8983/solr/books/select?q=type:book&json.facet={books:{type:terms,field:id,limit:-1,facet:{reviews:{domain:{blockChildren:"type:book"},type:query,q:"type:review"}}}}&rows=0&wt=XML

1 Answers1

0

All documents with nested children can be returned with:

q={!parent which='*:* AND -_nest_path_:*'}+_nest_path_:*

So all documents with no nested children is its negation:

q=!({!parent which='*:* AND -_nest_path_:*'}+_nest_path_:*)

However, that returns the parents that have no children as well as the children with no children. So we need another clause that filters out docs with that are not children, i.e. they are not on a nested path:

q=-_nest_path_:* AND !({!parent which='*:* AND -_nest_path_:*'}+_nest_path_:*)
DaveV
  • 1,876
  • 1
  • 11
  • 4