# What's wrong with this query?

**URL:** <https://discuss.elastic.co/t/whats-wrong-with-this-query/22720>\
**Category:** Elasticsearch\
**Created:** [March 17, 2015, 6:32pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query/22720 "2015-03-17T18:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrkroeg](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@jrkroeg](https://discuss.elastic.co/u/jrkroeg)\
**Post date:** [March 17, 2015, 6:32pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query/22720/1 "2015-03-17T18:32:12Z")

</div>

I'm trying to get the top 100 documents which match the filtered criteria,  
and sort by distance from the pin.location.

Here's my query - which isn't resulting in error, but should be returning  
results:

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": [  
{  
"term": {  
"searchTerm1": "N"  
}  
},  
{  
"term": {  
"searchTerm2": "Y"  
}  
},  
{  
"term": {  
"searchTerm3": "Y"  
}  
},  
{  
"term": {  
"searchTerm4": "Y"  
}  
}  
]  
}  
},  
"sort": [  
{  
"\_geo\_distance": {  
"pin.location": {  
"lat": 34.073620,  
"lon": -118.400356  
},  
"order": "asc",  
"unit": "mi"  
}  
}  
],  
"size": 100  
}

On a separate note, I'd like to find a way to make the filter more of a  
suggestion, rather than forced - how would I achieve this?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@roger](https://discuss.elastic.co/u/roger)\
**Post date:** [March 17, 2015, 6:55pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query/22720/2 "2015-03-17T18:55:11Z")

</div>

Look at this example on how to use multiple filters:

> **[Boolean query | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)**

You should wrap them on a bool filter

2015-03-17 15:32 GMT-03:00 jrkroeg [jrkroeg@gmail.com](mailto:jrkroeg@gmail.com):

> I'm trying to get the top 100 documents which match the filtered criteria,  
> and sort by distance from the pin.location.
> 
> Here's my query - which isn't resulting in error, but should be returning  
> results:
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": [  
> {  
> "term": {  
> "searchTerm1": "N"  
> }  
> },  
> {  
> "term": {  
> "searchTerm2": "Y"  
> }  
> },  
> {  
> "term": {  
> "searchTerm3": "Y"  
> }  
> },  
> {  
> "term": {  
> "searchTerm4": "Y"  
> }  
> }  
> ]  
> }  
> },  
> "sort": [  
> {  
> "\_geo\_distance": {  
> "pin.location": {  
> "lat": 34.073620,  
> "lon": -118.400356  
> },  
> "order": "asc",  
> "unit": "mi"  
> }  
> }  
> ],  
> "size": 100  
> }
> 
> On a separate note, I'd like to find a way to make the filter more of a  
> suggestion, rather than forced - how would I achieve this?
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/22379295-332d-4ebe-aef3-6c9b2326e755%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAJp2533a5NcTmSnSYBDTJtmPpVk9a1vyiO9TZkYnPqdyP3TwnQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAJp2533a5NcTmSnSYBDTJtmPpVk9a1vyiO9TZkYnPqdyP3TwnQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:26am UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query/22720/3 "2017-07-06T00:26:08Z")

</div>


