3

我正在使用弹性搜索模型(https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model),但我找不到在文档上设置 TTL 的方法。我尝试了几种方法,但没有成功。

我有一个名为“log”的模型和一个名为“logs”的索引。在模型中,我有以下映射:

include Elasticsearch::Model

mappings _ttl: { enabled: true, default: '7d' }

我希望它类似于https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html#mapping-ttl-field

在控制台中,这是我可以看到的:

> Log.mappings
=> #<Elasticsearch::Model::Indexing::Mappings:0x007fcefd985368 @mapping={}, @options={:_ttl=>{:enabled=>true, :default=>"7d"}}, @type="log">

但是,当使用 cURL 时,我只能使用模型属性而不是 ttl 选项:

curl -XGET 'http://localhost:9200/logs/_mappings'
{
    "logs": {
        "mappings": {
            "log": {
                "properties": {
                    "created_at": {
                        "format": "dateOptionalTime",
                        "type": "date"
                    },
                    "id": {
                        "type": "long"
                    },
                    "operation": {
                        "type": "string"
                    },
                    "order_number": {
                        "type": "string"
                    },
                    "request_payload": {
                        "type": "string"
                    },
                    "response_payload": {
                        "type": "string"
                    },
                    "updated_at": {
                        "format": "dateOptionalTime",
                        "type": "date"
                    }
                }
            }
        }
    }
}

我还尝试将 TTL 选项作为选项添加到批量导入中(为了实现这一点:https ://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-bulk.html#bulk- ttl)但我不能使用该选项:

> Log.import({
  query: -> { where(id: ids) },
  refresh: true,
  return: 'errors',
  ttl: '1d'
})
Unknown key: :ttl. Valid keys are: :start, :batch_size : {"ids":[358]}

关于我如何做到这一点的任何想法?

4

0 回答 0