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

x33g5p2x  于2022-01-28 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(180)

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

RestHighLevelClient.index介绍

[英]Index a document using the Index API. See Index API on elastic.co
[中]使用索引API为文档编制索引。见Index API on elastic.co

代码示例

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

/**
 * Performs an index operation with a retry.
 * @param request The index request that we want to perform.
 * @param operationDescription The type of operation that we are performing.
 */
private void indexWithRetry(final IndexRequest request, final String operationDescription) {
  try {
    new RetryUtil<IndexResponse>().retryOnException(() -> {
      try {
        return elasticSearchClient.index(request);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }, null, null, RETRY_COUNT, operationDescription, "indexWithRetry");
  } catch (Exception e) {
    Monitors.error(className, "index");
    logger.error("Failed to index {} for request type: {}", request.id(), request.type(), e);
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

@Override
public String index(IndexQuery query) {
  String documentId;
  IndexRequest request = prepareIndex(query);
  try {
    documentId = client.index(request).getId();
  } catch (IOException e) {
    throw new ElasticsearchException("Error while index for request: " + request.toString(), e);
  }
  // We should call this because we are not going through a mapper.
  if (query.getObject() != null) {
    setPersistentEntityId(query.getObject(), documentId);
  }
  return documentId;
}

代码示例来源:origin: tomoya92/pybbs

public void createDocument(String type, String id, Map<String, Object> source) {
 try {
  if (this.instance() == null) return;
  IndexRequest request = new IndexRequest(name, type, id);
  request.source(source);
  client.index(request, RequestOptions.DEFAULT);
 } catch (IOException e) {
  log.error(e.getMessage());
 }
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public void indexSingle(String index, String id, String json) throws IOException {
  IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id);
  request.source(json, XContentType.JSON);
  client.index(request, RequestOptions.DEFAULT);
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public void indexSingle(String index, String id, String json) throws IOException {
  IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id);
  request.source(json, XContentType.JSON);
  client.index(request, RequestOptions.DEFAULT);
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public void indexSingle(String index, String id, String json) throws IOException {
  IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id);
  request.source(json, XContentType.JSON);
  client.index(request);
}

代码示例来源:origin: fr.pilato.elasticsearch.crawler/fscrawler-elasticsearch-client-v5

@Override
public void indexSingle(String index, String type, String id, String json) throws IOException {
  IndexRequest request = new IndexRequest(index, type, id);
  request.source(json, XContentType.JSON);
  client.index(request);
}

代码示例来源:origin: com.wuyushuo/vplus-data

@Override
public IndexResponse createIndex(String index, String type, String id, Object source) throws Exception{
  IndexRequest request = new IndexRequest(index, type, id).source(JSON.toJSONString(source), XContentType.JSON);
  log.debug(request.toString());
  return client().index(request);
}

代码示例来源:origin: hakdogan/ElasticSearch

/**
 *
 * @param document
 * @return
 */
public String createIndex(Document document){
  try {
    IndexRequest request = new IndexRequest(props.getIndex().getName(), props.getIndex().getType());
    request.source(gson.toJson(document), XContentType.JSON);
    IndexResponse response = client.index(request);
    return response.getId();
  } catch (Exception ex) {
    log.error("The exception was thrown in createIndex method. {} ", ex);
  }
  return null;
}

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

@Override
public IndexResponse index(IndexRequest request) {
  try {
    return client.index(request, RequestOptions.DEFAULT);
  } catch (ElasticsearchStatusException e) {
    if (RestStatus.CONFLICT.equals(e.status())) {
      throw new ConcurrentUpdateException(e);
    }
    throw new NuxeoException(e);
  } catch (IOException e) {
    throw new NuxeoException(e);
  }
}

代码示例来源:origin: org.apache.camel/camel-elasticsearch-rest

message.setBody(restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT).getId());
} else if (operation == ElasticsearchOperation.Update) {
  UpdateRequest updateRequest = message.getBody(UpdateRequest.class);

代码示例来源:origin: mnemonic-no/act-platform

/**
 * Index a Fact into ElasticSearch.
 *
 * @param fact Fact to index
 * @return Indexed Fact
 */
public FactDocument indexFact(FactDocument fact) {
 if (fact == null || fact.getId() == null) return null;
 IndexResponse response;
 try {
  IndexRequest request = new IndexRequest(INDEX_NAME, TYPE_NAME, fact.getId().toString())
      .setRefreshPolicy(isTestEnvironment ? WriteRequest.RefreshPolicy.IMMEDIATE : WriteRequest.RefreshPolicy.NONE)
      .source(FACT_DOCUMENT_WRITER.writeValueAsBytes(fact), XContentType.JSON);
  response = clientFactory.getHighLevelClient().index(request);
 } catch (IOException ex) {
  throw logAndExit(ex, String.format("Could not perform request to index Fact with id = %s.", fact.getId()));
 }
 if (response.status() != RestStatus.OK && response.status() != RestStatus.CREATED) {
  LOGGER.warning("Could not index Fact with id = %s.", fact.getId());
 } else if (response.getResult() == DocWriteResponse.Result.CREATED) {
  LOGGER.info("Successfully indexed Fact with id = %s.", fact.getId());
 } else if (response.getResult() == DocWriteResponse.Result.UPDATED) {
  LOGGER.info("Successfully re-indexed existing Fact with id = %s.", fact.getId());
 }
 return fact;
}

相关文章

微信公众号

最新文章

更多