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

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

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


当前回答

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

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

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

其他回答

通过提供大小,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" : "" 
}'

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": [
          {

elasticsearch(ES)既支持GET请求,也支持POST请求,以便从ES集群索引中获取数据。

当我们执行GET操作时:

http://localhost:9200/[your index name]/_search?size=[no of records you want]&q=*:*

当我们做POST时:

http://localhost:9200/[your_index_name]/_search
{
  "size": [your value] //default 10
  "from": [your start index] //default 0
  "query":
   {
    "match_all": {}
   }
}   

我建议使用elasticsearch http://mobz.github.io/elasticsearch-head/的UI插件 这将帮助您更好地了解您创建的索引,并测试您的索引。

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

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

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

如果你只是添加一些大的数字作为大小,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>" 
}