2016-06-28 74 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