elasticsearch/elasticsearch — Issue #1645: Counts in date histogram facets are inaccurate on nested documents
Author: markbirbeck
Created: 2012-01-27 08:49:13+00:00
State: open

When using date histogram facets we're finding that the values returned are incorrect when using nested documents.

A script to load 5 documents and query them is here:

https://gist.github.com/1684494

It loads documents with the following structure:

```json
{
"title": "Article x",
"actions": [
{"date": "2010-11-18", "updated": 1, "action": "updated"}
]
}
```

and then queries for all documents that are called 'Article 1', with date of '2011-11-18'. This correctly has 1 as the value for the _updated_ facet.

However, if the script is changed to load _6_ documents, the same query returns a facet count of 2 instead of 1:

https://gist.github.com/1684506

We've shown that increasing the number of stored records also gradually increases the error, but this is the smallest number of records we've found that illustrates the problem.

We've also found on our live system with millions of documents, that if we increase the date range in the nested part of the query that then reduces the scale of the error. However, we've not been able to come up with a set of scripts that illustrates that problem.

We're using ES 0.18.7.