health status index                         uuid                   pri rep docs.count docs.deleted store.size pri.store.size
获取elasticsearch索引监控数据
@return
@throws ElasticSearchException
164566
public List<ESIndice> getIndexes() throws ElasticSearchException{
		 String data = this.client.executeHttp("_cat/indices?v",HTTP_GET);
         logger.debug(data);

         if(SimpleStringUtil.isNotEmpty(data)){
			try {
				List<ESIndice> indices = extractIndice(data);
				 return indices;
			} catch (IOException e) {
				throw new ElasticSearchException(e);
			}
        	
         }
         return null;
	 }
449121
function getIndexSizes(done, results) {
  var client = results.client;
  var ns = mongodbNS(results.namespace);
  client
    .db(ns.database)
    .collection(ns.collection)
    .stats(function(err, res) {
      if (err) {
        if (isNotAuthorizedError(err)) {
          debug(
            'Not authorized to get collection stats.  Returning default for indexSizes {}.'
          );
          return done(null, {});
        }
        return done(err);
      }

      res = _.mapValues(res.indexSizes, function(size) {
        return { size: size };
      });
      done(null, res);
    });
}
127952
public String getDocument(String indexName, String indexType,String documentId) throws ElasticSearchException{
		return getDocument(indexName, indexType,documentId,(Map<String,Object>)null);
	}
445921
protected long doCount(String spaceId) throws IOException {
        TopDocs result = getIndexSearcher().search(buildQuery(spaceId, null), 1);
        return result != null ? result.totalHits : -1;
    }
418867
public boolean createSingleIndex(String indexName) throws
            ElasticsearchException {
        CreateIndexRequest indexRequest = new CreateIndexRequest(indexName);
        CreateIndexResponse res = this.client.admin().indices().create(indexRequest).actionGet();
        return indexExists(indexName);
    }
348319
@Override
    public Status updateIndexes(List<ViewStore> inputViews) throws CouchbaseLiteException {
        synchronized (lockUpdateIndexes) {
            assert (inputViews != null);

            // workaround
            if (!inputViews.contains(this))
                inputViews.add(this);

            final ArrayList<View> views = new ArrayList<View>(inputViews.size());
            final ArrayList<Mapper> mapBlocks = new ArrayList<Mapper>(inputViews.size());
            final ArrayList<String> docTypes = new ArrayList<String>(inputViews.size());
            boolean useDocType = false;
            for (ViewStore v : inputViews) {
                ForestDBViewStore view = (ForestDBViewStore) v;
                ViewStoreDelegate delegate = view.getDelegate();
                Mapper map = delegate != null ? delegate.getMap() : null;
                if (map == null) {
                    Log.v(Log.TAG_VIEW, "    %s has no map block; skipping it", view.getName());
                    continue;
                }
                try {
                    view.openIndex();
                } catch (ForestException e) {
                    throw new CouchbaseLiteException(ForestBridge.err2status(e));
                }
                views.add(view._view);
                mapBlocks.add(map);
                String docType = delegate.getDocumentType();
                docTypes.add(docType);
                if (docType != null && !useDocType)
                    useDocType = true;
            }

            if (views.size() == 0) {
                Log.v(TAG, "    No input views to update the index");
                return new Status(Status.NOT_MODIFIED);
            }

            boolean success = false;
            Indexer indexer = null;
            try {
                indexer = new Indexer(views.toArray(new View[views.size()]));
                indexer.triggerOnView(this._view);
                DocumentIterator itr;
                try {
                    itr = indexer.iterateDocuments();
                    if (itr == null)
                        return new Status(Status.NOT_MODIFIED);
                } catch (ForestException e) {
                    if (e.code == FDBErrors.FDB_RESULT_SUCCESS)
                        return new Status(Status.NOT_MODIFIED);
                    else
                        throw new CouchbaseLiteException(ForestBridge.err2status(e));
                }
                // Now enumerate the docs:
                Document doc;
                while ((doc = itr.nextDocument()) != null) {
                    // For each updated document:
                    try {
                        String docType = useDocType ? doc.getType() : null;
                        // Skip design docs
                        boolean validDocToIndex =
                                !doc.deleted() && !doc.getDocID().startsWith("_design/");
                        // Read the document body:
                        Map<String, Object> body = ForestBridge.bodyOfSelectedRevision(doc);
                        body.put("_id", doc.getDocID());
                        body.put("_rev", doc.getRevID());
                        body.put("_local_seq", doc.getSequence());
                        if (doc.conflicted()) {
                            List<String> currentRevIDs = ForestBridge.getCurrentRevisionIDs(doc);
                            if (currentRevIDs != null && currentRevIDs.size() > 1)
                                body.put("_conflicts",
                                        currentRevIDs.subList(1, currentRevIDs.size()));
                        }
                        // Feed it to each view's map function:
                        for (int viewNumber = 0; viewNumber < views.size(); viewNumber++) {
                            if (!indexer.shouldIndex(doc, viewNumber))
                                continue;

                            boolean indexIt = validDocToIndex;
                            if (indexIt && useDocType) {
                                String viewDocType = docTypes.get(viewNumber);
                                if (viewDocType != null)
                                    indexIt = viewDocType.equals(docType);
                            }

                            if (indexIt)
                                emit(indexer, viewNumber, doc, body, mapBlocks.get(viewNumber));
                            else
                                emit(indexer, viewNumber, doc, body, null);
                        }
                    } finally {
                        doc.free();
                    }
                }
                success = true;
            } catch (ForestException e) {
                throw new CouchbaseLiteException(ForestBridge.err2status(e));
            } finally {
                if (indexer != null) {
                    try {
                        indexer.endIndex(success);
                    } catch (ForestException ex) {
                        Log.e(TAG, "Failed to call Indexer.endIndex(boolean)", ex);
                        if (success)
                            throw new CouchbaseLiteException(ForestBridge.err2status(ex));
                    }
                }
            }
            Log.v(TAG, "... Finished re-indexing (%s)", viewNames(inputViews));
            return new Status(Status.OK);
        }
    }
