org.elasticsearch.client.Client.get()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(307)

本文整理了Java中org.elasticsearch.client.Client.get()方法的一些代码示例,展示了Client.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.get()方法的具体详情如下:
包路径:org.elasticsearch.client.Client
类名称:Client
方法名:get

Client.get介绍

[英]Gets the document that was indexed from an index with a type and id.
[中]获取从具有类型和id的索引编制索引的文档。

代码示例

代码示例来源:origin: Netflix/conductor

@Override
public String get(String workflowInstanceId, String fieldToGet) {
  GetRequest request = new GetRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId)
    .fetchSourceContext(
      new FetchSourceContext(true, new String[]{fieldToGet}, Strings.EMPTY_ARRAY));
  GetResponse response = elasticSearchClient.get(request).actionGet();
  if (response.isExists()) {
    Map<String, Object> sourceAsMap = response.getSourceAsMap();
    if (sourceAsMap.containsKey(fieldToGet)) {
      return sourceAsMap.get(fieldToGet).toString();
    }
  }
  logger.debug("Unable to find Workflow: {} in ElasticSearch index: {}.", workflowInstanceId,
    indexName);
  return null;
}

代码示例来源:origin: floragunncom/search-guard

try (Writer writer = new FileWriter(filepath)) {
  final GetResponse response = tc.get(new GetRequest(index).type(type).id(id).refresh(true).realtime(false)).actionGet();

代码示例来源:origin: apache/flink

/**
 * Verify the results in an Elasticsearch index. The results must first be produced into the index
 * using a {@link TestElasticsearchSinkFunction};
 *
 * @param client The client to use to connect to Elasticsearch
 * @param index The index to check
 */
public static void verifyProducedSinkData(Client client, String index) {
  for (int i = 0; i < NUM_ELEMENTS; i++) {
    GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet();
    Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME));
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

client.get(getRequest, new ActionListener<GetResponse>(){

代码示例来源:origin: komoot/photon

@Override
public void updateOrCreate(PhotonDoc updatedDoc) {
  final boolean exists = this.esClient.get(this.esClient.prepareGet("photon", "place", String.valueOf(updatedDoc.getPlaceId())).request()).actionGet().isExists();
  if (exists) {
    this.update(updatedDoc);
  } else {
    this.create(updatedDoc);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void fetch(TermsLookup termsLookup, Client client, ActionListener<List<Object>> actionListener) {
  GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id())
    .preference("_local").routing(termsLookup.routing());
  client.get(getRequest, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      List<Object> terms = new ArrayList<>();
      if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists
        List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
        terms.addAll(extractedValues);
      }
      actionListener.onResponse(terms);
    }
    @Override
    public void onFailure(Exception e) {
      actionListener.onFailure(e);
    }
  });
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
 * task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
 * coordinating node if the node is no longer part of the cluster.
 */
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
  GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE,
      request.getTaskId().toString());
  get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
  client.get(get, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      try {
        onGetFinishedTaskFromIndex(getResponse, listener);
      } catch (Exception e) {
        listener.onFailure(e);
      }
    }
    @Override
    public void onFailure(Exception e) {
      if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
        // We haven't yet created the index for the task results so it can't be found.
        listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e,
          request.getTaskId()));
      } else {
        listener.onFailure(e);
      }
    }
  });
}

代码示例来源:origin: javanna/elasticshell

@Override
  protected ActionFuture<GetResponse> doExecute(GetRequest request) {
    return client.get(request);
  }
}

代码示例来源:origin: stackoverflow.com

Client client = new Client(Protocol.HTTP);  
client.get("http://127.0.0.1").getEntity().write(System.out);

代码示例来源:origin: stackoverflow.com

Client client = new Client(Protocol.HTTP);
Response response = client.get(url);
if (response.getStatus().isError()) {
  // uh oh!
}

代码示例来源:origin: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core

@Override
public GetResponse get(GetRequest request) {
  return client.get(request).actionGet();
}

代码示例来源:origin: harbby/presto-connectors

