Hello,
We hit an interesting bug a few days ago with our testing cluster. It ap…pears that if we do 2 consecutive updates to a document, **right after an elasticsearch restart**, the second update fails with `NullPointerException`. If we run the test script a second time (without restarting the server), the update succeeds.
Our test script that demostrates the issue:
```
# sudo /etc/init.d/elasticsearch restart && sleep 10 && bash test_es_mvel_issue
echo "Delete everything"
curl -X DELETE 'http://localhost:9200/_all?pretty'
echo "Create test index"
curl -X PUT 'http://localhost:9200/test?pretty'
echo "Add a document"
curl -X PUT 'http://localhost:9200/test/tweet/1?pretty' -d '{
"smth": "m"
}'
echo "Issue an update using mvel"
curl -X POST 'http://localhost:9200/test/tweet/1/_update?pretty' -d '{
"script": "foreach(field : updates.entrySet()) { ctx._source[field.key] = field.value; }",
"params": {
"updates": {
"1": 1,
"2": 1,
"3": 1,
"availability": null,
"5": 1,
"a": 1,
"b": 1,
"c": 1,
"d": 1,
"e": 1,
"f": 1,
"g": 1,
"h": 1,
"i": 1,
"j": 1,
"k": 1,
"l": 1,
"m": 1,
"n": 1,
"o": 1,
"p": 1,
"q": 1,
"r": 1,
"s": 1,
"t": 1,
"flter": 1
}
}
}'
echo "Issue a second update"
curl -X POST 'http://localhost:9200/test/tweet/1/_update?pretty' -d '{
"script": "foreach(field : updates.entrySet()) { ctx._source[field.key] = field.value; }",
"params": {
"updates": {
"1": 1,
"2": 1,
"3": 1,
"availability": null,
"5": 1,
"a": 1,
"b": 1,
"c": 1,
"d": 1,
"e": 1,
"f": 1,
"g": 1,
"h": 1,
"i": 1,
"j": 1,
"k": 1,
"l": 1,
"m": 1,
"n": 1,
"o": 1,
"p": 1,
"q": 1,
"r": 1,
"s": 1,
"t": 1,
"flter": 1
}
}
}'
#2014-03-20T15:20:30+02:00 [400] (0.016s)
#
# {
# "error": "ElasticSearchIllegalArgumentException[failed to execute script]; nested: NullPointerException; ",
# "status": 400
#
# }
```
The bug is reproducible to all elasticsearch versions (0.90, 1.0, 1.1, master).
Some interesting points that we noticed:
- It seems to depend on the payload, if we remove an attribute from the `updates` hash everything works.
- If we add some whitespace to the second's update mvel script, the update succeeds. Probably because it skips a cache.