# Double Counting in Multi Field Facet Search

**URL:** <https://discuss.elastic.co/t/double-counting-in-multi-field-facet-search/11050>\
**Category:** Elasticsearch\
**Created:** [March 7, 2013, 9:38am UTC](https://discuss.elastic.co/t/double-counting-in-multi-field-facet-search/11050 "2013-03-07T09:38:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alistair\_Cooke](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@Alistair\_Cooke](https://discuss.elastic.co/u/Alistair_Cooke)\
**Post date:** [March 7, 2013, 9:38am UTC](https://discuss.elastic.co/t/double-counting-in-multi-field-facet-search/11050/1 "2013-03-07T09:38:06Z")

</div>

Hi,

I'm having a problem with double counting in facet results. I've got  
several types in the same index  
where the structure of some of the different types is quite similar. When I  
use a multi-field facet  
and include a field that's in one type, it counts it in all types. If I  
include the fields from both types,  
that I get double counted results. Is this what's expected? Also, it  
seems to work differently if I use a single field facet.

Here's a simplified example. Say I want to get a count of 'towns' from  
these 4 docs:

curl -XPUT $ES/example/policeman/policeman1 -d '{  
"name": "Policeman 1",  
"addresses": [  
{  
"streetAddress": "1 Example Road",  
"town": "OneTown"  
}  
]  
}'

curl -XPUT $ES/example/policeman/policeman2 -d ' {  
"name": "Policeman 2",  
"addresses": [  
{  
"streetAddress": "2 Example Road",  
"town": "OneTown"  
}  
]  
}'

curl -XPUT $ES/example/fireman/fireman1 -d '{  
"name": "Fireman Sam",  
"addresses": [  
{  
"streetAddress": "2 Example Road",  
"town": "OneTown"  
}  
]  
}'

curl -XPUT $ES/example/fireman/fireman2 -d '{  
"name": "Fireman Dave",  
"addresses": [  
{  
"streetAddress": "2 Other Road",  
"town": "TwoTown"  
}  
]  
}'

If i do:

$ curl -XPOST $ES/example/\_search?pretty=true -d '{  
"query" : { "match\_all" : { } },  
"facets" : {  
"town" : { "terms" : { "fields" : ["policeman.addresses.town"] } }  
}  
}'

I get onetown: 3, twotown: 1. So it counts the towns in both policeman and  
fireman types. If i do:

$ curl -XPOST $ES/example/\_search?pretty=true -d '{  
"query" : { "match\_all" : { } },  
"facets" : {  
"town" : { "terms" : { "fields" : ["policeman.addresses.town",  
"fireman.addresses.town"]] } }  
}  
}'  
I get onetown: 6, twotown: 2. So it's counted everything twice.

Thanks  
Alistair

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:47am UTC](https://discuss.elastic.co/t/double-counting-in-multi-field-facet-search/11050/2 "2017-07-06T02:47:50Z")

</div>


