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

NPE enclosed in a SearchParseException for a "point" type "geo_shape" filter or query #8432

Closed
astefan opened this issue Nov 11, 2014 · 4 comments · Fixed by #8785
Closed
Assignees
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v1.4.2

Comments

@astefan
Copy link
Contributor

astefan commented Nov 11, 2014

Given the following mapping and data:

PUT /my_index
{
  "mappings": {
    "landmark": {
      "properties": {
        "name": {
          "type": "string"
        },
        "location": {
          "type": "geo_shape"
        }
      }
    }
  }
}

POST /my_index/landmark/1
{"name":"Dam Square, Amsterdam","location":{"type":"polygon","coordinates":[[[4.89218,52.37356],[4.89205,52.37276],[4.89301,52.37274],[4.89392,52.3725],[4.89431,52.37287],[4.89331,52.37346],[4.89305,52.37326],[4.89218,52.37356]]]}}

The following query, either a "geo_shape" filter or query, fails with a SearchParseException enclosing a NullPointerException:

GET /my_index/landmark/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "point",
          "coordinates": [["4.901238","52.36936"]]
        }
      }
    }
  }
}

And the exception in logs:

Caused by: java.lang.NullPointerException
    at org.elasticsearch.common.geo.builders.PointBuilder.build(PointBuilder.java:59)
    at org.elasticsearch.common.geo.builders.PointBuilder.build(PointBuilder.java:29)
    at org.elasticsearch.index.query.GeoShapeQueryParser.getArgs(GeoShapeQueryParser.java:173)
    at org.elasticsearch.index.query.GeoShapeFilterParser.parse(GeoShapeFilterParser.java:178)
    at org.elasticsearch.index.query.QueryParseContext.executeFilterParser(QueryParseContext.java:315)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:296)
    at org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:74)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:252)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:382)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:276)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:665)
@astefan astefan added >bug v1.4.0 v1.3.4 :Analytics/Geo Indexing, search aggregations of geo points and shapes labels Nov 11, 2014
@astefan
Copy link
Contributor Author

astefan commented Nov 11, 2014

Another NPE happens for a query type "polygon":

{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "polygon",
          "coordinates": ["4.901238","52.36936"]
        }
      }
    }
  }
}

and the stacktrace:

Caused by: java.lang.NullPointerException
    at org.elasticsearch.common.geo.builders.ShapeBuilder$GeoShapeType.parsePolygon(ShapeBuilder.java:644)
    at org.elasticsearch.common.geo.builders.ShapeBuilder$GeoShapeType.parse(ShapeBuilder.java:597)
    at org.elasticsearch.common.geo.builders.ShapeBuilder.parse(ShapeBuilder.java:235)
    at org.elasticsearch.index.query.GeoShapeQueryParser.parse(GeoShapeQueryParser.java:86)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:252)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:382)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:276)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:665)

@s1monw
Copy link
Contributor

s1monw commented Dec 1, 2014

@nknize can you take a look at this?

@nknize nknize self-assigned this Dec 2, 2014
@nknize
Copy link
Contributor

nknize commented Dec 4, 2014

The following is probably obvious (and likely the intent of the test):

The GeoJSON in the query request is invalid. e.g.,

"shape": {
          "type": "point",
          "coordinates": [["4.901238","52.36936"]]
        }

Should either be:

"type": "multipoint",
...

or:

...
"coordinates": ["4.901238","52.36936"]}

Same with the polygon - it should be an array of LinearRings (closed LineStrings).

I'll add a more useful parse error message instead of the "give up" NPE.

FYI, most of the shape parsing logic can use better error handling so I'm certain this isn't the last NPE parse error. I'll be adding better error handling as I go so add the issues as you find them.

@s1monw
Copy link
Contributor

s1monw commented Dec 4, 2014

if ripping it out and redo is a potential better solution I am all for it @nknize especially if we can add unittests to it as well :)

nknize added a commit to nknize/elasticsearch that referenced this issue Dec 10, 2014
…filter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs.  Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes elastic#8432
nknize added a commit that referenced this issue Dec 10, 2014
…filter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs.  Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes #8432
nknize added a commit that referenced this issue Dec 10, 2014
…filter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs.  Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes #8432
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
…filter or query

This fix adds better error handling for parsing multipoint, linestring, and polygon GeoJSONs.  Current logic throws a NPE when parsing a multipoint, linestring, or polygon that does not comply with the GeoJSON specification. That is, if a user provides a single coordinate instead of an array of coordinates, or array of linestrings, the ShapeParser throws a NPE wrapped in a SearchParseException instead of a more useful error message.

Closes elastic#8432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v1.4.2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants