Skip to content

Instantly share code, notes, and snippets.

@fosstrack
Forked from darklow/elasticsearch.custom.sort.py
Last active November 21, 2016 18:20
Show Gist options
  • Save fosstrack/b16ccb726fe88c8347f9 to your computer and use it in GitHub Desktop.
Save fosstrack/b16ccb726fe88c8347f9 to your computer and use it in GitHub Desktop.
Updated script to avoid org.elasticsearch.index.mapper.Uid.idFromUid which no longer works. Cast the doc['id'].value as needed to enable array look up. This is based on a comment by the original author elsewhere.
q = {
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"ids": {
"values": [
50,
80,
44,
12
]
}
},
"script_score": {
"params": {
"ids": [
50,
80,
44,
12
]
},
"script": "return -ids.indexOf((int)doc['id'].value);"
}
}
},
"size": 20,
"from": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment