# Number of filter matches in array field

**URL:** <https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921>\
**Category:** Elasticsearch\
**Created:** [December 3, 2012, 4:25pm UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921 "2012-12-03T16:25:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Fitzmaurice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_fitzmaurice/32/2592_2.png) [@Doug\_Fitzmaurice](https://discuss.elastic.co/u/Doug_Fitzmaurice)\
**Post date:** [December 3, 2012, 4:25pm UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921/1 "2012-12-03T16:25:15Z")

</div>

I have a set of documents, each with an array of geo\_points:

{  
name: "Test Record",  
locations: [  
{  
lat: 55.866638  
lon: -4.289562  
},  
{  
lat: 50.716633  
lon: -1.878344  
},  
{  
lat: 51.53587  
lon: 0.696672  
},  
{  
lat: 52.479473  
lon: -1.909198  
},  
{  
lat: 51.490692  
lon: -0.224432  
}  
]  
}

When using a geo\_distance filter, is there a way to return, for each  
document, the number of locations that matched the filter (I.E. were within  
the search radius)?

Thanks!

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 3, 2012, 4:51pm UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921/2 "2012-12-03T16:51:53Z")

</div>

I am wondering if you are not looking for Geo Distance Facets [1], do you?

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

HTH  
David

Le 3 décembre 2012 à 17:25, Doug Fitzmaurice [doug.fitzmaurice@ents24.com](mailto:doug.fitzmaurice@ents24.com) a  
écrit :

> I have a set of documents, each with an array of geo\_points:
> 
> {  
> name : "Test Record" ,  
> locations : [  
> {  
> lat : 55.866638  
> lon : - 4.289562  
> },  
> {  
> lat : 50.716633  
> lon : - 1.878344  
> },  
> {  
> lat : 51.53587  
> lon : 0.696672  
> },  
> {  
> lat : 52.479473  
> lon : - 1.909198  
> },  
> {  
> lat : 51.490692  
> lon : - 0.224432  
> }  
> ]  
> }
> 
> When using a geo\_distance filter, is there a way to return, for each  
> document, the number of locations that matched the filter (I.E. were within  
> the search radius)?
> 
> Thanks!
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Doug\_Fitzmaurice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_fitzmaurice/32/2592_2.png) [@Doug\_Fitzmaurice](https://discuss.elastic.co/u/Doug_Fitzmaurice)\
**Post date:** [December 3, 2012, 4:59pm UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921/3 "2012-12-03T16:59:00Z")

</div>

I've had a go at using the geo\_distance facet, but as far as I can tell it  
returns the total number of documents that match each range, whereas I  
would like the number of locations that match _per-document_.

As an example, if I queried with a geo\_distance filter of "lat: 55, lon: -4" against  
the above document, I would expect one of the location entries to match, so  
the document would be returned, but I would like to know h_ow many_ of the  
location entries in that document match (even if the answer is only 1).

On Monday, December 3, 2012 4:51:53 PM UTC, David Pilato wrote:

> I am wondering if you are not looking for Geo Distance Facets [1], do  
> you?
> 
> [1]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/geo-distance-facet.html)
> 
> HTH  
> David
> 
> Le 3 décembre 2012 à 17:25, Doug Fitzmaurice \<[doug.fit...@ents24.com](mailto:doug.fit...@ents24.com)\<javascript:\>\>  
> a écrit :
> 
> I have a set of documents, each with an array of geo\_points:
> 
> {  
> name : "Test Record" ,  
> locations : [  
> {  
> lat : 55.866638  
> lon : - 4.289562  
> },  
> {  
> lat : 50.716633  
> lon : - 1.878344  
> },  
> {  
> lat : 51.53587  
> lon : 0.696672  
> },  
> {  
> lat : 52.479473  
> lon : - 1.909198  
> },  
> {  
> lat : 51.490692  
> lon : - 0.224432  
> }  
> ]  
> }
> 
> When using a geo\_distance filter, is there a way to return, for each  
> document, the number of locations that matched the filter (I.E. were within  
> the search radius)?
> 
> Thanks!
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Doug\_Fitzmaurice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_fitzmaurice/32/2592_2.png) [@Doug\_Fitzmaurice](https://discuss.elastic.co/u/Doug_Fitzmaurice)\
**Post date:** [December 5, 2012, 3:37pm UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921/4 "2012-12-05T15:37:00Z")

</div>

Could this be done using either highlighting or nested documents?

I had a go at using highlighting, but I can't find any documentation on  
using it with a geo\_distance filter, and I haven't been able to make it  
work.

Nested / child documents could also work, but most queries that operate on  
them seem to be focused on returning parents where any child matches a  
parameter, whereas I want to return the parent, and those child documents  
that caused the match.

On Monday, December 3, 2012 4:59:00 PM UTC, Doug Fitzmaurice wrote:

> I've had a go at using the geo\_distance facet, but as far as I can tell it  
> returns the total number of documents that match each range, whereas I  
> would like the number of locations that match _per-document_.
> 
> As an example, if I queried with a geo\_distance filter of "lat: 55, lon:  
> -4" against the above document, I would expect one of the location  
> entries to match, so the document would be returned, but I would like to  
> know h_ow many_ of the location entries in that document match (even if  
> the answer is only 1).
> 
> On Monday, December 3, 2012 4:51:53 PM UTC, David Pilato wrote:
> 
> > I am wondering if you are not looking for Geo Distance Facets [1], do  
> > you?
> > 
> > [1]  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/geo-distance-facet.html)
> > 
> > HTH  
> > David
> > 
> > Le 3 décembre 2012 à 17:25, Doug Fitzmaurice [doug.fit...@ents24.com](mailto:doug.fit...@ents24.com) a  
> > écrit :
> > 
> > I have a set of documents, each with an array of geo\_points:
> > 
> > {  
> > name : "Test Record" ,  
> > locations : [  
> > {  
> > lat : 55.866638  
> > lon : - 4.289562  
> > },  
> > {  
> > lat : 50.716633  
> > lon : - 1.878344  
> > },  
> > {  
> > lat : 51.53587  
> > lon : 0.696672  
> > },  
> > {  
> > lat : 52.479473  
> > lon : - 1.909198  
> > },  
> > {  
> > lat : 51.490692  
> > lon : - 0.224432  
> > }  
> > ]  
> > }
> > 
> > When using a geo\_distance filter, is there a way to return, for each  
> > document, the number of locations that matched the filter (I.E. were within  
> > the search radius)?
> > 
> > Thanks!
> > 
> > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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, 3:01am UTC](https://discuss.elastic.co/t/number-of-filter-matches-in-array-field/9921/5 "2017-07-06T03:01:15Z")

</div>


