Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark GeoDistanceQuery distance property as required #2165

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Jun 30, 2023

geo_distance.distance parameter is required. If not provided, elasticsearch _search API returns a 400

Example of working query

GET kibana_sample_data_logs/_search
{
  "size": 10,
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "geo.coordinates"
                }
              },
              {
                "geo_distance": {
                  "distance": "100km",
                  "geo.coordinates": [
                    -107.31,
                    40.66
                  ]
                }
              }
            ]
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

Example of 400 query with distance not provided

GET kibana_sample_data_logs/_search
{
  "size": 10,
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "geo.coordinates"
                }
              },
              {
                "geo_distance": {
                  "geo.coordinates": [
                    -107.31,
                    40.66
                  ]
                }
              }
            ]
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

Error response

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "geo_distance requires 'distance' to be specified",
        "line": 21,
        "col": 17
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[21:17] [bool] failed to parse field [filter]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": "[21:17] [bool] failed to parse field [must]",
      "caused_by": {
        "type": "parsing_exception",
        "reason": "geo_distance requires 'distance' to be specified",
        "line": 21,
        "col": 17
      }
    }
  },
  "status": 400
}

@nreese nreese requested a review from delvedor June 30, 2023 14:36
Copy link
Contributor

@Anaethelion Anaethelion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nreese nreese merged commit 76e25d3 into elastic:main Jul 6, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants