Spring Data Solr使用子文档异常行为来获取文档

时间:2019-01-30 10:08:13

标签: json spring-data-solr

我有以下用于在solr文档上执行CRUD操作的mvc spring项目,我能够成功创建,读取,更新和删除,但是当我添加一些子文档时,事情变得有些混乱,例如我将新文档保存为json格式,但会保存它,但是当我查询它时,子文档将分别返回,而在主文档中则将其声明为空。

这就是我要做什么:

主要文件:

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@SolrDocument(collection = "movie")
public class Movie {

    @Id
    private long id;
    @Indexed
    private String title;
    @Indexed
    private List<Long> genreId;
    @Indexed
    private List<Genre> genre;
    @Indexed(required = true, stored = true)
    @ChildDocument
    private List<Person> director;
    @Indexed
    private Date releaseDate;
    @Indexed(required = true, stored = true)
    @ChildDocument
    private List<Person> distributor;
    @Indexed
    private MovieLanguage language;
    @Indexed(required = true, stored = true)
    @ChildDocument
    private List<Person> actor;
    @Indexed(required = true, stored = true)
    @ChildDocument
    private List<Person> creator;
    @Indexed
    private long duration;

}

子文档:

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Person implements Serializable {

    @Id
    private int id;
    @Indexed
    private String firstName;
    @Indexed
    private String lastName;
    @Indexed
    @ChildDocument
    private List<Role> role;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Role implements Serializable {

    @Id
    private int id;
    @Indexed
    private String name;

}

其余的Spring类(存储库,服务和受控类)除了默认值外没有任何事务。

这是我的要求:

{
    "id": 1,
    "title": "movie",
    "genreId": [
        1,
        3,
        4
    ],
    "genre": [
        "Comedy",
        "Drama"
    ],
    "director": [
        {
            "id": 9,
            "firstName": "aaa",
            "lastName": "aaddd",
            "role": [
                {
                    "id": 2,
                    "name": "director"
                }
            ]
        }
    ],
    "releaseDate": "2006-11-30T00:00:00.000+0000",
    "distributor": [
        {
            "id": 3,
            "firstName": "aaa",
            "lastName": "aaddd",
            "role": [
                {
                    "id": 4,
                    "name": "DISTRIBUTOR"
                }
            ]
        }
    ],
    "language": "Arabic",
    "actor": [
        {
            "id": 5,
            "firstName": "aaa",
            "lastName": "aaddd",
            "role": [
                {
                    "id": 6,
                    "name": "Actor"
                }
            ]
        }
    ],
    "creator": [
        {
            "id": 7,
            "firstName": "aaa",
            "lastName": "aaddd",
            "role": [
                {
                    "id": 8,
                    "name": "Creator"
                }
            ]
        }
    ],
    "duration": 1200
}

这是招募所有员工的回应:

{
    "content": [
        {
            "id": 1,
            "title": "movie",
            "genreId": [
                1,
                3,
                4
            ],
            "genre": [
                "Comedy",
                "Drama"
            ],
            "director": null,
            "releaseDate": "2006-11-30T00:00:00.000+0000",
            "distributor": null,
            "language": "Arabic",
            "actor": null,
            "creator": null,
            "duration": 1200
        },
        {
            "id": 2,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 9,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 4,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 3,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 6,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 5,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 8,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 7,
            "title": null,
            "genreId": null,
            "genre": null,
            "director": null,
            "releaseDate": null,
            "distributor": null,
            "language": null,
            "actor": null,
            "creator": null,
            "duration": 0
        },
        {
            "id": 1,
            "title": "movie",
            "genreId": [
                1,
                3,
                4
            ],
            "genre": [
                "Comedy",
                "Drama"
            ],
            "director": null,
            "releaseDate": "2006-11-30T00:00:00.000+0000",
            "distributor": null,
            "language": "Arabic",
            "actor": null,
            "creator": null,
            "duration": 1200
        }
    ],
    "pageable": {
        "sort": {
            "sorted": false,
            "unsorted": true,
            "empty": true
        },
        "offset": 0,
        "pageSize": 10,
        "pageNumber": 0,
        "paged": true,
        "unpaged": false
    },
    "facetResultPages": [],
    "facetQueryResult": {
        "content": [],
        "pageable": "INSTANCE",
        "last": true,
        "totalPages": 1,
        "totalElements": 0,
        "size": 0,
        "number": 0,
        "sort": {
            "sorted": false,
            "unsorted": true,
            "empty": true
        },
        "numberOfElements": 0,
        "first": true,
        "empty": true
    },
    "highlighted": [],
    "maxScore": null,
    "fieldStatsResults": {},
    "suggestions": [],
    "facetFields": [],
    "allFacets": [
        null
    ],
    "alternatives": [],
    "facetPivotFields": [],
    "totalPages": 1,
    "totalElements": 10,
    "size": 10,
    "number": 0,
    "sort": {
        "sorted": false,
        "unsorted": true,
        "empty": true
    },
    "numberOfElements": 10,
    "first": true,
    "last": true,
    "empty": false
}

有人可以解释为什么我的文档中有多个空数据,以及为什么actor,director,creator和distributed字段为空吗?

0 个答案:

没有答案