如果索引存在于php elastica中,如何获取现有索引对象

时间:2015-03-15 10:10:29

标签: php elasticsearch elastica

我是弹性搜索新手。我正在使用php elastica客户端并面临一个问题: 如果存在索引,我想获取此现有索引的对象而不是重新创建它。怎么办呢?

client = new \Elastica\Client($arrServerConf, $callback);

if ( $client->getIndex($name)->exists() ) {
      //do something here to get this existing object -- what to do here???
} else {
      // create a new one
      $index = $client->getIndex($name);
      $index->create(array('index' => array('number_of_shards' => $shards, 'number_of_replicas' => 0)), $delete);
}
$type = $index->getType($typeName);

或者还有其他方法吗? 我需要这个,因为,我将在这个索引中添加文档并在其中搜索。

1 个答案:

答案 0 :(得分:0)

我的坏。我可以很容易地做到这一点: $ index = $ client-> getIndex($ name);

我的代码本身存在一些问题。