2016-04-15 85 views
0

什麼是最快的方式來獲得某個索引的_ids與fosElasticaBundle(3.1.0)? 我的索引大約有30,000個文檔。如何獲得只有ID或FOS elastica的一個領域

例如,我會得到fosElastica的所有ID列表。等效Elasticsearch:

curl http://localhost:9200/search/etablissement/_search?pretty=true -d { ' 
     "query" : { 
      "match_all" : {} 
     }, 
     "fields": [] 
    } 
    ' 

或者,如果我想的名字:

curl http://localhost:9200/search/etablissement/_search?pretty=true -d { ' 
     "query" : { 
      "match_all" : {} 
     }, 
     "fields": ['name'] 
    } 
    ' 

謝謝

回答

0

終於讓我找到了答案,我的問題過濾文件。我只是想知道這是否正確。

$elasticaService = $this->container->get('fos_elastica.index.search'); 
    $elasticaService->request("_search", "GET", array("fields"=>array()), array("match_all" => array(),"size" => 999999)) 

    $i = 1; 
    $data = array(); 
    if(isset($results["hits"]["hits"])){ 
     foreach($results["hits"]["hits"] as $result){ 
      $data[$i] = $result["_id"]; 
      ++$i; 
     } 
    } 
    return $data; 

爲了避免錯誤,我不得不補充:

「index.max_result_window:999999」 到/etc/elasticsearch/elasticsearch.yml 和 「服務的Apache2重啓」 重新加載配置。

1

您可以通過上面的命令,在指數ID:

curl -XGET 'http://localhost:9200/search/etablissement/1 

這會給你文檔的第一個ID。

或 您可以通過指定文檔ID

{ 
    "ids" : { 
     "type" : "my_type", 
     "values" : ["2", "34", "333"] 
    } 
} 
相關問題