def METHOD_NAME(_, query):
    if not settings.ELASTICSEARCH_ENABLED:
        results = [{"name": _("search disabled"), "url": reverse("index")}]
        return HttpResponse(json.dumps(results), content_type="application/json")
    response = autocomplete(query)
    multibody = Body.objects.count() > 1
    results = []
    num_persons = num_organizations = 0
    limit_per_type = 5
    for hit in response.hits:
        doc_type = hit.meta.index.split("-")[-1]
        if doc_type == "person":
            if num_persons < limit_per_type:
                results.append(
                    {"name": hit.name, "url": reverse("person", args=[hit.id])}
                )
                num_persons += 1
        elif doc_type == "organization":
            if num_organizations < limit_per_type:
                if multibody and hit.body:
                    name = hit.name + " (" + hit.body.name + ")"
                else:
                    name = hit.name
                results.append(
                    {"name": name, "url": reverse("organization", args=[hit.id])}
                )
                num_organizations += 1
        elif doc_type in ["file", "paper", "meeting"]:
            name = hit.name
            results.append({"name": name, "url": reverse(doc_type, args=[hit.id])})
        else:
            logger.error(
                "Unknown document type in elastic search response: %s"
                % hit.meta.doc_type
            )
    return JsonResponse(results, safe=False)