I have a list of sequences e.g 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1390
and a single sensor_pk
and record_type
. All the sequences documents share a common sensor_pk
and record_type
. I want to change the sensor_pk
once instead of going through all the sequences and doing it individually. Here's what I have in python elasticsearch_dsl
ubq = UpdateByQuery(using=es.es, index=es.ALIAS_NAME)
query = Q('bool', filter=[
Q('term', sensor_pk=sensor_pk),
Q('terms', sequence=sequences),
Q('term', type=record_type)
])
ubb = ubq.query(query)
ubb.script(source=f'ctx._source.sensor_pk = -{sensor_pk};')
response = ubb.execute()
the response shows everything is okay but the sensor_pk doesn't get updated
{'took': 165, 'timed_out': False, 'total': 502, 'updated': 5...}
what might I be doing wrongly?
I updated the code to use
update_by_query