本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentFactory.xContentType方法的典型用法代码示例。如果您正苦于以下问题:Java XContentFactory.xContentType方法的具体用法?Java XContentFactory.xContentType怎么用?Java XContentFactory.xContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.xcontent.XContentFactory
的用法示例。
在下文中一共展示了XContentFactory.xContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PercolateQueryBuilder
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
* Read from a stream.
*/
PercolateQueryBuilder(StreamInput in) throws IOException {
super(in);
field = in.readString();
documentType = in.readString();
indexedDocumentIndex = in.readOptionalString();
indexedDocumentType = in.readOptionalString();
indexedDocumentId = in.readOptionalString();
indexedDocumentRouting = in.readOptionalString();
indexedDocumentPreference = in.readOptionalString();
if (in.readBoolean()) {
indexedDocumentVersion = in.readVLong();
} else {
indexedDocumentVersion = null;
}
document = in.readOptionalBytesReference();
if (document != null) {
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
documentXContentType = XContentType.readFrom(in);
} else {
documentXContentType = XContentFactory.xContentType(document);
}
} else {
documentXContentType = null;
}
}
示例2: Item
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
/**
* Read from a stream.
*/
Item(StreamInput in) throws IOException {
index = in.readOptionalString();
type = in.readOptionalString();
if (in.readBoolean()) {
doc = (BytesReference) in.readGenericValue();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(doc);
}
} else {
id = in.readString();
}
fields = in.readOptionalStringArray();
perFieldAnalyzer = (Map<String, String>) in.readGenericValue();
routing = in.readOptionalString();
version = in.readLong();
versionType = VersionType.readFromStream(in);
}
示例3: readFrom
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
lang = in.readString();
if (lang.isEmpty()) {
lang = null;
}
id = in.readOptionalString();
content = in.readBytesReference();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(content);
}
}
示例4: readFrom
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
type = in.readOptionalString();
id = in.readOptionalString();
routing = in.readOptionalString();
parent = in.readOptionalString();
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) {
in.readOptionalString(); // timestamp
in.readOptionalWriteable(TimeValue::new); // ttl
}
source = in.readBytesReference();
opType = OpType.fromId(in.readByte());
version = in.readLong();
versionType = VersionType.fromValue(in.readByte());
pipeline = in.readOptionalString();
isRetry = in.readBoolean();
autoGeneratedTimestamp = in.readLong();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
contentType = in.readOptionalWriteable(XContentType::readFrom);
} else {
contentType = XContentFactory.xContentType(source);
}
}
示例5: handleRequest
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
String scrollId = request.param("scroll_id");
SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
searchScrollRequest.scrollId(scrollId);
String scroll = request.param("scroll");
if (scroll != null) {
searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
}
if (RestActions.hasBodyContent(request)) {
XContentType type = XContentFactory.xContentType(RestActions.getRestContent(request));
if (type == null) {
if (scrollId == null) {
scrollId = RestActions.getRestContent(request).toUtf8();
searchScrollRequest.scrollId(scrollId);
}
} else {
// NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
buildFromContent(RestActions.getRestContent(request), searchScrollRequest);
}
}
client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}
示例6: restContentBuilder
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public static XContentBuilder restContentBuilder(RestRequest request)
throws IOException {
XContentType contentType = XContentType
.fromRestContentType(request.header("Content-Type"));
if (contentType == null) {
// try and guess it from the body, if exists
if (request.hasContent()) {
contentType = XContentFactory.xContentType(request.content());
}
}
if (contentType == null) {
// default to JSON
contentType = XContentType.JSON;
}
BytesStreamOutput out = new BytesStreamOutput();
XContentBuilder builder = new XContentBuilder(
XContentFactory.xContent(contentType), out);
if (request.paramAsBoolean("pretty", false)) {
builder.prettyPrint();
}
String casing = request.param("case");
if (casing != null && "camelCase".equals(casing)) {
builder.fieldCaseConversion(
XContentBuilder.FieldCaseConversion.CAMELCASE);
} else {
builder.fieldCaseConversion(
XContentBuilder.FieldCaseConversion.NONE);
}
return builder;
}
示例7: doRewrite
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
if (document != null) {
return this;
}
GetRequest getRequest = new GetRequest(indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
getRequest.preference("_local");
getRequest.routing(indexedDocumentRouting);
getRequest.preference(indexedDocumentPreference);
if (indexedDocumentVersion != null) {
getRequest.version(indexedDocumentVersion);
}
GetResponse getResponse = queryShardContext.getClient().get(getRequest).actionGet();
if (getResponse.isExists() == false) {
throw new ResourceNotFoundException(
"indexed document [{}/{}/{}] couldn't be found", indexedDocumentIndex, indexedDocumentType, indexedDocumentId
);
}
if(getResponse.isSourceEmpty()) {
throw new IllegalArgumentException(
"indexed document [" + indexedDocumentIndex + "/" + indexedDocumentType + "/" + indexedDocumentId + "] source disabled"
);
}
final BytesReference source = getResponse.getSourceAsBytesRef();
return new PercolateQueryBuilder(field, documentType, source, XContentFactory.xContentType(source));
}
示例8: readFrom
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public static PipelineConfiguration readFrom(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
return new PipelineConfiguration(in.readString(), in.readBytesReference(), XContentType.readFrom(in));
} else {
final String id = in.readString();
final BytesReference config = in.readBytesReference();
return new PipelineConfiguration(id, config, XContentFactory.xContentType(config));
}
}
示例9: innerToXContent
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public void innerToXContent(XContentBuilder builder, Params params) throws IOException {
if (queryBuilder != null) {
builder.field("query");
queryBuilder.toXContent(builder, params);
}
if (queryBinary != null) {
if (XContentFactory.xContentType(queryBinary) == builder.contentType()) {
builder.rawField("query", queryBinary);
} else {
builder.field("query_binary", queryBinary);
}
}
}
示例10: writeRawValue
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public final void writeRawValue(BytesReference content) throws IOException {
XContentType contentType = XContentFactory.xContentType(content);
if (contentType == null) {
throw new IllegalArgumentException("Can't write raw bytes whose xcontent-type can't be guessed");
}
writeRawValue(content, contentType);
}
示例11: readFrom
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readOptionalString();
verbose = in.readBoolean();
source = in.readBytesReference();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(source);
}
}
示例12: readFrom
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
source = in.readBytesReference();
if (in.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
xContentType = XContentType.readFrom(in);
} else {
xContentType = XContentFactory.xContentType(source);
}
}
示例13: appendField
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public static void appendField(XContentBuilder builder, String field,
byte[] data) throws IOException {
XContentType contentType = XContentFactory.xContentType(data);
if (contentType == null) {
addSimpleField(builder, field, data);
} else {
addComplexField(builder, field, contentType, data);
}
}
示例14: toXContent
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
@Override
public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(getName());
if (this.metaData != null) {
builder.field("meta", this.metaData);
}
builder.field(type);
internalXContent(builder, params);
if (aggregations != null || aggregationsBinary != null) {
if (aggregations != null) {
builder.startObject("aggregations");
for (AbstractAggregationBuilder subAgg : aggregations) {
subAgg.toXContent(builder, params);
}
builder.endObject();
}
if (aggregationsBinary != null) {
if (XContentFactory.xContentType(aggregationsBinary) == builder.contentType()) {
builder.rawField("aggregations", aggregationsBinary);
} else {
builder.field("aggregations_binary", aggregationsBinary);
}
}
}
return builder.endObject();
}
示例15: newBuilder
import org.elasticsearch.common.xcontent.XContentFactory; //导入方法依赖的package包/类
public XContentBuilder newBuilder(@Nullable BytesReference autoDetectSource, boolean useFiltering) throws IOException {
XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type")));
if (contentType == null) {
// try and guess it from the auto detect source
if (autoDetectSource != null) {
contentType = XContentFactory.xContentType(autoDetectSource);
}
}
if (contentType == null) {
// default to JSON
contentType = XContentType.JSON;
}
String[] filters = useFiltering ? request.paramAsStringArrayOrEmptyIfAll("filter_path") : null;
XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), bytesOutput(), filters);
if (request.paramAsBoolean("pretty", false)) {
builder.prettyPrint().lfAtEnd();
}
builder.humanReadable(request.paramAsBoolean("human", builder.humanReadable()));
String casing = request.param("case");
if (casing != null) {
String msg = "Parameter 'case' has been deprecated, all responses will use underscore casing in the future";
DEPRECATION_LOGGER.deprecated(msg);
}
if (casing != null && "camelCase".equals(casing)) {
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
} else {
// we expect all REST interfaces to write results in underscore casing, so
// no need for double casing
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
}
return builder;
}