我找到了一些答案,比如Make elasticsearch only return certain fields?
但它们都需要_source
场。
在我的系统中,磁盘和网络都是稀缺资源。
我不能存储_source
字段,也不需要_index
、_score
字段。
ElasticSearch版本:5.5
索引Map就像
{
"index_2020-04-08": {
"mappings": {
"type1": {
"_all": {
"enabled": false
},
"_source": {
"enabled": false
},
"properties": {
"rank_score": {
"type": "float"
},
"first_id": {
"type": "keyword"
},
"second_id": {
"type": "keyword"
}
}
}
}
}
}
我的查询:
GET index_2020-04-08/type1/_search
{
"query": {
"bool": {
"filter": {
"term": {
"first_id": "hello"
}
}
}
},
"size": 1000,
"sort": [
{
"rank_score": {
"order": "desc"
}
}
]
}
我得到的搜索结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": null,
"hits": [
{
"_index": "index_2020-04-08",
"_type": "type1",
"_id": "id_1",
"_score": null,
"sort": [
0.06621722
]
},
{
"_index": "index_2020-04-08",
"_type": "type1",
"_id": "id_2",
"_score": null,
"sort": [
0.07864579
]
}
]
}
}
我要的结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": null,
"hits": [
{
"_id": "id_1"
},
{
"_id": "id_2"
}
]
}
}
我可以实施它吗?
2条答案
按热度按时间1mrurvl11#
要返回文档中的特定域,必须执行以下两项操作之一:
1.在文档中包括
_source
域,默认情况下启用该域。1.使用必须手动启用的存储字段功能存储特定字段
因为您需要大量的文档Id和一些元数据,所以可以使用filter_path特性。
下面的示例与您所需的内容非常接近(只需更改字段列表):
wyyhbhjk2#
根据你链接的SO问题,你不是在 * 存储 *
_source
,你是在从ES-请求 * 它。_score
、_index
等是无论如何都要检索的 meta字段。这将为您节省几个字节
但是执行聚合本身就有成本。