Reputation: 445
I am using Elasticsearch 7.6 and trying to run a query that runs a geo_distance query to find matching documents within an exact city OR within a distance range of 25 miles in this case.
In layman's terms, it would be "Do a search for all jobs in the city of "Santa Rosa, CA" OR 25 miles around it. If there are jobs within 25 miles of Santa Rosa, CA those documents should be returned in the search results in addition to any jobs where the "job_location" field is specifically "Santa Rosa, CA"
Here is my query, which returns 0 results despite there being matching documents within 25 miles of my specified longitude and latitude which is Santa Rosa, CA.
I must have the syntax wrong.
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "25 miles",
"geo_location": "38.440429,-122.7140548"
}
},
"must": [
{
"match": {
"active": true
}
},
{
"bool": {
"should": [
{
"term": {
"job_location": "Santa Rosa, CA"
}
}
]
}
}
]
}
}
}
Upvotes: 0
Views: 603
Reputation: 217254
Your query is not properly built. Try like this and it should work as you expect. The OR conditions should all be in bool/should
:
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"job_location": "Santa Rosa, CA"
}
},
{
"geo_distance": {
"distance": "25m",
"geo_location": "38.440429,-122.7140548"
}
}
],
"filter": [
{
"match": {
"active": true
}
}
]
}
}
}
Upvotes: 1