Elastic 5.4.3: Geo_Distance confusion

Hi,

I'm pretty new to elastic and I'm using Elastic 5.4.3. I'm trying to perform a bool query search using "must" and also apply a geo_distance filter at the same time. My results are not quite what I'm expecting.

I'm expecting 2 records back, but only getting 1.

My geo_distance filter successfully returns a record in Bellevue, WA, which is within 15 miles of the lat/lon I specified below, but there is also a record that has a value of "Seattle, WA United States" in the "customer_location" field. I would think this record would be returned also, but it's not. I basically want to return any records that match the value in the customer_location field as well as any records that fall within my geo_distance filter.

Any idea why?

My code which I'm running from Kibana:

 GET /businesses/postings/_search
    {
        "query": {
            "bool" : {
                "must" : {
                   "match" : {
                      "customer_location": "Seattle, WA United States"
                     
                   } 
                },
                "filter" : {
                    "geo_distance" : {
                        "distance" : "15miles",
                        "geo_location" : {
                            "lat" : 47.6062,
                            "lon" : -122.3321
                        }
                    }
                }
            }
        }
    }

Can you show us the two documents you are expecting to match?

Use should instead of must I think

@warkolm - I put together a simple example with two docs and it seems to be working using the original code I had. My index is a bit more complex so I think there must be something else going on and I probably need to do some more debugging.

Here is working example which should return 2 hits as Bellevue, WA is within 7 miles of Seattle, or at least the lat/longitude I'm using in the example meets that criteria

PUT /customer/?pretty

PUT customer/_mapping/external
{
  "properties": {
    
    "customer_location": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "geo_location": {
      "type": "geo_point"
    }
    
    
  }
}

PUT /customer/external/1?pretty
{
  "name": "Macrosoft Corporation",
  "customer_location" : "Seattle, WA",
  "geo_location": "47.606209,-122.332071"
}

PUT /customer/external/2?pretty
{
  "name": "Fusion Technologies",
  "customer_location" : "Bellevue, WA",
  "geo_location": "47.610150,-122.201516"
}

GET /customer/external/_search
{
"query": {
    "bool" : {
        "must" : {
           "match" : {
             "customer_location": "Seattle, WA"
             
           } 
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "7miles",
                "geo_location" : {
                    "lat" : 47.606209,
                    "lon" : -122.332071
                }
            }
        }
    }
}
}

@dadoonet - There doesn't seem to be an "instead" when using a bool query. I get this error:

"error": {
"root_cause": [
  {
    "type": "parsing_exception",
    "reason": "[bool] query does not support [instead]",
    "line": 4,
    "col": 25
  }
],
"type": "parsing_exception",
"reason": "[bool] query does not support [instead]",
"line": 4,
"col": 25
  },
  "status": 400
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.