Issue 1:
I've got an issue with facet counts that I've managed to simplify into a re-creatable example (attached).

When searching an index I get a facet count for 'fabric' as 12 however when I then filter on that attribute it increases to 13, not sure how this is possible as by adding a must query I can surely only decrease the facet counts.

Attached is the script which should recreate the issue in a test_bug index, it will insert 118 documents and run a query where the "fabric" facet comes out at 12.

Query looks like:

{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_operator": "AND",
"fields": [
"_all"
],
"query": "double"
}
}
]
}
},
"facets": {
"styles": {
"terms": {
"field": "product_styles"
}
}
},
"size": 1
}

Facet comes out as:

"facets" : {
"styles" : {
"_type" : "terms",
"missing" : 11,
"total" : 243,
"other" : 141,
"terms" : [ {
"term" : "beds",
"count" : 19
}, {
"term" : "fabric",
"count" : 12
}, {
"term" : "products",
"count" : 11
}, {
"term" : "new",
"count" : 11
}, {
"term" : "luxury",
"count" : 10
}, {
"term" : "furniture",
"count" : 10
}, {
"term" : "upholstered",
"count" : 8
}, {
"term" : "kingsize",
"count" : 7
}, {
"term" : "double",
"count" : 7
}, {
"term" : "bedroom",
"count" : 7
} ]
}

When adding a filter on the fabric like this:

{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_operator": "AND",
"fields": [
"_all"
],
"query": "double"
}
},
{
"term": {
"product_styles": "fabric"
}
}
]
}
},
"facets": {
"styles": {
"terms": {
"field": "product_styles"
}
}
},
"size": 1
}

the fabric facet then increases to 13:

"facets" : {
"styles" : {
"_type" : "terms",
"missing" : 0,
"total" : 186,
"other" : 97,
"terms" : [ {
"term" : "fabric",
"count" : 13
}, {
"term" : "beds",
"count" : 12
}, {
"term" : "upholstered",
"count" : 9
}, {
"term" : "luxury",
"count" : 9
}, {
"term" : "products",
"count" : 8
}, {
"term" : "new",
"count" : 8
}, {
"term" : "kingsize",
"count" : 8
}, {
"term" : "double",
"count" : 8
}, {
"term" : "furniture",
"count" : 7
}, {
"term" : "bedroom",
"count" : 7
} ]
}

Hopefully I've explained everything and you can also recreate this. I'm using elasticsearch-0.19.1 on Mac OS X Lion.

Script for recreating data is at https://gist.github.com/2283964

Issue 2:
I'm working with nested documents and have noticed that my faceted search interface is giving the wrong counts when I have more than one shard. To be more specific, I'm working with RDF triples (entity > attribute > value) and I'm nesting the attributes (called predicates in my example):

{
"_id" : "512a2c022f0b4e3daa341e6c8bcf6c2f",
"url": "http://dbpedia.org/resource/Alan_Shepard",
"predicates": [
{
"type": "type",
"string_value": ["thing", "person", "astronaut"]
}, {
"type": "label",
"string_value": ["Alan Shepard"]
}, {
"type": "time in space",
"float_value": [216.950]
},
... lots more
]
}

I've created a shell script (https://gist.github.com/1196986) that recreates the problem with a fresh index. The created data set has these totals:

thing (30)

creative work (20)

video game (10)

tv show (10)

people (10)

With only one shard the following query gives the correct counts no matter what the size parameter is set to:

{
"size": 0,
"query": {
"match_all": {}
},
"facets": {
"type_counts": {
"terms": {
"field": "string_value",
"size": 5
},
"nested": "predicates",
"facet_filter": {
"term": {
"type": "type"
}
}
}
}
}

However, with more than one shard the size parameter affects the accuracy of the counts. If it is equal to or greater than the number of terms returned by the facet query (5 in this case) then it works fine. However, the terms at the bottom of the list start to display low counts as you reduce the size parameter:

With "size" : 4

thing (30)

creative work (20)

video game (10)

tv show (9)

With "size" : 3

thing (30)

creative work (15)

video game (9)

With "size" : 2

thing (30)

creative work (15)

So it looks like the sub-totals from some of the shards aren't being included for some reason. BTW I'm on ubuntu and the problem seems to affect all versions of ES I've tried (17.0, 17.1 and 17.6). Any ideas...?

P.S. absolutely loving ES - it's made my life a lot easier :)