scrapi.settings.ELASTIC_INST_INDEX

Here are the examples of the python api scrapi.settings.ELASTIC_INST_INDEX taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: scrapi Source File: views.py
Function: institutions
@api_view(['GET', 'POST'])
def institutions(request):
    if not es:
        return HttpResponse('No connection to elastic search', status=503)
    if request.data.get('query') or request.query_params.get('q'):
        query = request.data.get('query') or {
            'query': {
                'query_string': {
                    'query': request.query_params.get('q')
                }
            }
        }
    else:
        query = {
            'query': {
                'match_all': {}
            }
        }

    es.indices.create(index='institutions', ignore=400)
    res = es.search(index=settings.ELASTIC_INST_INDEX, body=query)
    # validate query and grab whats wanted
    try:
        res = {
            'results': [val['_source'] for val in res['hits']['hits']],
            'aggregations': res.get('aggregations') or res.get('aggs'),
            'count': res['hits']['total']
        }
    except IndexError:
        return Response('Invalid query', status=400)
    return Response(res, status=200)