elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.87k stars 24.72k forks source link

NullPointerException on scroll where initial query with geohash_grid aggrigations #9878

Closed estin closed 9 years ago

estin commented 9 years ago

start elasticsearch in docker

sudo docker run -p 9200:9200 -p 9300:9300 -v `pwd`/esdata:/data dockerfile/elasticsearch /elasticsearch/bin/elasticsearch

check elasticsearch version in output

script

#!/bin/bash
echo 'version'
curl -XGET 'http://localhost:9200' | python -mjson.tool

echo;
curl -XDELETE 'http://localhost:9200/places'
sleep 1;
curl -XPOST 'http://localhost:9200/places' -d'{
    "mappings": {
        "place": {
            "_id": {
                "path": "id"
            },
            "properties": {
                "id": {"type": "long"},
                "name": {"type": "string"},
                "alias": {"type": "string"},
                "location": {
                    "type": "geo_point",
                    "geohash": true,
                    "geohash_prefix": true,
                    "geohash_precision": 1
                },
                "popup": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "alias": {"type": "string"}
                    }
                }
            }
        }
    }
}
'
curl -XPOST 'http://localhost:9200/places/_refresh'

echo;
echo 'bulk create documents'
curl -XPOST 'http://localhost:9200/_bulk?refresh=true' -d '{"index": {"_type": "place", "_id": 1455, "_index": "places"}}
{"popup": {"alias": "place0", "name": "place0"}, "alias": "place0", "location": {"lat": 41.101, "lon": 41.1}, "id": 1455, "name": "place0"}
{"index": {"_type": "place", "_id": 1456, "_index": "places"}}
{"popup": {"alias": "place1", "name": "place1"}, "alias": "place1", "location": {"lat": 41.101, "lon": 41.1}, "id": 1456, "name": "place1"}
{"index": {"_type": "place", "_id": 1457, "_index": "places"}}
{"popup": {"alias": "place2", "name": "place2"}, "alias": "place2", "location": {"lat": 41.101, "lon": 41.1}, "id": 1457, "name": "place2"}
{"index": {"_type": "place", "_id": 1458, "_index": "places"}}
{"popup": {"alias": "place3", "name": "place3"}, "alias": "place3", "location": {"lat": 41.102, "lon": 41.1}, "id": 1458, "name": "place3"}
{"index": {"_type": "place", "_id": 1459, "_index": "places"}}
{"popup": {"alias": "place4", "name": "place4"}, "alias": "place4", "location": {"lat": 41.102, "lon": 41.1}, "id": 1459, "name": "place4"}
{"index": {"_type": "place", "_id": 1460, "_index": "places"}}
{"popup": {"alias": "place5", "name": "place5"}, "alias": "place5", "location": {"lat": 41.103, "lon": 41.1}, "id": 1460, "name": "place5"}
{"index": {"_type": "place", "_id": 1461, "_index": "places"}}
{"popup": {"alias": "place6", "name": "place6"}, "alias": "place6", "location": {"lat": 41.103, "lon": 41.1}, "id": 1461, "name": "place6"}
{"index": {"_type": "place", "_id": 1462, "_index": "places"}}
{"popup": {"alias": "place7", "name": "place7"}, "alias": "place7", "location": {"lat": 41.105, "lon": 41.1}, "id": 1462, "name": "place7"}
{"index": {"_type": "place", "_id": 1463, "_index": "places"}}
{"popup": {"alias": "place8", "name": "place8"}, "alias": "place8", "location": {"lat": 41.106, "lon": 41.1}, "id": 1463, "name": "place8"}
{"index": {"_type": "place", "_id": 1464, "_index": "places"}}
{"popup": {"alias": "place9", "name": "place9"}, "alias": "place9", "location": {"lat": 41.107, "lon": 41.1}, "id": 1464, "name": "place9"}
'

RES=$(curl -XGET 'http://localhost:9200/places/place/_search?scroll=10m' -d '{
  "aggs": {
    "clusters": {
      "aggs": {
        "popup": {
          "top_hits": {
            "_source": {
              "include": [
                "location",
                "popup"
              ]
            },
            "size": 1,
            "sort": [
              {
                "_id": {
                  "order": "desc"
                }
              }
            ]
          }
        }
      },
      "geohash_grid": {
        "field": "location",
        "precision": 8
      }
    }
  },
  "filter": {
      "geo_bounding_box": {
          "location": {
            "bottom_left": {
              "lat": 41.1,
              "lon": 41.09
            },
            "top_right": {
              "lat": 41.11,
              "lon": 41.108
            }
          }
        }
   },
  "size": 2
}')

echo;
echo 'result'
echo $RES | python -mjson.tool

echo;
echo 'scroll_id'
SCROLL_ID=$(echo $RES | python -c"import sys, json; sys.stdout.write(json.loads(sys.stdin.read())['_scroll_id'])")
echo $SCROLL_ID

echo;
echo 'scroll next'
curl -XGET "http://localhost:9200/_search/scroll?scroll=10m&size=10" -d"$SCROLL_ID" | python -mjson.tool

output

version
{
    "cluster_name": "elasticsearch",
    "name": "Fever Pitch",
    "status": 200,
    "tagline": "You Know, for Search",
    "version": {
        "build_hash": "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
        "build_snapshot": false,
        "build_timestamp": "2015-02-19T13:05:36Z",
        "lucene_version": "4.10.3",
        "number": "1.4.4"
    }
}

{"acknowledged":true}{"acknowledged":true}{"_shards":{"total":10,"successful":4,"failed":0}}
bulk create documents
{"took":397,"errors":false,"items":[{"index":{"_index":"places","_type":"place","_id":"1455","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1456","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1457","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1458","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1459","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1460","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1461","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1462","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1463","_version":1,"status":201}},{"index":{"_index":"places","_type":"place","_id":"1464","_version":1,"status":201}}]}
result
{
    "_scroll_id": "cXVlcnlUaGVuRmV0Y2g7NTsxNTY6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNjA6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTg6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTk6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTc6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzswOw==",
    "_shards": {
        "failed": 0,
        "successful": 5,
        "total": 5
    },
    "aggregations": {
        "clusters": {
            "buckets": [
                {
                    "doc_count": 3,
                    "key": "szm1z60n",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1457",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.101,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place2",
                                            "name": "place2"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 3
                        }
                    }
                },
                {
                    "doc_count": 2,
                    "key": "szm1z684",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1460",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.103,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place5",
                                            "name": "place5"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 2
                        }
                    }
                },
                {
                    "doc_count": 2,
                    "key": "szm1z62h",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1458",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.102,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place3",
                                            "name": "place3"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 2
                        }
                    }
                },
                {
                    "doc_count": 1,
                    "key": "szm1z721",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1464",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.107,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place9",
                                            "name": "place9"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 1
                        }
                    }
                },
                {
                    "doc_count": 1,
                    "key": "szm1z705",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1463",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.106,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place8",
                                            "name": "place8"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 1
                        }
                    }
                },
                {
                    "doc_count": 1,
                    "key": "szm1z6bj",
                    "popup": {
                        "hits": {
                            "hits": [
                                {
                                    "_id": "1462",
                                    "_index": "places",
                                    "_score": null,
                                    "_source": {
                                        "location": {
                                            "lat": 41.105,
                                            "lon": 41.1
                                        },
                                        "popup": {
                                            "alias": "place7",
                                            "name": "place7"
                                        }
                                    },
                                    "_type": "place",
                                    "sort": [
                                        null
                                    ]
                                }
                            ],
                            "max_score": null,
                            "total": 1
                        }
                    }
                }
            ]
        }
    },
    "hits": {
        "hits": [],
        "max_score": null,
        "total": 0
    },
    "timed_out": false,
    "took": 6
}

scroll_id
cXVlcnlUaGVuRmV0Y2g7NTsxNTY6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNjA6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTg6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTk6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzsxNTc6SkFXblB6OTdSZFNtZGpuQ01yMUpJZzswOw==

scroll next
{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[JAWnPz97RdSmdjnCMr1JIg][places][0]: QueryPhaseExecutionException[[places][0]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[JAWnPz97RdSmdjnCMr1JIg][places][1]: QueryPhaseExecutionException[[places][1]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[JAWnPz97RdSmdjnCMr1JIg][places][2]: QueryPhaseExecutionException[[places][2]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[JAWnPz97RdSmdjnCMr1JIg][places][3]: QueryPhaseExecutionException[[places][3]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[JAWnPz97RdSmdjnCMr1JIg][places][4]: QueryPhaseExecutionException[[places][4]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }]",
    "status": 500
}

Sorry for my poor English

clintongormley commented 9 years ago

Hi @colings86 - please could you take a look at this one too.

colings86 commented 9 years ago

Exception logged on server is listed below. This is strange as it seems that the top hits aggregator is being run on the 'scroll next' call when it should only be run on the initial scan.

org.elasticsearch.search.query.QueryPhaseExecutionException: [places][0]: query[ConstantScore(cache(_type:place))],from[2],size[2]: Query Failed [Failed to execute main query]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:314)
    at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:299)
    at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:1)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.apache.lucene.search.TopFieldCollector$OutOfOrderOneComparatorNonScoringCollector.collect(TopFieldCollector.java:134)
    at org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregator.collect(TopHitsAggregator.java:118)
    at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.collectBucketNoCounts(BucketsAggregator.java:74)
    at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.collectExistingBucket(BucketsAggregator.java:63)
    at org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregator.collect(GeoHashGridAggregator.java:83)
    at org.elasticsearch.search.aggregations.AggregationPhase$AggregationsCollector.collect(AggregationPhase.java:161)
    at org.elasticsearch.common.lucene.MultiCollector.collect(MultiCollector.java:60)
    at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:193)
    at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:163)
    at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:35)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:621)
    at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)
    at org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:243)
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:136)
    ... 7 more
