在Solr中按嵌套对象字段对文档排序

x4shl7ld  于 2022-11-05  发布在  Solr
关注(0)|答案(1)|浏览(186)

我有这样的文件

"name":"test",
        "_version_":1667998128851124224,
        "_root_":"test",
        "files":
        {
          "name":"<random_string>_test",
          "fileName":"test.html",
          ...
          "_nest_parent_":"test",
          "_version_":1667998128851124224,
          "_root_":"test"}},

我需要按嵌套文档中的字段fileName对文档进行排序(假设每个文档中只有一个嵌套的obj)。

pdtvr36n

pdtvr36n1#

在此场景中,有两种方式可以实现按子字段排序:
1.使用@MatsLindh在上面的评论中已经提出的方法

{
      "query": "*:*",
      "limit": 10,
      "filter": [
        "{!parent which=\"path:1.document\"}path:\"2.comment\""
      ],
      "fields": ["id"],
      "sort": "{!parent which=path:1.document score=max v='+path:2.comment {!func}fileName'} desc"
    }

1.使用子字段语法

{
      "query": "*:*",
      "limit": 10,
      "filter": [
        "{!parent which=\"path:1.document\"}path:\"2.comment\""
      ],
      "fields": ["id"],
      "sort": "childfield(fileName, {!parent which=path:1.document v=path:2.comment}) desc"
    }

相关问题