# GeoLocated search and facet scoping

**URL:** <https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515>\
**Category:** Elasticsearch\
**Created:** [September 9, 2013, 1:10pm UTC](https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515 "2013-09-09T13:10:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billy\_Catherall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/billy_catherall/32/2119_2.png) [@Billy\_Catherall](https://discuss.elastic.co/u/Billy_Catherall)\
**Post date:** [September 9, 2013, 1:10pm UTC](https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515/1 "2013-09-09T13:10:50Z")

</div>

So we've been working with ElasticSearch and Geo Locations in Rails using  
Tire, and have run into an issue.

We have locations, those locations have several attributes that can be  
searched on including tags. Tags are also facets. Currently all the search  
attributes except location are included in the Tire search using a "must"  
query. The location part of the search is done via a filter. Right now the  
search results return an attribute, current\_tags, for the list of facets  
scoped by the current "must" query.

The problem is that current\_tags is not scoped by the location because it's  
a filter.

I can see two possible solutions. 1. move the location filter into the  
"must" query. 2. scope the current\_tags by the filter. Either of these  
would work if either of these were supported. Unfortunately I can't find  
anything on Elastic for how to support either of these options.

So if anyone knows how to get a list of facets out of ElasticSearch that  
have been scoped by a geo-aware search, I'd really appreciate a quick  
explanation on how to do it.

Thanks,

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 10, 2013, 3:22pm UTC](https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515/2 "2013-09-10T15:22:50Z")

</div>

If I understand your problem correctly (I might be wrong), it seems like  
you are using a query with a top-level filter. Can you provide an example  
query? If so, the easiest solution would be to change your query/filter  
into a filtered query. The documents faceted on will be only be those that  
pass the filtered query. In the case of a top-level filter, the documents  
faceted on will not be affected by the filter. In this case, you can also  
use the same top-level filter as as facet\_filter.

> **[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.

Cheers,

Ivan

On Mon, Sep 9, 2013 at 6:10 AM, Billy Catherall [bcatherall@gmail.com](mailto:bcatherall@gmail.com)wrote:

> So we've been working with Elasticsearch and Geo Locations in Rails using  
> Tire, and have run into an issue.
> 
> We have locations, those locations have several attributes that can be  
> searched on including tags. Tags are also facets. Currently all the search  
> attributes except location are included in the Tire search using a "must"  
> query. The location part of the search is done via a filter. Right now the  
> search results return an attribute, current\_tags, for the list of facets  
> scoped by the current "must" query.
> 
> The problem is that current\_tags is not scoped by the location because  
> it's a filter.
> 
> I can see two possible solutions. 1. move the location filter into the  
> "must" query. 2. scope the current\_tags by the filter. Either of these  
> would work if either of these were supported. Unfortunately I can't find  
> anything on Elastic for how to support either of these options.
> 
> So if anyone knows how to get a list of facets out of Elasticsearch that  
> have been scoped by a geo-aware search, I'd really appreciate a quick  
> explanation on how to do it.
> 
> Thanks,
> 
> --  
> 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).

--  
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:** ![Billy\_Catherall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/billy_catherall/32/2119_2.png) [@Billy\_Catherall](https://discuss.elastic.co/u/Billy_Catherall)\
**Post date:** [September 12, 2013, 12:13am UTC](https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515/3 "2013-09-12T00:13:43Z")

</div>

Thanks Ivan. That was exactly what I needed to fix it. Just wrapping both  
the query and the filter correctly (as in the link) did the trick.

On Tuesday, September 10, 2013 11:22:50 AM UTC-4, Ivan Brusic wrote:

> If I understand your problem correctly (I might be wrong), it seems like  
> you are using a query with a top-level filter. Can you provide an example  
> query? If so, the easiest solution would be to change your query/filter  
> into a filtered query. The documents faceted on will be only be those that  
> pass the filtered query. In the case of a top-level filter, the documents  
> faceted on will not be affected by the filter. In this case, you can also  
> use the same top-level filter as as facet\_filter.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query/)
> 
> Cheers,
> 
> Ivan
> 
> On Mon, Sep 9, 2013 at 6:10 AM, Billy Catherall \<[bcath...@gmail.com](mailto:bcath...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > So we've been working with Elasticsearch and Geo Locations in Rails using  
> > Tire, and have run into an issue.
> > 
> > We have locations, those locations have several attributes that can be  
> > searched on including tags. Tags are also facets. Currently all the search  
> > attributes except location are included in the Tire search using a "must"  
> > query. The location part of the search is done via a filter. Right now the  
> > search results return an attribute, current\_tags, for the list of facets  
> > scoped by the current "must" query.
> > 
> > The problem is that current\_tags is not scoped by the location because  
> > it's a filter.
> > 
> > I can see two possible solutions. 1. move the location filter into the  
> > "must" query. 2. scope the current\_tags by the filter. Either of these  
> > would work if either of these were supported. Unfortunately I can't find  
> > anything on Elastic for how to support either of these options.
> > 
> > So if anyone knows how to get a list of facets out of Elasticsearch that  
> > have been scoped by a geo-aware search, I'd really appreciate a quick  
> > explanation on how to do it.
> > 
> > Thanks,
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:17am UTC](https://discuss.elastic.co/t/geolocated-search-and-facet-scoping/13515/4 "2017-07-06T02:17:04Z")

</div>

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