218443
public <T> T getDocument(String indexName, String indexType,String documentId,Map<String,Object> options,Class<T> beanType) throws ElasticSearchException{
		try{
			SearchHit searchResult = this.client.executeRequest(BuildTool.buildGetDocumentRequest(  indexName,   indexType,  documentId,  options),null,   new GetDocumentResponseHandler( beanType),ClientUtil.HTTP_GET);

			return ResultUtil.buildObject(searchResult, beanType);
		}
		catch(ElasticSearchException e){
			return ResultUtil.hand404HttpRuntimeException(e,beanType,ResultUtil.OPERTYPE_getDocument);
		}

	}
53883
@Operation(name = JpaConstants.OPERATION_GET_RESOURCE_COUNTS, idempotent = true, returnParameters = {
		@OperationParam(name = "AllergyIntolerance", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Appointment", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "AppointmentResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "AuditEvent", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Basic", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Binary", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "BodySite", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Bundle", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "CarePlan", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "CarePlan2", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Claim", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ClaimResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ClinicalImpression", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Communication", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "CommunicationRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Composition", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ConceptMap", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Condition", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Conformance", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Contract", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Contraindication", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Coverage", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DataElement", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Device", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DeviceComponent", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DeviceMetric", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DeviceUseRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DeviceUseStatement", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DiagnosticOrder", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DiagnosticReport", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DocumentManifest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "DocumentReference", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "EligibilityRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "EligibilityResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Encounter", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "EnrollmentRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "EnrollmentResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "EpisodeOfCare", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ExplanationOfBenefit", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "FamilyMemberHistory", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Flag", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Goal", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Group", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "HealthcareService", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ImagingObjectSelection", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ImagingStudy", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Immunization", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ImmunizationRecommendation", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ListResource", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Location", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Media", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Medication", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "MedicationAdministration", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "MedicationDispense", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "MedicationPrescription", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "MedicationStatement", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "MessageHeader", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "NamingSystem", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "NutritionOrder", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Observation", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "OperationDefinition", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "OperationOutcome", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Order", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "OrderResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Organization", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Parameters", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Patient", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "PaymentNotice", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "PaymentReconciliation", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Person", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Practitioner", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Procedure", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ProcedureRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ProcessRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ProcessResponse", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Provenance", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Questionnaire", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "QuestionnaireAnswers", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ReferralRequest", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "RelatedPerson", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "RiskAssessment", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Schedule", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "SearchParameter", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Slot", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Specimen", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "StructureDefinition", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Subscription", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Substance", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "Supply", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "ValueSet", type = IntegerDt.class, min = 0, max = 1),
		@OperationParam(name = "VisionPrescription", type = IntegerDt.class, min = 0, max = 1)
	})
	@Description(shortDefinition = "Provides the number of resources currently stored on the server, broken down by resource type")
	//@formatter:on
	public Parameters getResourceCounts() {
		Parameters retVal = new Parameters();

		Map<String, Long> counts = mySystemDao.getResourceCountsFromCache();
		counts = defaultIfNull(counts, Collections.emptyMap());
		counts = new TreeMap<>(counts);
		for (Entry<String, Long> nextEntry : counts.entrySet()) {
			retVal.addParameter().setName(new StringDt(nextEntry.getKey())).setValue(new IntegerDt(nextEntry.getValue().intValue()));
		}

		return retVal;
	}
1177250
public synchronized int getPartitionStoreCount() {
        int count = 0;
        for (String store : storeToPartitionIds.keySet()) {
            count += storeToPartitionIds.get(store).size();
        }
        return count;
    }
1254129
synchronized int removeAllDocuments(String uuid) throws IOException
   {
      synchronized (updateMonitor)
      {
         //updateInProgress = true;
         indexUpdateMonitor.setUpdateInProgress(true, false);
      }
      int num;
      try
      {
         Term idTerm = new Term(FieldNames.UUID, uuid.toString());
         executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
         num = volatileIndex.removeDocument(idTerm);
         if (num > 0)
         {
            redoLog.append(new DeleteNode(getTransactionId(), uuid));
         }
         for (int i = 0; i < indexes.size(); i++)
         {
            PersistentIndex index = indexes.get(i);
            // only remove documents from registered indexes
            if (indexNames.contains(index.getName()))
            {
               int removed = index.removeDocument(idTerm);
               if (removed > 0)
               {
                  redoLog.append(new DeleteNode(getTransactionId(), uuid));
               }
               num += removed;
            }
         }
         executeAndLog(new Commit(getTransactionId()));
      }
      finally
      {
         synchronized (updateMonitor)
         {
            //updateInProgress = false;
            indexUpdateMonitor.setUpdateInProgress(false, false);
            updateMonitor.notifyAll();
            releaseMultiReader();
         }
      }
      return num;
   }
386817
Entry get(String uuid)
   {
      LRUMap cacheSegment = docNumbers[getSegmentIndex(uuid.charAt(0))];
      // uuid may be invalid
      //        if (uuid.length() != UUID.UUID_FORMATTED_LENGTH) {
      //            return null;
      //        }
      String key = uuid;
      Entry entry;
      synchronized (cacheSegment)
      {
         entry = (Entry)cacheSegment.get(key);
      }
      if (log.isDebugEnabled())
      {
         accesses++;
         if (entry == null)
         {
            misses++;
         }
         // log at most after 1000 accesses and every 10 seconds
         if (accesses > 1000 && System.currentTimeMillis() - lastLog > LOG_INTERVAL)
         {
            long ratio = 100;
            if (misses != 0)
            {
               ratio -= misses * 100L / accesses;
            }
            StringBuilder statistics = new StringBuilder();
            int inUse = 0;
            for (int i = 0; i < docNumbers.length; i++)
            {
               inUse += docNumbers[i].size();
            }
            statistics.append("size=").append(inUse);
            statistics.append("/").append(docNumbers[0].maxSize() * CACHE_SEGMENTS);
            statistics.append(", #accesses=").append(accesses);
            statistics.append(", #hits=").append((accesses - misses));
            statistics.append(", #misses=").append(misses);
            statistics.append(", cacheRatio=").append(ratio).append("%");
            log.debug(statistics.toString());
            accesses = 0;
            misses = 0;
            lastLog = System.currentTimeMillis();
         }
      }
      return entry;
   }
1003698
public static boolean isIndexExist(RestClient client, String index) throws Exception {
		Response response = client.performRequest(new Request("HEAD", "/" + index));
		return response.getStatusLine().getStatusCode() == 200;
	}
915080
public <T> ESDatas<T> searchAllParallel(String index,  Class<T> type,int thread) throws ElasticSearchException{
			return searchAllParallel(index,  ClientInterface.DEFAULT_FETCHSIZE,type,thread);
	}
694054
private static boolean isMappingExist(RestHighLevelClient client, String index) throws Exception {
        GetMappingsResponse mapping = client.indices().getMapping(new GetMappingsRequest().indices(index), RequestOptions.DEFAULT);
        // Let's get the default mapping
        if (mapping.mappings().isEmpty()) {
            return false;
        }
        MappingMetaData doc = mapping.mappings().values().iterator().next();
        return !doc.getSourceAsMap().isEmpty();
    }
453282
public   MapSearchHit getDocumentHit(String indexName, String indexType,String documentId) throws ElasticSearchException{
		return getDocumentHit(indexName, indexType,documentId,(Map<String,Object> )null);
	}
1274709
public <T> T getDocument(String indexName, String indexType,String documentId,Class<T> beanType) throws ElasticSearchException{
		return getDocument(  indexName,   indexType,  documentId,(Map<String,Object>)null,beanType);
	}
1373191
boolean deleteIndexEntry(S userStorable) throws PersistException {
        try {
            return makeIndexEntry(userStorable).tryDelete();
        } catch (PersistException e) {
            Throwable cause = e.getCause();
            if (cause instanceof IllegalArgumentException) {
                // Can be caused by a corrupt master record, which is
                // attempting do assign an illegal value to the index. There's
                // no way to find the old index entry to delete.
                return false;
            }
            throw e;
        }
    }