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

其他回答

官方文档提供了这个问题的答案!你可以在这里找到它。

{
  "query": { "match_all": {} },
  "size": 1
}

您只需将size(1)替换为您想要看到的结果的数量!

Elasticsearch 6.x

请求:GET /foo/_search?漂亮= true

Response:在Hits-> total中,给出文档的计数

    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 1001,
        "max_score": 1,
        "hits": [
          {
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

http://localhost:9200/foo/_search/?size=1000&pretty=1

您需要指定大小查询参数,因为默认值是10