我正在使用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/