本文介绍了检索ElasticSearch中所有_id的高效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取ElasticSearch中某个索引的所有_id的最快方法是什么?是否可以使用简单的查询?我的一个索引有大约20,000个文档。解决方案
编辑:请阅读@Aleck Landgraf的答案也是>
您只需要弹性搜索 - 内部 _id 字段?或者您的文档中的 id 字段?
对于前者,尝试
curl http:// localhost:9200 / index / type / _search?pretty = true -d' {query {match_all:{} },fields:[] } ' pre>结果将仅包含文档的元数据
对于后者,如果要包含文档中的字段,只需将其添加到字段数组 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 an id field from within your documents?
For the former, try
curl 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 localhost:9200/index/type/_search?pretty=true -d '
{
"query" : {
"match_all" : {}
},
"fields": ["document_field_to_be_returned"]
}
'
更多推荐
检索ElasticSearch中所有
发布评论