2015-09-30 39 views
1

在php中利用Elasticsearch客戶端。 如何在ES中找到很多文檔,因爲id等於SQL中的「WHERE id IN(1,2,3,4,9)」? 對於單聲道得到我這樣做Multy如何獲得Elasticsearch php的樣本?

$ params = [ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'id' => 'my_id' 
  ]; 

  $ response = $ client-> get ($ params); 

如何讓一些唱片嗎? 我試了,但它不工作

$ params = [[ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'id' => 'my_id' 
  ] 
  [ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'id' => 'my_id2' 
  ]]; 

  $ response = $ client-> mget ($ params); 

$ params = [ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'id' => array ('my_id', 'my_id2') 
  ]; 

  $ response = $ client-> mget ($ params); 

的API是PHP只有HTTPS:https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_getting_documents.html

這樣了,只CURL請求HTTPS:https://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-multi-get.html

誰與ES合作過,請幫忙!)

回答

1

你只需要使用ids過濾器,像這樣:

$params = [ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'body' => [ 
     'query' => [ 
      'filtered' => [ 
       'filter' => [ 
        'ids' => [ 
         'values' => ['my_id', 'my_id2'] 
        ] 
       ] 
      ] 
     ] 
    ] 
]; 


$results = $client->search($params); 

UPDATE

如果你絕對要使用mget,那麼你應該做這樣的:

$ params = [ 
    'index' => 'my_index', 
    'type' => 'my_type', 
    'body' => array ('my_id', 'my_id2') 
    ]; 

    $ response = $ client-> mget ($ params); 
+0

你有機會嘗試一下嗎? – Val

+0

但爲什麼不是mget的工作。它應該與'文檔'鍵合作嗎? https://www.elastic.co/guide/en/elasticsearch/guide/current/_retrieving_multiple_documents.html –

+1

我已經更新了我的答案。 – Val

-1

只需在插入過程中添加以下行

"refresh"=> true