String getScriptFromIndex(String scriptLang, String id, HasContextAndHeaders context) {
  if (client == null) {
    throw new IllegalArgumentException("Got an indexed script with no Client registered.");
  }
  scriptLang = validateScriptLanguage(scriptLang);
  GetRequest getRequest = new GetRequest(SCRIPT_INDEX, scriptLang, id);
  getRequest.copyContextAndHeadersFrom(context);
  GetResponse responseFields = client.get(getRequest).actionGet();
  if (responseFields.isExists()) {
    return getScriptFromResponse(responseFields);
  }
  throw new IllegalArgumentException("Unable to find script [" + SCRIPT_INDEX + "/"
      + scriptLang + "/" + id + "]");
}

代码示例来源:origin: com.floragunn/search-guard-6

try (Writer writer = new FileWriter(filepath)) {
  final GetResponse response = tc.get(new GetRequest(index).type(type).id(id).refresh(true).realtime(false)).actionGet();

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

private List<Object> fetch(TermsLookup termsLookup, Client client) {
  List<Object> terms = new ArrayList<>();
  GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id())
      .preference("_local").routing(termsLookup.routing());
  final GetResponse getResponse = client.get(getRequest).actionGet();
  if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists
    List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
    terms.addAll(extractedValues);
  }
  return terms;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private void fetch(TermsLookup termsLookup, Client client, ActionListener<List<Object>> actionListener) {
  GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id())
    .preference("_local").routing(termsLookup.routing());
  client.get(getRequest, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      List<Object> terms = new ArrayList<>();
      if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists
        List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
        terms.addAll(extractedValues);
      }
      actionListener.onResponse(terms);
    }
    @Override
    public void onFailure(Exception e) {
      actionListener.onFailure(e);
    }
  });
}

代码示例来源:origin: apache/servicemix-bundles

private void fetch(TermsLookup termsLookup, Client client, ActionListener<List<Object>> actionListener) {
  GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id())
    .preference("_local").routing(termsLookup.routing());
  client.get(getRequest, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      List<Object> terms = new ArrayList<>();
      if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists
        List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap());
        terms.addAll(extractedValues);
      }
      actionListener.onResponse(terms);
    }
    @Override
    public void onFailure(Exception e) {
      actionListener.onFailure(e);
    }
  });
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
 * task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
 * coordinating node if the node is no longer part of the cluster.
 */
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
  GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE,
      request.getTaskId().toString());
  get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
  client.get(get, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      try {
        onGetFinishedTaskFromIndex(getResponse, listener);
      } catch (Exception e) {
        listener.onFailure(e);
      }
    }
    @Override
    public void onFailure(Exception e) {
      if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
        // We haven't yet created the index for the task results so it can't be found.
        listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e,
          request.getTaskId()));
      } else {
        listener.onFailure(e);
      }
    }
  });
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
 * task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
 * coordinating node if the node is no longer part of the cluster.
 */
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
  GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE,
      request.getTaskId().toString());
  get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
  client.get(get, new ActionListener<GetResponse>() {
    @Override
    public void onResponse(GetResponse getResponse) {
      try {
        onGetFinishedTaskFromIndex(getResponse, listener);
      } catch (Exception e) {
        listener.onFailure(e);
      }
    }
    @Override
    public void onFailure(Exception e) {
      if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
        // We haven't yet created the index for the task results so it can't be found.
        listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e,
          request.getTaskId()));
      } else {
        listener.onFailure(e);
      }
    }
  });
}

代码示例来源:origin: harbby/presto-connectors

public void queryScriptIndex(GetIndexedScriptRequest request, final ActionListener<GetResponse> listener) {
  String scriptLang = validateScriptLanguage(request.scriptLang());
  GetRequest getRequest = new GetRequest(request, SCRIPT_INDEX).type(scriptLang).id(request.id())
      .version(request.version()).versionType(request.versionType())
      .preference("_local"); //Set preference for no forking
  client.get(getRequest, listener);
}

代码示例来源:origin: harbby/presto-connectors

@Override
  public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));
    // don't get any fields back...
    getRequest.fields(Strings.EMPTY_ARRAY);
    // TODO we can also just return the document size as Content-Length

    client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
      @Override
      public RestResponse buildResponse(GetResponse response) {
        if (!response.isExists()) {
          return new BytesRestResponse(NOT_FOUND);
        } else {
          return new BytesRestResponse(OK);
        }
      }
    });
  }
}

相关文章