Elasticsearch range request

138 Views Asked by At

I want to create a request that transmits me all the documents for last 15min. My XPUT document looks like this:

curl -XPUT localhost:9200/indexname/documentname/4 -d'
{
    "user": "sergey",
    "onlineUserCount": "43"
}'

I've searched like this:

$ curl -XGET localhost:9200/indexname/documentname/_query -d'{
"query":{
  "range":{
    "timestamp":{
      "gt": "now -15m"
    }
  }
}}'

But It gave me

{"_index":"indexname","_type":"documentname","_id":"_query","found":false}

Help please!!!

1

There are 1 best solutions below

7
On

You need to use the _search endpoint instead of the _query endpoint and it's more advisable to use -XPOST when sending a query in the HTTP request body.

$ curl -XPOST localhost:9200/indexname/documentname/_search -d'{
"query":{
  "range":{
    "timestamp":{
      "gt": "now -15m"
    }
  }
}}'