elasticsearch - elasticsearch 将结果减少到一列 - 每个文档仅返回 1 个值
问题描述
我尝试将 elasticsearch 的 json 结果减少到仅我建议获取的一列或多列。有什么办法吗?
当我使用以下命令时,我将结果嵌套到“_source”中:
{
"from": "0", "size":"2",
"_source":["id"],
"query": {
"match_all": {}
}
}
'
并且不需要我的用例。
我得到这个结果:
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "indexer_1",
"_type" : "type_indexer_1",
"_id" : "38142",
"_score" : 1.0,
"_source" : {
"id" : 38142
}
},
{
"_index" : "indexer_1",
"_type" : "type_indexer_1",
"_id" : "38147",
"_score" : 1.0,
"_source" : {
"id" : 38147
}
}
]
}
}
我想拥有的:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : 1.0,
"hits" : [
{
"id" : 38142
},
{
"id" : 38147
}
]
}
}
我会喜欢这个 json 结果:
{
{
"id" : 38142
},
{
"id" : 38147
}
}
ES中是否有开箱即用的方法来减少结果集?
解决方案
您可以过滤输出 JSON 查看文档:响应过滤
GET /index/_search?filter_path=hits.hits._id
{
"from": "0",
"size":"2",
"_source":["id"],
"query": {
"match_all": {}
}
}
推荐阅读
- spring-boot - Azure DevOps 构建管道 - 基于特定 application.profile 构建 Spring Boot
- android - 如何在 Android Gradle 任务中注册生成的资源?
- javascript - 父状态更新时子组件的道具不更新
- kubernetes - istio 中是否允许交叉规则?应用它的策略是什么?
- javascript - 什么是“PHP”的运行时环境,例如“Javascript”的“Node.js”运行时环境,用于构建服务器端 Web 应用程序?
- java - 使用 JavaMail 发送带有附件的邮件 - 编写 Multipart 时出现异常
- macos - macOS - 未授权将 Apple 事件发送到 <>
- r - 如何在胶水内制作上标?
- c# - 从 S3 下载后生成的 Zip 文件无效
- r - 如何在数据集中找到超过 6 个值的最大增量