2016-06-28 80 views
0

我正在使用PHP API將文檔發佈爲彈性文件,但我需要根據它的時間戳檢索最後發佈的文檔。PHP API獲取文檔

我目前使用的感查詢是這樣的:

GET index-*/type/_search 
{ 
    "query": { 
    "match_all": {} 
    }, 
    "size": 1, 
    "sort": [ 
    { 
     "timestamp": { 
     "order": "desc" 
     } 
    } 
    ] 
} 

我把它翻譯成我的PHP API

$params = [ 
    'index' => 'index-*', 
    'type' => 'type', 
    'custom' => [ 
     'query'=> [ 
      'match_all'=> [] 
     ], 
     'size'=> 1, 
     'sort'=> [ 
      [ 
      'timestamp'=> [ 
      'order'=> 'desc' 
       ] 
      ] 
     ] 
    ] 
]; 
$response = $client->get($params); 

但遺憾的是不斷拋出錯誤,並要求「身份證」,但我的ID是生成的。我不能以其他方式做。有沒有辦法解決這個問題?由於

回答

0

您需要使用search method

$params = [ 
    'index' => 'index-*', 
    'type' => 'type', 
    'body' => [ 
     'query'=> [ 
      'match_all'=> [] 
     ], 
     'size'=> 1, 
     'sort'=> [ 
      [ 
      'timestamp'=> [ 
      'order'=> 'desc' 
       ] 
      ] 
     ] 
    ] 
]; 
$response = $client->search($params); 
+0

哇,謝謝你這麼多的快速響應。這是我的一個愚蠢的錯誤。謝謝, – ScipioAfricanus

+0

不用擔心,很高興幫助! – Val