# Incorrect data from elasticsearch query?

**URL:** <https://discuss.elastic.co/t/incorrect-data-from-elasticsearch-query/23439>\
**Category:** Elasticsearch\
**Created:** [April 28, 2015, 2:32pm UTC](https://discuss.elastic.co/t/incorrect-data-from-elasticsearch-query/23439 "2015-04-28T14:32:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trekr5](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@trekr5](https://discuss.elastic.co/u/trekr5)\
**Post date:** [April 28, 2015, 2:32pm UTC](https://discuss.elastic.co/t/incorrect-data-from-elasticsearch-query/23439/1 "2015-04-28T14:32:19Z")

</div>

Hello,

I'm attempting to extract the number of status 500 errors from an  
ElasticSearch server over a range of time and I believe that the data is  
incorrect or too high and believe that the query may be incorrect. (I'm  
using a search query from logstash and dumping it straight into a ruby  
script.

#elastic.rb

require 'elasticsearch'

client = Elasticsearch::Client.new hosts: [{host: '10.10.10.10', port:  
9200}]

value = client.search index: '2015.04.28',  
body: {  
"facets"=\> {  
"0"=\> {  
"date\_histogram"=\> {  
"field"=\> "@timestamp",  
"interval"=\> "15m"  
},  
"global"=\> true,  
"facet\_filter"=\> {  
"fquery"=\> {  
"query"=\> {  
"filtered"=\> {  
"query"=\> {  
"query\_string"=\> {  
"query"=\> "type:iis6 AND status:500"  
}  
},  
"filter"=\> {  
"bool"=\> {  
"must"=\> [  
{  
"range"=\> {  
"@timestamp"=\> {  
"from"=\> "#{last\_time}",  
"to"=\> "#{current\_time}"  
}  
}  
}  
]  
}  
}  
}  
}  
}  
}  
}  
},  
"size"=\> 0  
}

values = value["hits"]["total"] # where current\_time is current time in  
epoch and last\_time is current\_time-7200(2 hours)

I'm getting a very high value (over 340,000) when I should be getting a  
value of say 272 errors over a 2 hour period.

Can you please tell me what I'm doing wrong?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36623448-ae2d-426b-b870-54804797853b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36623448-ae2d-426b-b870-54804797853b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:17am UTC](https://discuss.elastic.co/t/incorrect-data-from-elasticsearch-query/23439/2 "2017-07-06T00:17:22Z")

</div>

Closed on July 6, 2017, 12:17am UTC


