2

PHP で curl を使用して ttl 機能を有効にする方法は知っていますが、公式の Elasticsearch PHP ライブラリ ( https://github.com/elasticsearch/elasticsearch-php ) もこの機能をサポートしているかどうか疑問に思います。私はすでにLibのコードを掘り下げましたが、それを理解することができませんでした.

ご協力いただきありがとうございます!

4

2 に答える 2

0

インデックス タイプで ttl 機能を有効にする独自の方法を作成しました。公式の Github リポジトリにも問題を提出しました: 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'];
  }
} 
于 2014-03-27T10:02:56.997 に答える
0

私見では、putMapping() メソッドを使用して Elasticsearch マッピングを更新する必要があります。特別なメソッド呼び出しは必要ありません。

これは、私たちのシステムで機能した例です。

    $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);
于 2015-08-06T12:15:54.590 に答える