elasticsearch - 如何从 Elasticsearch 返回源字段
问题描述
我正在使用 Elasticsearch V7。
我只想从 Elasticsearch 中获取源字段。
请求查询:
GET /test/_search?filter_path=hits.hits._source
{
"query": {
"term": {
"test": {
"value": "123"
}
}
}
}
回复:
{
"hits" : {
"hits" : [
{
"_source" : {
"field1" : "value1",
"field2" : "value2",
"field3" : "value3",
}
}
]
}
}
预期结果:
{
"hits" : {
"hits" : [
{
"field1" : "value1",
"field2" : "value2",
"field3" : "value3",
},
{
"field1" : "value1",
"field2" : "value2",
"field3" : "value3",
}
]
}
}
或者
"hits" : [
{
"field1" : "value1",
"field2" : "value2",
"field3" : "value3",
},
{
"field1" : "value1",
"field2" : "value2",
"field3" : "value3",
}
]
有没有办法从 Elasticsearch 中获取上述预期结果?
解决方案
不,这是不可能的。filter_path
就本机响应过滤而言,它已尽善尽美。
话虽如此,您可以使用jq
命令行 JSON 处理器来_sources
进一步提取:
curl -XGET "http://localhost:9200/test/_search?filter_path=hits.hits._source" \
-H 'Content-Type: application/json' \
-d'{
"query": {
"match_all": {}
}
}' \
| jq '{hits: [.hits.hits[]._source]}'
推荐阅读
- python - 如何检查 objedc 是否具有属性 false o true
- python-3.x - 比较两个文件的每个元素(逐行)
- html - 相对于显示的内容而不是页面定位播放按钮
- pandas - 我想替换异常值而不是完全删除它...有什么建议吗?
- amazon-web-services - 每天将大量 csv 数据摄取到弹性搜索中
- reactjs - 如何在材料 ui datepicker 中仅获取日期?
- asp.net - 如何在 ASP.NET 中显示时间?
- jquery - 使用 Jquery - 在两个给定类之间查找特定类并添加内容
- c - 为什么 > 运算符不能正常工作?
- ios - 使用按钮切换视图根本不起作用