'Elasticsearch duplicate date timestamp

I make a query with python to a server where it has duplicate data by date. I know that the database would have to be debugged, but how could I do a query like the following and return a single record per date (@timestamp). I clarify that the dates (@timestamp) are duplicated:

{ "query":{"bool":{"must":{"range":{"@timestamp":{"lte": "2021-09-21T23:10:00.000-03:00","gte": "2021-09-21T23:10:00.000-03:00"}}}, {"match":{"type.keyword":"CampoTabla1"}}}}, "size":1000, "sort": [{"@timestamp": {"order": "asc"}}], "_source":{"includes":["@timestamp","el_var"]} }

Results:

{'took': 70, 'timed_out': False, '_shards': {'total': 40, 'successful': 40, 'skipped': 36, 'failed': 0}, 'hits': {'total': {'value': 64, 'relation': 'eq'}, 'max_score': None, 'hits': [ ... {'_index': 'kpi-000395', '_type': '_doc', '_id': 'oudDNn8B4bqQsUm_acZW', '_score': None, '_source': {'@timestamp': '2022-02-26T07:15:00.000-03:00', 'el_var': '0.04'}, 'sort': [1645870500000]}, {'_index': 'kpi-000395', '_type': '_doc', '_id': 'hfn6NX8BJ-wjLp01PocL', '_score': None, '_source': {'@timestamp': '2022-02-26T07:15:00.000-03:00', 'el_var': '0.04'}, 'sort': [1645870500000]}, {'_index': 'kpi-000395', '_type': '_doc', '_id': 'ErjnNX8B4bqQsUm_4B5v', '_score': None, '_source': {'@timestamp': '2022-02-26T07:15:00.000-03:00', 'el_var': '0.04'}, 'sort': [1645870500000]}, {'_index': 'kpi-000395', '_type': '_doc', '_id': 'pB76NX8BjW58xE3kLh0Z', '_score': None, '_source': {'@timestamp': '2022-02-26T07:30:00.000-03:00', 'el_var': '0.05'}, 'sort': [1645871400000]}, {'_index': 'kpi-000395', '_type': '_doc', '_id': '0Pn6NX8BJ-wjLp01LnMq', '_score': None, '_source': {'@timestamp': '2022-02-26T07:30:00.000-03:00', 'el_var': '0.05'}, 'sort': [1645871400000]}, {'_index': 'kpi-000395', '_type': '_doc', '_id': '2zMMNn8B4bqQsUm_e4JZ', '_score': None, '_source': {'@timestamp': '2022-02-26T07:30:00.000-03:00', 'el_var': '0.05'}, 'sort': [1645871400000]} }]}}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source