从ElasticSearch获取某个索引的所有_id的最快方式是什么?是否可以使用简单的查询?我的一个索引有大约20,000个文件。 编辑:请阅读@Aleck Landgraf的答案 你只需要弹性搜索 – 内部的_id字
你只需要弹性搜索 – 内部的_id字段?或者你的文件中的id字段?
对于前者,试试
curl http://localhost:9200/index/type/_search?pretty=true -d '
{
"query" : {
"match_all" : {}
},
"fields": []
}
'
结果将只包含文档的“元数据”
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.0,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "36",
"_score" : 1.0
}, {
"_index" : "index",
"_type" : "type",
"_id" : "38",
"_score" : 1.0
}, {
"_index" : "index",
"_type" : "type",
"_id" : "39",
"_score" : 1.0
}, {
"_index" : "index",
"_type" : "type",
"_id" : "34",
"_score" : 1.0
} ]
}
}
对于后者,如果要从文档中包含一个字段,只需将其添加到fields数组中即可
curl http://localhost:9200/index/type/_search?pretty=true -d '
{
"query" : {
"match_all" : {}
},
"fields": ["document_field_to_be_returned"]
}
'
