简体   繁体   中英

TTL in elasticsearch

I am using the elasticsearch python client to create and store data to a aws elasticsearch instance.

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)

As defined above, now I am expecting the records to be deleted automatically after 2 minutes, however they are persisting.

What could be the possible reason ?

There was an error with the way I had defined mappings, corrected it as shown below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM