Java 类org.elasticsearch.client.action.index.IndexRequestBuilder 实例源码

项目:read-open-source-code    文件:ElasticSearchBulk.java   
/**
 * @param requestBuilder
 * @param rowMeta
 * @param row
 * @throws IOException
 */
private void addSourceFromRowFields(IndexRequestBuilder requestBuilder, RowMetaInterface rowMeta, Object[] row) throws IOException {
  XContentBuilder jsonBuilder = XContentFactory.jsonBuilder().startObject();

  for (int i = 0; i < rowMeta.size(); i++) {
    if(idFieldIndex != null && i == idFieldIndex){//skip id
      continue;
    }

    ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
    String name = hasFields ? columnsToJson.get(valueMeta.getName()) : valueMeta.getName();
    Object value = row[i];
    if(value instanceof Date && value.getClass() != Date.class){
      Date subDate = (Date) value;
      //create a genuine Date object, or jsonBuilder will not recognize it
      value = new Date(subDate.getTime());
    }
    if (StringUtils.isNotBlank(name)) {
      jsonBuilder.field(name, value);
    }
  }

  jsonBuilder.endObject();
  requestBuilder.setSource(jsonBuilder);
}
项目:kettle-4.4.0-stable    文件:ElasticSearchBulk.java   
/**
 * @param requestBuilder
 * @param rowMeta
 * @param row
 * @throws IOException
 */
private void addSourceFromRowFields(IndexRequestBuilder requestBuilder, RowMetaInterface rowMeta, Object[] row) throws IOException {
  XContentBuilder jsonBuilder = XContentFactory.jsonBuilder().startObject();

  for (int i = 0; i < rowMeta.size(); i++) {
    if(idFieldIndex != null && i == idFieldIndex){//skip id
      continue;
    }

    ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
    String name = hasFields ? columnsToJson.get(valueMeta.getName()) : valueMeta.getName();
    Object value = row[i];
    if(value instanceof Date && value.getClass() != Date.class){
      Date subDate = (Date) value;
      //create a genuine Date object, or jsonBuilder will not recognize it
      value = new Date(subDate.getTime());
    }
    if (StringUtils.isNotBlank(name)) {
      jsonBuilder.field(name, value);
    }
  }

  jsonBuilder.endObject();
  requestBuilder.setSource(jsonBuilder);
}
项目:kettle-trunk    文件:ElasticSearchBulk.java   
/**
 * @param requestBuilder
 * @param rowMeta
 * @param row
 * @throws IOException
 */
private void addSourceFromRowFields(IndexRequestBuilder requestBuilder, RowMetaInterface rowMeta, Object[] row) throws IOException {
  XContentBuilder jsonBuilder = XContentFactory.jsonBuilder().startObject();

  for (int i = 0; i < rowMeta.size(); i++) {
    if(idFieldIndex != null && i == idFieldIndex){//skip id
      continue;
    }

    ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
    String name = hasFields ? columnsToJson.get(valueMeta.getName()) : valueMeta.getName();
    Object value = row[i];
    if(value instanceof Date && value.getClass() != Date.class){
      Date subDate = (Date) value;
      //create a genuine Date object, or jsonBuilder will not recognize it
      value = new Date(subDate.getTime());
    }
    if (StringUtils.isNotBlank(name)) {
      jsonBuilder.field(name, value);
    }
  }

  jsonBuilder.endObject();
  requestBuilder.setSource(jsonBuilder);
}
项目:read-open-source-code    文件:ElasticSearchBulk.java   
/**
 * @param row
 * @param requestBuilder
 */
private void addSourceFromJsonString(Object[] row, IndexRequestBuilder requestBuilder) throws KettleStepException {
  Object jsonString = row[jsonFieldIdx];
  if (jsonString instanceof byte[]) {
    requestBuilder.setSource((byte[]) jsonString);
  } else if (jsonString instanceof String) {
    requestBuilder.setSource(((String) jsonString).getBytes());
  }
  else{
    throw new KettleStepException(BaseMessages.getString("ElasticSearchBulk.Error.NoJsonFieldFormat"));
  }
}
项目:kettle-4.4.0-stable    文件:ElasticSearchBulk.java   
/**
 * @param row
 * @param requestBuilder
 */
private void addSourceFromJsonString(Object[] row, IndexRequestBuilder requestBuilder) throws KettleStepException {
  Object jsonString = row[jsonFieldIdx];
  if (jsonString instanceof byte[]) {
    requestBuilder.setSource((byte[]) jsonString);
  } else if (jsonString instanceof String) {
    requestBuilder.setSource(((String) jsonString).getBytes());
  }
  else{
    throw new KettleStepException(BaseMessages.getString("ElasticSearchBulk.Error.NoJsonFieldFormat"));
  }
}
项目:kettle-trunk    文件:ElasticSearchBulk.java   
/**
 * @param row
 * @param requestBuilder
 */
private void addSourceFromJsonString(Object[] row, IndexRequestBuilder requestBuilder) throws KettleStepException {
  Object jsonString = row[jsonFieldIdx];
  if (jsonString instanceof byte[]) {
    requestBuilder.setSource((byte[]) jsonString);
  } else if (jsonString instanceof String) {
    requestBuilder.setSource(((String) jsonString).getBytes());
  }
  else{
    throw new KettleStepException(BaseMessages.getString("ElasticSearchBulk.Error.NoJsonFieldFormat"));
  }
}