检索ElasticSearch中所有

编程入门 行业动态 更新时间:2024-10-27 14:27:24
本文介绍了检索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中所有

本文发布于:2023-10-26 10:10:19,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ElasticSearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!