It's my first time trying to create a rollover and I've read a bunch of posts with similar topics but nothing quite answers mine.
from elasticsearch import Elasticsearch, helpers
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
es.indices.delete(index='myind-000001', ignore=[400, 404])
my_idx_settings = {
"template": "myind*",
"settings": {"index" : {
"number_of_shards" : 3, "number_of_replicas": 1}},
"aliases": {"myind_write": {}},
"mappings": {
'mytype': {
"properties": {
"vs": {
"type": "nested",
"properties": {
"par": {"type": "keyword"},
"value": {"type": "float"}
}
},
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
}
}
}
}
}
es.indices.put_template("bm_temp", my_idx_settings)
es.indices.create(index = 'myind-000001')
#es.indices.put_mapping(index='myind-000001', doc_type='mytype', body=mymap) # don't need this.
es.indices.put_alias(index=['myind-000001'], name = 'myind_write' )
roll_body = '{"conditions": {"max_docs": 5}}'
es.indices.rollover(alias=alias, body=roll_body)
data = []
for i in range(1,42):
obj = {}
obj['_type'] = 'mytype'
obj['vs'] = [{'par': 'HR', 'val': i}]
obj['_index'] = 'myind-000001'
data.append(obj)
data = iter(data)
helpers.bulk(es, data)
This code works except that everything gets ingested into the original index and no rolling takes place.
What am I doing wrong?
Thank you!