【问题标题】:Official Elasticsearch PHP Module enable TTL官方 Elasticsearch PHP 模块启用 TTL
【发布时间】:2015-08-06 20:15:54
【问题描述】:

我知道如何在 php 中使用 curl 激活 ttl 功能,但我想知道官方的 Elasticsearch PHP 库 (https://github.com/elasticsearch/elasticsearch-php) 是否也支持此功能。我已经挖掘了 Lib 的代码,但无法弄清楚。

感谢您的帮助!

【问题讨论】:

  • 您是否尝试过在$params 数组中提交TTL?看Clients code
  • 是的,我做到了...但是我需要激活索引中的 ttl 功能。

标签: php elasticsearch ttl


【解决方案1】:

我创建了自己的方法来启用索引类型的 ttl 功能。我还在官方 Github Repo 上提交了一个问题:https://github.com/elasticsearch/elasticsearch-php/issues/62

class ElasticSearchClient extends \Elasticsearch\Client {
  public function enableTtl($params) {
    $index = $this->extractArgument($params, 'index');
    $type = $this->extractArgument($params, 'type');
    $body = json_encode(array($type => array('_ttl' => array('enabled' => true))));
    /** @var callback $endpointBuilder */
    $endpointBuilder = $this->dicEndpoints;

    /** @var \Elasticsearch\Endpoints\Update $endpoint */
    $endpoint = $endpointBuilder('Indices\Mapping\Put');
    $endpoint->setIndex($index)
        ->setType($type)
        ->setBody($body);
    $endpoint->setParams($params);
    $response = $endpoint->performRequest();
    return $response['data'];
  }
} 

【讨论】:

    【解决方案2】:

    好吧,恕我直言,您需要使用 putMapping() 方法更新弹性搜索映射。不需要特殊的方法调用。

    这是在我们的系统中运行的示例。

        $params['index'] = 'yourindexname';
        $params['type'] = 'yourtypename';
    
        $mapping = [
            '_ttl' => [
                'enabled' => 'true',
                'default' => '14d',
            ],
            'properties' => [
                [... add your properties here ...]
            ]
        ];
    
        $params['body']['yourtypename'] = $mapping;
        $this->getClient()->indices()->putMapping($params);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2021-02-03
      • 2014-09-26
      • 2017-08-15
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多