1

I would like to make a query in elastic search such as I only get the last 40 data I have on my database. For the moment my query is such :

  {
    "size": 40,
    "query" : {
      "exists": {
      "field": "transaction.domain"
      }
      "range": {
      "@timestamp" : {
          "from": "now-30mn",
          "to": "now"
      }
    }
    }
  }

Thanks for your help. Victoire

1 Answer 1

3

You are almost there, you just need to add sorting on your timestamp field.

below query should work for you.

{
    "size": 40,
    "query": {
        "exists": {
            "field": "transaction.domain"
        },
        "range": {
            "@timestamp": {
                "from": "now-30mn",
                "to": "now"
            }
        }
    },
    "sort": [
        {
            "@timestamp": "desc"
        }
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.