python - Elasticsearch中的TTL

标签 python elasticsearch elasticsearch-plugin

我正在使用elasticsearch python客户端创建数据并将数据存储到aw elasticsearch实例。

def create_index():
    """
        create mapping of data
    """
    mappings = '''
    {
        "tweet":{
            "_ttl":{
                "enabled": true,
                "default": "2m"
            },
            "properties": {
                "text":{
                    "type": "string"
                },
                "location":{
                    "type": "geo_point"
                }
            }
        }
    }
    '''
    # Ignore if index already exists
    es.indices.create(index='tweetmap', ignore=400, body=mappings)

按照上面的定义,现在我希望记录在2分钟后会自动删除,但是这些记录会持续存在。

可能是什么原因?

最佳答案

我定义映射的方式存在错误,如下所示进行了纠正:

mappings = '''
    {
        "mappings":{
            "tweet":{
                "_ttl":{
                    "enabled": true,
                    "default": "1d"
                },
                "properties": {
                    "text":{
                        "type": "string"
                    },
                    "location":{
                        "type": "geo_point"
                    }
                }
            }
        }
    }
    '''

关于python - Elasticsearch中的TTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40187202/

相关文章:

elasticsearch - 如何将 ignore_unavailable 作为查询参数传递给 elasticsearch 搜索请求?

elasticsearch - 弹性观察者不附加文件

amazon-web-services - 在 Elasticsearch 上自动添加节点

python - 代码在将 0.0 转换为 0 时有效,但在 1.0 转换时失败?

python - Cloud9 Python : getting Flask module not found on Run action

python - 如果将每个 View 类移动到单独的 .py 文件,是否会影响性能?

javascript - 词干查询elasticsearch

java - 使用 Appdynamics 时是否需要 ELK-stack 或 Graphite?

python-3.x - python3 UnicodeEncodeError : 'charmap' codec can't encode characters in position 95-98: character maps to <undefined>

python - 分发自己的python,跨linux