Elasticsearch查詢返回所有記錄

本文翻譯自:Elasticsearch query to return all records

I have a small database in Elasticsearch and for testing purposes would like to pull all records back. 我在Elasticsearch中有一個小型數據庫,出於測試目的,我希望將所有記錄拉回來。 I am attempting to use a URL of the form... 我試圖使用表單的URL ...

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

Can someone give me the URL you would use to accomplish this, please? 有人可以給我你用來完成這個的URL嗎?


#1樓

參考:https://stackoom.com/question/b2wm/Elasticsearch查詢返回所有記錄


#2樓

Note: The answer relates to an older version of Elasticsearch 0.90 . 注意:答案與Elasticsearch 0.90的舊版本有關。 Versions released since then have an updated syntax. 從那時起發佈的版本具有更新的語法。 Please refer to other answers that may provide a more accurate answer to the latest answer that you are looking for. 請參閱其他答案,以便爲您正在尋找的最新答案提供更準確的答案。

The query below would return the NO_OF_RESULTS you would like to be returned.. 下面的查詢將返回您想要返回的NO_OF_RESULTS。

curl -XGET 'localhost:9200/foo/_search?size=NO_OF_RESULTS' -d '
{
"query" : {
    "match_all" : {}
  }
}'

Now, the question here is that you want all the records to be returned. 現在,這裏的問題是你想要返回所有記錄。 So naturally, before writing a query, you wont know the value of NO_OF_RESULTS . 很自然地,在編寫查詢之前,您不會知道NO_OF_RESULTS的值。

How do we know how many records exist in your document? 我們如何知道您的文檔中存在多少條記錄? Simply type the query below 只需在下面輸入查詢即可

curl -XGET 'localhost:9200/foo/_search' -d '

This would give you a result that looks like the one below 這會給你一個看起來像下面的結果

 {
hits" : {
  "total" :       2357,
  "hits" : [
    {
      ..................

The result total tells you how many records are available in your document. 結果總計告訴您文檔中有多少記錄可用。 So, that's a nice way to know the value of NO_OF RESULTS 所以,這是瞭解NO_OF結果值的好方法

curl -XGET 'localhost:9200/_search' -d ' 

Search all types in all indices 搜索所有索引中的所有類型

curl -XGET 'localhost:9200/foo/_search' -d '

Search all types in the foo index 搜索foo索引中的所有類型

curl -XGET 'localhost:9200/foo1,foo2/_search' -d '

Search all types in the foo1 and foo2 indices 搜索foo1和foo2索引中的所有類型

curl -XGET 'localhost:9200/f*/_search

Search all types in any indices beginning with f 搜索以f開頭的任何索引中的所有類型

curl -XGET 'localhost:9200/_all/type1,type2/_search' -d '

Search types user and tweet in all indices 在所有索引中搜索類型用戶和推文


#3樓

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

Note the size param , which increases the hits displayed from the default (10) to 1000 per shard. 請注意大小參數 ,它會將默認值(10)顯示的匹配數增加到每個分片1000個。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html


#4樓

使用server:9200/_stats也可以獲取有關所有別名的統計信息..如每個別名的大小和元素數量,這非常有用,並提供有用的信息


#5樓

elasticsearch(ES) supports both a GET or a POST request for getting the data from the ES cluster index. elasticsearch(ES)支持從ES集羣索引獲取數據的GET或POST請求。

When we do a GET: 當我們做GET時:

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

When we do a POST: 當我們做POST時:

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

I would suggest to use a UI plugin with elasticsearch http://mobz.github.io/elasticsearch-head/ This will help you get a better feeling of the indices you create and also test your indices. 我建議使用帶彈性搜索的UI插件http://mobz.github.io/elasticsearch-head/這將幫助您更好地瞭解您創建的索引並測試索引。


#6樓

Elasticsearch will get significant slower if you just add some big number as size, one method to use to get all documents is using scan and scroll ids. Elasticsearch將得到顯著慢,如果你只需要添加一些大的數量大小,一個方法用來獲取所有文檔是使用掃描和滾動標識。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

In Elasticsearch v7.2, you do it like this: 在Elasticsearch v7.2中,您可以這樣做:

POST /foo/_search?scroll=1m
{
    "size": 100,
    "query": {
        "match_all": {}
    }
}

The results from this would contain a _scroll_id which you have to query to get the next 100 chunk. 這樣的結果將包含一個_scroll_id,你必須查詢它以獲得下一個100塊。

POST /_search/scroll 
{
    "scroll" : "1m", 
    "scroll_id" : "<YOUR SCROLL ID>" 
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章