# Elasticsearch API Search query does not give correct results between timestamp range

**URL:** https://discuss.elastic.co/t/elasticsearch-api-search-query-does-not-give-correct-results-between-timestamp-range/268786
**Category:** Elasticsearch
**Created:** [March 30, 2021, 12:18pm UTC](https://discuss.elastic.co/t/elasticsearch-api-search-query-does-not-give-correct-results-between-timestamp-range/268786 "2021-03-30T12:18:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![suresh123](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@suresh123](https://discuss.elastic.co/u/suresh123)
#### Post date: [March 30, 2021, 12:18pm UTC](https://discuss.elastic.co/t/elasticsearch-api-search-query-does-not-give-correct-results-between-timestamp-range/268786/1 "2021-03-30T12:18:27Z")

</div>

Hello Guys,

I have been facing this issue for last 2 days. Can anyone pls help on below issue.

Am able to get exact hit counts for example 750755, but field results am not getting between timestamp range. Only few results around 6 or 7 am getting suppose to get 750755 results.

**My query is**

curl -X GET "http://elasticsearch\_ip:port/qa-web-logs-\*/\_search?track\_total\_hits=true&rest\_total\_hits\_as\_int=true&pretty" -H 'Content-Type: application/json' -d'  
{

```
"_source": ["request", "referrer", "response_code", "timestamp"],
"query": {
    "bool": {
      "should": [
        {
            "match": {
                    "referrer": ".*"
            }

        },
        {
          "range" : {
            "timestamp" : {
              "gte": "2021-03-28T02:00:00",
          "lt": "now"
            }
          }
        }
       ],
       "must_not": [
    {
      "match": {
        "response_code": "200"
      }
    }
  ]
}

```

}

}  
'

**Output**

{  
"took" : 1548,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 19,  
"successful" : 19,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : 750755,  
"max\_score" : 1.0,  
"hits" : [  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "8SCDMDNFDXCSDFNDJFDJF",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value1",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:57.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "SDSDSDHSDHSHDHS",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value2",  
"referrer" : "[https://www.google.com/](https://www.google.com/)",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:57.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "SDSDJmscnsnsm",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value3",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:57.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "asdssdnsnsjnADNJSDA",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value3",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:58.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "sdfnsdjfsdjfsdjf",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value4",  
"referrer" : "-",  
"response\_code" : 301,  
"timestamp" : "2021-03-28T13:26:58.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "sdnasjdsjadasj",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value5",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:58.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "ASDSBSNBFNBF",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value6",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:59.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "sdnsdnsdbvnbvn",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value7",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:26:57.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "ASNSNCBSNBSNB",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value8",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T13:27:01.000Z"  
}  
},  
{  
"\_index" : "qa-web-logs-2021.03.28",  
"\_type" : "\_doc",  
"\_id" : "SSFSNFBSNFSN",  
"\_score" : 1.0,  
"\_source" : {  
"request" : "value9",  
"referrer" : "-",  
"response\_code" : 304,  
"timestamp" : "2021-03-28T12:03:27.000Z"  
}  
}  
]  
}  
}

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [March 30, 2021, 2:01pm UTC](https://discuss.elastic.co/t/elasticsearch-api-search-query-does-not-give-correct-results-between-timestamp-range/268786/2 "2021-03-30T14:01:25Z")

</div>

Please do not open more than 1 thread on the same topic.

> [@Elasticsearch query time range issue](https://discuss.elastic.co/t/elasticsearch-query-time-range-issue/268672):
>
> Hello Experts, I am not able to retrieve all the status\_code values with below query. It has given only less value than actual values. \*\*My query\*\* "\_source": ["status\_code", "referrer", "timestamp"], "query": { "bool": { "should": [ { "match": { "referrer": ".\*" } }, { "range" : { "timestamp" : { "gte": "2021-03-28T06:00:00.000Z…

Please continue the discussion in that thread.

Please provide a set of sample data and sample that were not returned.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [March 30, 2021, 2:02pm UTC](https://discuss.elastic.co/t/elasticsearch-api-search-query-does-not-give-correct-results-between-timestamp-range/268786/3 "2021-03-30T14:02:19Z")

</div>


