1

I am trying to return child document fields with the parent in a query's field list.

In version 7.7 of Solr, we had to specify fl=*,[child parentFilter=type:account] which would correctly return all parents' fields along with the associated child documents of type account.

In version 8.x of Solr, things changed with the introduction of _nest_path_. We are properly including both the fieldType _nest_path_ and the field _nest_path_ in the schema (it's generated by SolrJ).

<fieldType name="_nest_path_" class="solr.NestPathField" omitTermFreqAndPositions="true" omitNorms="true" maxCharsForDocValues="-1" stored="false"/>
<field name="_nest_path_" type="_nest_path_"/>

We are able to properly query on child document fields in relation to the parent, but unable to return child document fields.

In my example, I have two parent documents (account), each with 3 child documents (policy).

Here is the flat structure returned by *:*

{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":25,
    "params":{
      "q":"*:*",
      "_":"1611069992439"}},
  "response":{"numFound":8,"start":0,"maxScore":1.0,"numFoundExact":true,"docs":[
      {
        "id":"policy-1",
        "type":["policy"],
        "_version_":1689330740566687744},
      {
        "id":"policy-2",
        "type":["policy"],
        "_version_":1689330740566687744},
      {
        "id":"policy-3",
        "type":["policy"],
        "_version_":1689330740566687744},
      {
        "id":"account-1",
        "name":["Harvey John Birdman"],
        "type":["account"],
        "_version_":1689330740566687744},
      {
        "id":"policy-4",
        "type":["policy"],
        "_version_":1689330740571930624},
      {
        "id":"policy-5",
        "type":["policy"],
        "_version_":1689330740571930624},
      {
        "id":"policy-6",
        "type":["policy"],
        "_version_":1689330740571930624},
      {
        "id":"account-2",
        "name":["Billy George Zane"],
        "type":["account"],
        "_version_":1689330740571930624}]
  }}

Here is the response for q=type:account&fl=*,[child]

{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":28,
    "params":{
      "q":"type:account",
      "fl":"*,[child]",
      "_":"1611069992439"}},
  "response":{"numFound":2,"start":0,"maxScore":0.5822426,"numFoundExact":true,"docs":[
      {
        "id":"account-1",
        "name":["Harvey John Birdman"],
        "type":["account"],
        "_version_":1689330740566687744},
      {
        "id":"account-2",
        "name":["Billy George Zane"],
        "type":["account"],
        "_version_":1689330740571930624}]
  }}

And if I don't return any parent fields, I get empty results (no child data)

{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":29,
    "params":{
      "q":"type:account",
      "fl":"[child]",
      "_":"1611069992439"}},
  "response":{"numFound":2,"start":0,"maxScore":0.5822426,"numFoundExact":true,"docs":[
      {},
      {}]
  }}

I am using Spring's abstraction on SolrJ, but using SolrJ direct with the SolrInputDocument results in the same thing. Mentioning this in case there are any known bugs with either of these libraries.

Solr version = 8.5.2

SolrJ version = 8.5.2

4

0 回答 0