我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
当前回答
要从所有索引中返回所有记录,您可以执行:
curl -XGET http://35.195.120.21:9200/_all/_search?size=50&pretty
输出:
"took" : 866,
"timed_out" : false,
"_shards" : {
"total" : 25,
"successful" : 25,
"failed" : 0
},
"hits" : {
"total" : 512034694,
"max_score" : 1.0,
"hits" : [ {
"_index" : "grafana-dash",
"_type" : "dashboard",
"_id" : "test",
"_score" : 1.0,
...
其他回答
如果你只是添加一些大的数字作为大小,Elasticsearch会变得非常慢,一种获取所有文档的方法是使用scan和scroll id。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
在Elasticsearch v7.2中,您可以这样做:
POST /foo/_search?scroll=1m
{
"size": 100,
"query": {
"match_all": {}
}
}
这样的结果将包含一个_scroll_id,您必须查询它来获得下一个100块。
POST /_search/scroll
{
"scroll" : "1m",
"scroll_id" : "<YOUR SCROLL ID>"
}
使用Elasticsearch 7.5.1
http://${HOST}:9200/${INDEX}/_search?pretty=true&q=*:*&scroll=10m&size=5000
如果你也可以用&size=${number}来指定数组的大小
以防你不知道你的索引
http://${HOST}:9200/_cat/indices?v
你可以使用_count API来获取size参数的值:
http://localhost:9200/foo/_count?q=<your query>
返回{count:X,…}。提取值'X',然后执行实际查询:
http://localhost:9200/foo/_search?q=<your query>&size=X
官方文档提供了这个问题的答案!你可以在这里找到它。
{
"query": { "match_all": {} },
"size": 1
}
您只需将size(1)替换为您想要看到的结果的数量!
通过提供大小,elasticSearch将返回的最大结果是10000
curl -XGET 'localhost:9200/index/type/_search?scroll=1m' -d '
{
"size":10000,
"query" : {
"match_all" : {}
}
}'
在此之后,您必须使用Scroll API来获取结果并获得_scroll_id值,并将此值放入scroll_id中
curl -XGET 'localhost:9200/_search/scroll' -d'
{
"scroll" : "1m",
"scroll_id" : ""
}'