我有以下查询。
GET sales/_search
{
"query": {
"terms": {
"ean": ["8719092410766", "8719092444716"]
}
},
"_source": ["ean"],
"size": 10000
}
这给了我以下结果。
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "sales",
"_type": "doc",
"_id": "CuDvcGIBmw7bqEEVBvZq",
"_score": 1,
"_source": {
"ean": "8719092444716"
}
},
{
"_index": "sales",
"_type": "doc",
"_id": "DeDvcGIBmw7bqEEVBvZq",
"_score": 1,
"_source": {
"ean": "8719092410766"
}
},
{
"_index": "sales",
"_type": "doc",
"_id": "9yHvcGIBbx4s3M8zD9_u",
"_score": 1,
"_source": {
"ean": "8719092410766"
}
}
]
}
}
这是很多数据,实际上我只对来源感兴趣。我希望它返回的是:
["8719092444716", "8719092410766"]
或尽可能接近它。有什么技巧可以减少从数据库中获取的数据量?我读到有关
filter_path
的信息,但ElasticSearch 6.0似乎无法识别此关键字。
最佳答案
如前所述,您可以使用filter_path
(docs),这是一个参数,您可以将其添加到请求的URL中,并指定(以逗号分隔)要的数据组件,以将包括在响应中。例如,如果您只对匹配数感兴趣,而对所有ES指标都不感兴趣,则可以这样做(curl示例)
curl http://localhost:9200/index01/type01/_search?filter_path=hits.hits
,并得到以下回应
{
"hits" : {
"hits" : [
{
"_index" : "index01",
"_id" : "6PHE_WIBts_g9zk4nzM5",
"_type" : "type01",
"_source" : {
"title" : "Radioactive Honeycomb"
},
"_score" : 1
}
]
}
}
希望能有所帮助(我正在使用ES 6.0 btw)。
关于elasticsearch - 减少ElasticSearch返回的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027310/