我有一个包含嵌套字段的文档。示例:
"mappings": {
"blogpost": {
"properties": {
"title": { "type": "text" },
"body": { "type": "text" },
"comments": {
"type": "nested",
"properties": {
"name": { "type": "text" },
"comment": { "type": "text" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
}
能否修改查询,使响应仅包含非嵌套字段?
在此示例中,响应将仅包含body
和title
。
使用_source
可以排除/包含字段
GET /blogpost/_search
{
"_source":{
"excludes":["comments"]
}
}
但是您必须将字段名称明确地放在排除中,我正在寻找一种排除所有嵌套字段而又不知道其字段名称的方法
答案 0 :(得分:0)
您可以通过静态方式实现,这意味着您使用excludes关键字输入了字段名称,例如:
GET your_index/_search
{
"_source": {
"excludes": "comments"
},
"query": {
"match_all" : {}
}
}
excludes
可以接受array
个字符串;不只是一个字符串。