es查询所欲,检索ElasticSearch中所有_id的高效方法

What is the fastest way to get all _ids of a certain index from ElasticSearch? Is it possible by using a simple query? One of my index has around 20,000 documents.

解决方案

Edit: Please read @Aleck Landgraf's Answer, too

You just want the elasticsearch-internal _id field? Or an id field from within your documents?

For the former, try

curl http://localhost:9200/index/type/_search?pretty=true -d '

{

"query" : {

"match_all" : {}

},

"fields": []

}

'

The result will contain only the "metadata" of your documents

{

"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

} ]

}

}

For the latter, if you want to include a field from your document, simply add it to the fields array

curl http://localhost:9200/index/type/_search?pretty=true -d '

{

"query" : {

"match_all" : {}

},

"fields": ["document_field_to_be_returned"]

}

'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值