org.elasticsearch.common.xcontent.XContentBuilder.flush()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(85)

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

XContentBuilder.flush介绍

暂无

代码示例

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

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

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

private static GeoPoint parseGeoPointString(String value) {
  try {
    XContentBuilder content = JsonXContent.contentBuilder();
    content.value(value);
    content.flush();
    content.close();
    try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
        THROW_UNSUPPORTED_OPERATION, ((ByteArrayOutputStream) content.getOutputStream()).toByteArray())) {
      parser.nextToken();
      return GeoUtils.parseGeoPoint(parser);
    }
  } catch (IOException e) {
    throw new IllegalArgumentException("Invalid value for geopoint: " + e.getMessage());
  }
}

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

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

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

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

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

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

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

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
  boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
  if (!includeDefaults) {
    // simulate the generation to make sure we don't add unnecessary content if all is default
    // if all are defaults, no need to write it at all - generating is twice is ok though
    BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0);
    XContentBuilder b =  new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput);
    b.startObject().flush();
    long pos = bytesStreamOutput.position();
    innerToXContent(b, false);
    b.flush();
    if (pos == bytesStreamOutput.position()) {
      return builder;
    }
  }
  builder.startObject(CONTENT_TYPE);
  innerToXContent(builder, includeDefaults);
  builder.endObject();
  return builder;
}

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

static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbField,
                  QueryBuilder queryBuilder, ParseContext context) throws IOException {
  if (indexVersion.onOrAfter(Version.V_6_0_0_beta2)) {
    try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
      try (OutputStreamStreamOutput out  = new OutputStreamStreamOutput(stream)) {
        out.setVersion(indexVersion);
        out.writeNamedWriteable(queryBuilder);
        byte[] queryBuilderAsBytes = stream.toByteArray();
        qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
      }
    }
  } else {
    try (XContentBuilder builder = XContentFactory.contentBuilder(QUERY_BUILDER_CONTENT_TYPE)) {
      queryBuilder.toXContent(builder, new MapParams(Collections.emptyMap()));
      builder.flush();
      byte[] queryBuilderAsBytes = BytesReference.toBytes(BytesReference.bytes(builder));
      context.doc().add(new Field(qbField.name(), queryBuilderAsBytes, qbField.fieldType()));
    }
  }
}

代码示例来源:origin: org.elasticsearch.plugin/percolator-client

static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbField,
                  QueryBuilder queryBuilder, ParseContext context) throws IOException {
  if (indexVersion.onOrAfter(Version.V_6_0_0_beta2)) {
    try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
      try (OutputStreamStreamOutput out  = new OutputStreamStreamOutput(stream)) {
        out.setVersion(indexVersion);
        out.writeNamedWriteable(queryBuilder);
        byte[] queryBuilderAsBytes = stream.toByteArray();
        qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
      }
    }
  } else {
    try (XContentBuilder builder = XContentFactory.contentBuilder(QUERY_BUILDER_CONTENT_TYPE)) {
      queryBuilder.toXContent(builder, new MapParams(Collections.emptyMap()));
      builder.flush();
      byte[] queryBuilderAsBytes = BytesReference.toBytes(BytesReference.bytes(builder));
      context.doc().add(new Field(qbField.name(), queryBuilderAsBytes, qbField.fieldType()));
    }
  }
}

代码示例来源:origin: crate/elasticsearch-inout-plugin

XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(XContentType.JSON), os);
exportFields.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.flush();
BytesReference bytes = os.bytes();
out.write(bytes.array(), bytes.arrayOffset(), bytes.length());

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

try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
      builder.copyCurrentStructure(parser);
      builder.flush();
      documents.add(BytesReference.bytes(builder));
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
  builder.copyCurrentStructure(parser);
  builder.flush();
  documents.add(BytesReference.bytes(builder));

代码示例来源:origin: org.elasticsearch.plugin/percolator-client

try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
      builder.copyCurrentStructure(parser);
      builder.flush();
      documents.add(BytesReference.bytes(builder));
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
  builder.copyCurrentStructure(parser);
  builder.flush();
  documents.add(BytesReference.bytes(builder));

相关文章

微信公众号

最新文章

更多