Skip to content

Instantly share code, notes, and snippets.

@mal
Last active August 29, 2015 14:03
Show Gist options
  • Save mal/2a36f5caa91e47fbcff7 to your computer and use it in GitHub Desktop.
Save mal/2a36f5caa91e47fbcff7 to your computer and use it in GitHub Desktop.
elasticsearch-issue-6827
SERVER=localhost:9200
REQUEST() {
curl -sS -X$1 "http://$SERVER$2" -d "$3"
echo
}
GET() {
REQUEST GET "$1"
}
POST() {
REQUEST POST "$1" "$2"
}
PUT() {
REQUEST PUT "$1" "$2"
}
DELETE() {
REQUEST DELETE "$1"
}
DELETE /t
PUT /t '{"settings": {"number_of_shards": 1}, "mappings": {"t": {"properties": {"vals": {"type": "string"}}}}}'
PUT /t/t/1 '{ "vals": [] }'
PUT /t/t/2 '{ "vals": [3,2,1] }'
PUT /t/t/3 '{ }'
PUT /t/t/4 '{ "vals": [984,987,54] }'
PUT /t/t/5 '{ "vals": [] }'
PUT /t/t/6 '{ }'
PUT /t/t/7 '{ "vals": [23,26,27] }'
PUT /t/t/8 '{ }'
PUT /t/t/9 '{ "vals": [] }'
sleep 1
POST /t/t/_search '
{
"script_fields": {
"lowest_val": {
"lang": "mvel",
"script": "set = doc['"'"'vals'"'"'].values; lowest = set[0]; for (candidate : set) { lowest = min(lowest, candidate); } return lowest;"
}
}
}
'
{"acknowledged":true}
{"acknowledged":true}
{"_index":"t","_type":"t","_id":"1","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"2","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"3","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"4","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"5","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"6","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"7","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"8","_version":1,"created":true}
{"_index":"t","_type":"t","_id":"9","_version":1,"created":true}
{"took":6,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":9,"max_score":1.0,"hits":[{"_index":"t","_type":"t","_id":"1","_score":1.0,"fields":{"lowest_val":[null]}},{"_index":"t","_type":"t","_id":"2","_score":1.0,"fields":{"lowest_val":[1]}},{"_index":"t","_type":"t","_id":"3","_score":1.0,"fields":{"lowest_val":["1"]}},{"_index":"t","_type":"t","_id":"4","_score":1.0,"fields":{"lowest_val":[54]}},{"_index":"t","_type":"t","_id":"5","_score":1.0,"fields":{"lowest_val":["54"]}},{"_index":"t","_type":"t","_id":"6","_score":1.0,"fields":{"lowest_val":["54"]}},{"_index":"t","_type":"t","_id":"7","_score":1.0,"fields":{"lowest_val":[23]}},{"_index":"t","_type":"t","_id":"8","_score":1.0,"fields":{"lowest_val":["23"]}},{"_index":"t","_type":"t","_id":"9","_score":1.0,"fields":{"lowest_val":["23"]}}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment