def get_limit_parameter(request):
    """
    Return the ``limit`` parameter of the request's GET parameters. This
    number is used to limit queries to the database or Elasticsearch. It
    needs to be a positive integer below the maximum valid limit. If the
    limit is not indicated or invalid, the default limit is returned.

    Args:
        ``request`` (django.http.HttpRequest): The request object with
        parameter ``limit`` set.

    Returns:
        ``int``. The limit.
    """
    DEFAULT_LIMIT = 10
    MAX_LIMIT = 500
    try:
        limit = int(request.GET.get('limit', DEFAULT_LIMIT))
    except ValueError:
        limit = DEFAULT_LIMIT
    if limit <= 0 or limit > MAX_LIMIT:
        return DEFAULT_LIMIT
    return limit