-
-
Save wubin1989/14d9387f63ecf9e27c8f2396ea49e74c to your computer and use it in GitHub Desktop.
get some random documents from elasticsearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from elasticsearch import Elasticsearch | |
es = Elasticsearch(["node001.bol.com", "node002.bol.com"], | |
sniff_on_start=True, | |
# refresh nodes after a node fails to respond | |
sniff_on_connection_fail=True, | |
# and also every xxx seconds | |
sniffer_timeout=300 | |
) | |
# retrieve 2 random documents from index | |
res = es.search(index='barrie_cat_reco', doc_type='recommendation', size=2, body={"query": {"match_all": {}}, "sort": { | |
"_script" : { | |
"script" : "Math.random()", | |
"lang" : "groovy", | |
"type" : "number", | |
"params" : {} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment