def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" query = {"filter": {"ids": {"values": [doc_id]}}} found_indices = {} es_doc_type = None for index in ES_META: res = run_query(index, query) if 'hits' in res and res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] found_indices[index] = to_json(es_doc) es_doc_type = es_doc_type or es_doc.get('doc_type') context = { "doc_id": doc_id, "es_info": { "status": "found" if found_indices else "NOT FOUND IN ELASTICSEARCH!", "doc_type": es_doc_type, "found_indices": found_indices, }, "couch_info": _lookup_id_in_database(doc_id), } return render(request, "hqadmin/doc_in_es.html", context)
def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" query = {"filter": {"ids": {"values": [doc_id]}}} found_indices = {} es_doc_type = None for index in ES_META: res = run_query(index, query) if 'hits' in res and res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] found_indices[index] = to_json(es_doc) es_doc_type = es_doc_type or es_doc.get('doc_type') context = { "doc_id": doc_id, "es_info": { "status": "found" if found_indices else "NOT FOUND IN ELASTICSEARCH!", "doc_type": es_doc_type, "found_indices": found_indices, }, "couch_info": _lookup_id_in_couch(doc_id), } return render(request, "hqadmin/doc_in_es.html", context)
def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) try: couch_doc = get_db().get(doc_id) except ResourceNotFound: couch_doc = {} query = {"filter": {"ids": { "values": [doc_id]}}} es_doc = {} index_found = '' for index, url in ES_URLS.items(): res = run_query(url, query) if res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] index_found = index break doc_type = couch_doc.get('doc_type') or es_doc.get('doc_type', "Unknown") def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" context = { "doc_id": doc_id, "status": "found" if es_doc else "NOT FOUND!", "doc_type": doc_type, "couch_doc": to_json(couch_doc), "es_doc": to_json(es_doc), "index": index_found } return render(request, "hqadmin/doc_in_es.html", context)
def run(self, include_hits=False): """Actually run the query. Returns an ESQuerySet object.""" query = self._clean_before_run(include_hits) raw = run_query(query.index, query.raw_query, debug_host=query.debug_host) return ESQuerySet(raw, deepcopy(query))
def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) try: couch_doc = get_db().get(doc_id) except ResourceNotFound: couch_doc = {} query = {"filter": {"ids": { "values": [doc_id]}}} def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" found_indices = {} doc_type = couch_doc.get('doc_type') es_doc_type = None for index, url in ES_URLS.items(): res = run_query(url, query) if 'hits' in res and res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] found_indices[index] = to_json(es_doc) es_doc_type = es_doc_type or es_doc.get('doc_type') doc_type = doc_type or es_doc_type or 'Unknown' context = { "doc_id": doc_id, "status": "found" if found_indices else "NOT FOUND!", "doc_type": doc_type, "couch_doc": to_json(couch_doc), "found_indices": found_indices, } return render(request, "hqadmin/doc_in_es.html", context)
def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) try: couch_doc = get_db().get(doc_id) except ResourceNotFound: couch_doc = {} query = {"filter": {"ids": { "values": [doc_id]}}} es_doc = {} for url in ES_URLS.values(): res = run_query(url, query) if res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] break doc_type = couch_doc.get('doc_type') or es_doc.get('doc_type', "Unknown") def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" context = { "doc_id": doc_id, "status": "found" if es_doc else "NOT FOUND!", "doc_type": doc_type, "couch_doc": to_json(couch_doc), "es_doc": to_json(es_doc), } return render(request, "hqadmin/doc_in_es.html", context)
def run(self, include_hits=False): """Actually run the query. Returns an ESQuerySet object.""" query = self._clean_before_run(include_hits) raw = run_query( query.index, query.raw_query, debug_host=query.debug_host, es_instance_alias=self.es_instance_alias, ) return ESQuerySet(raw, deepcopy(query))
def doc_in_es(request): doc_id = request.GET.get("id") if not doc_id: return render(request, "hqadmin/doc_in_es.html", {}) couch_doc = {} db_urls = [settings.COUCH_DATABASE] + settings.EXTRA_COUCHDB_DATABASES.values() for url in db_urls: try: couch_doc = Database(url).get(doc_id) break except ResourceNotFound: pass query = {"filter": {"ids": { "values": [doc_id]}}} def to_json(doc): return json.dumps(doc, indent=4, sort_keys=True) if doc else "NOT FOUND!" found_indices = {} doc_type = couch_doc.get('doc_type') es_doc_type = None for index, url in ES_URLS.items(): res = run_query(url, query) if 'hits' in res and res['hits']['total'] == 1: es_doc = res['hits']['hits'][0]['_source'] found_indices[index] = to_json(es_doc) es_doc_type = es_doc_type or es_doc.get('doc_type') doc_type = doc_type or es_doc_type or 'Unknown' context = { "doc_id": doc_id, "status": "found" if found_indices else "NOT FOUND!", "doc_type": doc_type, "couch_doc": to_json(couch_doc), "found_indices": found_indices, } return render(request, "hqadmin/doc_in_es.html", context)
def run(self): """ Actually run the query. Return an ESQuerySet object. """ raw = run_query(self.url, self.raw_query) return ESQuerySet(raw, deepcopy(self))
def run(self): """Actually run the query. Returns an ESQuerySet object.""" raw = run_query(self.index, self.raw_query, debug_host=self.debug_host) return ESQuerySet(raw, deepcopy(self))