From 5603c4d09c2a2fd3f4cfd3bccbc780131c42222c Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 6 May 2010 15:50:35 +0300 Subject: [PATCH] add the ability to control the content type the map will serialize under --- .../elasticsearch/action/index/IndexRequest.java | 13 +++++++++++-- .../elasticsearch/util/xcontent/XContentType.java | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 92f4cfd33b8..4ae71bee5c6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -214,13 +214,22 @@ public class IndexRequest extends ShardReplicationOperationRequest { } /** - * Writes the JSON as a {@link Map}. + * Writes the Map as a JSON. * * @param source The map to index */ @Required public IndexRequest source(Map source) throws ElasticSearchGenerationException { + return source(source, XContentType.JSON); + } + + /** + * Writes the JSON as the provided content type. + * + * @param source The map to index + */ + @Required public IndexRequest source(Map source, XContentType contentType) throws ElasticSearchGenerationException { try { - BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(XContentType.JSON); + BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(contentType); builder.map(source); this.source = builder.copiedBytes(); } catch (IOException e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java index 634d24511cd..914bf58b4dd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java @@ -20,11 +20,19 @@ package org.elasticsearch.util.xcontent; /** + * The content type of {@link org.elasticsearch.util.xcontent.XContent}. + * * @author kimchy (shay.banon) */ public enum XContentType { + /** + * A JSON based content type. + */ JSON(0), + /** + * An optimized binary form of JSON. + */ XSON(1); public static XContentType fromRestContentType(String contentType) {