我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…

http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}

有人能给我你要用来完成这个的URL吗?


当前回答

curl -X GET 'localhost:9200/foo/_search?q=*&pretty' 

其他回答

Size参数将显示的命中数从默认值(10)增加到500。

http://localhost:9200/[indexName]/_search?pretty=true&size=500&q=*:*

将from逐步更改为获取所有数据。

http://localhost:9200/[indexName]/_search?size=500&from=0

除了@Akira Sendoh,没有人回答如何实际获得所有文档。但是即使是这个解决方案也会使我的ES 6.3服务在没有日志的情况下崩溃。对我来说,使用底层elasticsearch-py库唯一有效的是通过使用scroll() api的扫描助手:

from elasticsearch.helpers import scan

doc_generator = scan(
    es_obj,
    query={"query": {"match_all": {}}},
    index="my-index",
)

# use the generator to iterate, dont try to make a list or you will get out of RAM
for doc in doc_generator:
    # use it somehow

然而,现在更简洁的方法似乎是通过elasticsearch-dsl库,它提供了更抽象、更简洁的调用,例如:http://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#hits

curl -XGET '{{IP/localhost}}:9200/{{Index name}}/{{type}}/_search?scroll=10m&pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
}}'

简单!你可以使用size和from参数!

http://localhost:9200/[your index name]/_search?size=1000&from=0

然后逐渐改变,直到你得到所有的数据。

要从所有索引中返回所有记录,您可以执行:

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,
       ...