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

Range aggregation with no ranges throw a NullPointerException #22881

Closed
damienalexandre opened this issue Jan 31, 2017 · 7 comments · Fixed by #23241
Closed

Range aggregation with no ranges throw a NullPointerException #22881

damienalexandre opened this issue Jan 31, 2017 · 7 comments · Fixed by #23241
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories v5.2.0 v6.0.0-alpha2

Comments

@damienalexandre
Copy link
Contributor

Elasticsearch version: 5.1.1

Plugins installed: [analysis-icu]

JVM version: Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_111-internal/25.111-b14

OS version: Linux/4.8.0-34-generic/amd64

Description of the problem including expected versus actual behavior:

A NullPointerException is displayed to the user when the Range aggregation is malformed:

{
  "error": {
    "root_cause": [
      {
        "type": "null_pointer_exception",
        "reason": null
      }
    ],
    "type": "null_pointer_exception",
    "reason": null
  },
  "status": 500
}

Steps to reproduce:

  1. Run a badly formatted query:
GET /_search
{
  "aggs": {
    "foobar": {
      "range": {
        "field": "hey"
      }
    }
  }
}

Provide logs (if relevant):

Trace:

[2017-01-31T10:49:11,250][WARN ][r.suppressed             ] path: /_search, params: {}
java.lang.NullPointerException: null
	at org.elasticsearch.search.aggregations.bucket.range.RangeParser.createFactory(RangeParser.java:58) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.aggregations.bucket.range.RangeParser.createFactory(RangeParser.java:39) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.parse(AbstractValuesSourceParser.java:150) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser$NumericValuesSourceParser.parse(AbstractValuesSourceParser.java:48) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:156) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:80) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.builder.SearchSourceBuilder.parseXContent(SearchSourceBuilder.java:1018) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.rest.action.search.RestSearchAction.parseSearchRequest(RestSearchAction.java:105) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.rest.action.search.RestSearchAction.prepareRequest(RestSearchAction.java:81) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:66) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.rest.RestController.executeHandler(RestController.java:243) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:200) [elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.http.HttpServer.dispatchRequest(HttpServer.java:113) [elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.http.netty4.Netty4HttpServerTransport.dispatchRequest(Netty4HttpServerTransport.java:507) [transport-netty4-5.1.1.jar:5.1.1]
	at org.elasticsearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:69) [transport-netty4-5.1.1.jar:5.1.1]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at org.elasticsearch.http.netty4.pipelining.HttpPipeliningHandler.channelRead(HttpPipeliningHandler.java:66) [transport-netty4-5.1.1.jar:5.1.1]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) [netty-codec-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:536) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:490) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) [netty-common-4.1.6.Final.jar:4.1.6.Final]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111-internal]
@giorgosp
Copy link
Contributor

giorgosp commented Feb 1, 2017

Hello @clintongormley @jpountz, I am looking for my first elasticsearch contribution!

However, I cannot reproduce this bug on my fresh elasticsearch build.
This is the response for GET /:

{
  "name": "node-0",
  "cluster_name": "distribution_run",
  "cluster_uuid": "fQLnWXIERNuBj5vWoNtBlw",
  "version": {
    "number": "6.0.0-alpha1",
    "build_hash": "a4ac29c",
    "build_date": "2017-01-23T13:54:32.228Z",
    "build_snapshot": true,
    "lucene_version": "6.4.0"
  },
  "tagline": "You Know, for Search"
}

and this is what I get for the issue's request:

GET /_search
{
  "aggs": {
    "foobar": {
      "range": {
        "field": "hey"
      }
    }
  }
}
{
  "took": 27,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "foobar": {
      "buckets": []
    }
  }
}

My java -version on OS X 10.11.6

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

I understand that my build is 1 version later, should I build the 5.1.1 version and check the issue?
Thanks!

@jpountz
Copy link
Contributor

jpountz commented Feb 1, 2017

Did you test on master or the 5.x branch? If it does not reproduce on 5.x, then then 5.1 branch is indeed what I would look at next.

@giorgosp
Copy link
Contributor

giorgosp commented Feb 1, 2017

Yes I was testing on master. I just checked 5.x, 5.1, 5.2 and it does reproduce on 5.1 only.
So I guess no further action is needed since it is ok on master and 5.x?

@jpountz
Copy link
Contributor

jpountz commented Feb 2, 2017

Good to know that issue is already fixed in 5.2! Thank you for investigating @giorgosp, we appreciate! I will close this issue now.

@jimczi
Copy link
Contributor

jimczi commented Feb 2, 2017

@giorgosp I don't think it's resolved in 5.x nor master. The only difference with 5.1 is that you need to have at least one document with the range field to fail the query. The following recreation for instance fails in 5.1, 5.2, 5.x and master:

PUT t/t/1
{
   "number": 3
}

GET /_search
{
  "aggs": {
    "foobar": {
      "range": {
        "field": "number"
      }
    }
  }
}

@jimczi jimczi reopened this Feb 2, 2017
@cbuescher cbuescher added the help wanted adoptme label Feb 2, 2017
@giorgosp
Copy link
Contributor

giorgosp commented Feb 2, 2017

Ok, I am checking it

@giorgosp
Copy link
Contributor

giorgosp commented Feb 3, 2017

Ok, it fails if the range aggregation query is invalid and the "field" value is an existing field inside the document (changing "field": "number" to "field": "number1123" doesn't reproduce the issue).

I will keep working on it in my spare time but since I am also trying to familiarize myself with the codebase, if someone else wants to fix it faster than me then it is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories v5.2.0 v6.0.0-alpha2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants