php - 如果PHP Elastica中存在索引,如何获取现有的索引对象

标签 php elasticsearch elastica

我是 flex 搜索的新手。我正在使用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);

还是有其他方法可以做到这一点?
我需要这样做是因为,我将在此索引中添加文档并在其中搜索。

最佳答案

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

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

关于php - 如果PHP Elastica中存在索引,如何获取现有的索引对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29059454/

相关文章:

PHP 将 SQL 数据库中的时间与当前时间进行比较

docker - Docker容器启动后如何自动运行脚本

elasticsearch - 在Kibana中将Filebeat消息字段拆分为多个字段

elasticsearch - 如何按点查找包含多边形的文档?

php - 如何在ElasticSearch中的某些索引中搜索

php - 当我实例化该类时,方法会调用自身

php - 将 PayPal 返回 URL 设置为本地主机

php - 在 PHP 中以编程方式将照片作为页面本身上传到 Facebook 页面

elasticsearch - ElasticSearch比赛分数

elasticsearch - 如果字段存在,Elasticsearch查询将应用范围