检索ElasticSearch中所有_id的高效方法 [英] Efficient way to retrieve all _ids in ElasticSearch
本文介绍了检索ElasticSearch中所有_id的高效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
编辑:请阅读@Aleck Landgraf的答案也是>
您只需要弹性搜索 - 内部 _id
字段?或者您的文档中的 id
字段?
对于前者,尝试
curl http:// localhost:9200 / index / type / _search?pretty = true -d'
pre>
{
query {
match_all:{}
},
fields:[]
}
'
结果将仅包含文档的元数据
take:7,
timed_out:false,
_shards:{
total:5,
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
}]
}
}
对于后者,如果要包含文档中的字段,只需将其添加到
字段
数组curl http:// localhost:9200 / index / type / _search?pretty = true -d'
{
query:{
match_all:{}
},
fields:[document_field_to_be_returned]
}
'
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 anid
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
arraycurl http://localhost:9200/index/type/_search?pretty=true -d ' { "query" : { "match_all" : {} }, "fields": ["document_field_to_be_returned"] } '
这篇关于检索ElasticSearch中所有_id的高效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文