【发布时间】:2015-08-01 10:23:52
【问题描述】:
我在 Scala 和 REST 中使用弹性搜索,并具有以下数据结构:(作为 JSON 输入文件)
{
"bookTitle" : "textbook",
"bookAuthors" : [
{
"authorId" : "01",
"authorName" : "author1"
},
{
"authorId" : "02",
"authorName" : "author2"
},
]
}
此集合使用的数据映射:
{
"properties" : {
"book": {
"properties": {
"bookTitle": {
"type": "string"
},
"bookAuthors": {
"type": "nested",
"properties": {
"authorId ": {
"type":"string"
},
"authorName" : {
"type": "string"
}
}
}
}
}
}
}
我希望能够通过作者 ID 进行查询,并仅获取匹配的单个作者。到目前为止,我已经设法通过 authorId 进行查询,但我不断得到整个书籍文档,同时显示了两位作者;我也尝试只选择特定于 bookAuthors 的字段来显示,但结果是一样的。
目前情况: 获取 authorId 为 01 的作者姓名 => 返回 [author1,author2]
必填查询: 获取 authorId 为 01 的作者姓名 => return [author1]
【问题讨论】:
标签: json elasticsearch nested