【发布时间】:2020-04-08 23:35:14
【问题描述】:
我找到了一些答案,例如 Make elasticsearch only return certain fields?
但他们都需要_source字段。
在我的系统中,磁盘和网络都是稀缺资源。
我无法存储_source 字段,我不需要_index、_score 字段。
ElasticSearch 版本:5.5
索引映射只是喜欢
{
"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"
}
]
}
}
我可以实现吗?
【问题讨论】:
-
请提供ES版本。可以肯定的是,您没有将 _source 存储在 ES 文档中?可以分享你的映射吗?你在使用存储字段吗?
-
@Alexandre Juma 感谢您的关注。我提供了更多信息,请看一下。
-
您也可以发布您的 API 调用吗?
标签: elasticsearch elasticsearch-query