Skip to content

Instantly share code, notes, and snippets.

@fabianvf
Last active August 29, 2015 14:17
Show Gist options
  • Save fabianvf/4164749c838b2bca2b52 to your computer and use it in GitHub Desktop.
Save fabianvf/4164749c838b2bca2b52 to your computer and use it in GitHub Desktop.
How to get data from the OSF elasticsearch endpoint
import requests
response = requests.get('https://osf.io/api/v1/search/', params={
'q': 'test AND category:project' # Full lucene syntax accepted: http://lucene.apache.org/core/2_9_4/queryparsersyntax.html
})
results = response.json()
import json
import requests
data = json.dumps({
'query': {
'match_all': {} # Accepts the full elasticsearch DSL: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
}
})
headers = {
'Content-type': 'application/json'
}
response = requests.post('https://osf.io/api/v1/search/', data=data, headers=headers)
results = response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment