首页 > 解决方案 > solr 8 嵌套文档/如何使用 Child Doc Transfomer

问题描述

从文档草稿中我可以看到 SOLR 8 对嵌套文档进行了一些改进

我已经按照该指南进行了尝试并尝试了这个:创建核心

➜  ./bin/solr create -c test

发布一个嵌套的 json

➜  ./bin/post -c test nested.json

查询所有文档

➜  curl "localhost:8983/solr/test/select?q=*:*"
{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"*:*"}},
  "response":{"numFound":2,"start":0,"docs":[
      {
        "ID":[1],
        "title":["Cooking Recommendations"],
        "tags":["cooking",
          "meetup"],
        "posts.ID":[2,
          5],
        "posts.title":["Cookies",
          "Cakes"],
        "posts.comments.ID":[3,
          4],
        "posts.comments.content":["Lovely recipe",
          "A-"],
        "id":"2bbde94d-3058-49d2-a53b-74dbc2d417e0",
        "_version_":1633529758781276160},
      {
        "ID":[6],
        "title":["For Hire"],
        "tags":["professional",
          "jobs"],
        "posts.ID":[7,
          10],
        "posts.title":["Search Engineer",
          "Low level Engineer"],
        "posts.comments.ID":[8,
          9],
        "posts.comments.content":["I am interested",
          "How large is the team?"],
        "id":"8276a056-d731-4707-81ec-bbc3624e7763",
        "_version_":1633529758785470464}]
  }}

使用Child Doc Transformer查询

➜  curl "http://localhost:8983/solr/test/select?fl=ID,[child childFilter=/comments/content:recipe]&q=ID:1"

{
  "responseHeader":{
    "status":400,
    "QTime":1,
    "params":{
      "q":"ID:1",
      "fl":"ID,[child childFilter=/comments/content:recipe]"}},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"undefined field content",
    "code":400}}

我在这里缺少什么?我是否需要启用更多功能才能使用此查询q=ID:1, fl=ID,[child childFilter=/comments/content:recipe]

更多:在该文档中,查询响应是一个带有子元素的 json 文档,相反,如果我进行简单查询,我仍然有一个扁平化文档

curl http://localhost:8983/solr/test/get?id=2bbde94d-3058-49d2-a53b-74dbc2d417e0

{
  "doc":
  {
    "ID":[1],
    "title":["Cooking Recommendations"],
    "tags":["cooking",
      "meetup"],
    "posts.ID":[2,
      5],
    "posts.title":["Cookies",
      "Cakes"],
    "posts.comments.ID":[3,
      4],
    "posts.comments.content":["Lovely recipe",
      "A-"],
    "id":"2bbde94d-3058-49d2-a53b-74dbc2d417e0",
    "_version_":1633529758781276160}}

标签: solr

解决方案


推荐阅读