colings86 commented 9 years ago

The issue can be reproduced on the 1.4 branch but not on the master branch. I haven't checked any other versions.

@estin could you confirm which version of Elasticsearch you are running?

estin commented 9 years ago

1.4.4

docker image - https://github.com/dockerfile/elasticsearch

curl -XGET 'http://localhost:9200

version
{
    "cluster_name": "elasticsearch",
    "name": "Fever Pitch",
    "status": 200,
    "tagline": "You Know, for Search",
    "version": {
        "build_hash": "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
        "build_snapshot": false,
        "build_timestamp": "2015-02-19T13:05:36Z",
        "lucene_version": "4.10.3",
        "number": "1.4.4"
    }
}
estin commented 9 years ago

1.5.0 have this bug - NullPointerException, but error message changed compared to 1.4.4

{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[AJziGR-zRralfguZOlUAfw][places][0]: QueryPhaseExecutionException[[places][0]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:\"id\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@714de5ce>!]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[AJziGR-zRralfguZOlUAfw][places][1]: QueryPhaseExecutionException[[places][1]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:\"id\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@7bac1fe0>!]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[AJziGR-zRralfguZOlUAfw][places][2]: QueryPhaseExecutionException[[places][2]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:\"id\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@27e2ed3>!]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[AJziGR-zRralfguZOlUAfw][places][3]: QueryPhaseExecutionException[[places][3]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:\"id\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@e3d27fc>!]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }{[AJziGR-zRralfguZOlUAfw][places][4]: QueryPhaseExecutionException[[places][4]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:\"id\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@63735262>!]: Query Failed [Failed to execute main query]]; nested: NullPointerException; }]",
    "status": 500
}
[2015-03-27 07:12:24,639][DEBUG][action.search.type       ] [Kang the Conqueror] [327] Failed to execute query phase
org.elasticsearch.search.query.QueryPhaseExecutionException: [places][2]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.11, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:"id": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@27e2ed3>!]: Query Failed [Failed to execute main query]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:328)
        at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:299)
        at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:296)
        at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at org.apache.lucene.search.TopFieldCollector$OutOfOrderOneComparatorNonScoringCollector.collect(TopFieldCollector.java:134)
        at org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregator.collect(TopHitsAggregator.java:116)
        at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.collectBucketNoCounts(BucketsAggregator.java:74)
        at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.collectExistingBucket(BucketsAggregator.java:63)
        at org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregator.collect(GeoHashGridAggregator.java:83)
        at org.elasticsearch.search.aggregations.AggregationPhase$AggregationsCollector.collect(AggregationPhase.java:161)
        at org.elasticsearch.common.lucene.MultiCollector.collect(MultiCollector.java:60)
        at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:193)
        at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:163)
        at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:35)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:621)
        at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:581)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:533)
        at org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:424)
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:127)
        ... 7 more
estin commented 9 years ago

on 1.6.0

[2015-07-02 19:54:45,895][DEBUG][action.search.type       ] [Crimson Dynamo V] [28140] Failed to execute query phase
org.elasticsearch.search.query.QueryPhaseExecutionException: [places][3]: query[filtered(ConstantScore(+GeoBoundingBoxFilter(location, [41.1
1, 41.09], [41.1, 41.108])))->cache(_type:place)],from[2],size[2],sort[<score>,<custom:"id": org.elasticsearch.index.fielddata.fieldcomparat
or.LongValuesComparatorSource@392631ef>!]: Query Failed [Failed to execute main query]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:331)
        at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:299)
        at org.elasticsearch.search.action.SearchServiceTransportAction$9.call(SearchServiceTransportAction.java:296)
        at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
clintongormley commented 9 years ago

Fixed in master. Closing