0

I have below raw elasticsearch query in which i want to change the @timestamp range.

import json
from elasticsearch_dsl import Search

query = """
{
  "query": {
    "range": {
      "@timestamp": {
        "gte": "now-1d/d",
        "lt": "now/d"
      }
    }
  },
  "aggs": {
    "my-agg-name": {
      "terms": {
        "field": "my-field"
      }
    }
  }
}
"""
s = Search().from_dict(json.loads(query))

I tried below approach, it adds additional range query but not update it. How can I update the existing range instead of adding additional one?

s = s.query("range", **{"@timestamp": {"gte": "now-10m", "lte": "now"}})
print(s)



{'query': {'bool': {'must': [{'range': {'@timestamp': {'gte': 'now-1d/d',
       'lt': 'now/d'}}},
    {'range': {'@timestamp': {'gte': 'now-10m', 'lte': 'now'}}}]}},
 'aggs': {'my-agg-name': {'terms': {'field': 'my-field'}}}}    
Sirish
  • 9,183
  • 22
  • 72
  • 107

0 Answers0