Support for indexing all Java collections

Started using ElasticSearch on a new (to me) project and came across a
small issue while indexing sets.

Set set = ...
builder.field("fieldName", set);

The code will call the overloaded method XContentBuilder#field(String
name, Object value), since there is no method for the more restrictive
type Set. There is an overloaded method for
XContentBuilder#field(String name, List value), so the solution is to
simply create a list out of the set. However, looking at the latter
method, there should be no reason why the type should not be
Collection and not just List.

Ivan

The aim is not to create a full object to json mapping in elasticsearch,
use jackson for that.

On Wed, Nov 30, 2011 at 2:10 AM, Ivan Brusic ivan@brusic.com wrote:

Started using Elasticsearch on a new (to me) project and came across a
small issue while indexing sets.

Set set = ...
builder.field("fieldName", set);

The code will call the overloaded method XContentBuilder#field(String
name, Object value), since there is no method for the more restrictive
type Set. There is an overloaded method for
XContentBuilder#field(String name, List value), so the solution is to
simply create a list out of the set. However, looking at the latter
method, there should be no reason why the type should not be
Collection and not just List.

Ivan

The issue has nothing to do with JSON. Indexing any Java collection is
easy with a change of the method:
https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L498

Replace List with Collection and you should now be able to index items
such as Sets and even Vectors. Currently, a Set uses the Object level
overloaded method:

https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L616

Since the if-elsif statements does not find set, it simply gets
converted with toString, but the List method would work perfectly.

The issue is very minor. The workaround is simple, but it would be
nice to have Collection level support and not just List.

Cheers,

Ivan

On Wed, Nov 30, 2011 at 3:09 AM, Shay Banon kimchy@gmail.com wrote:

The aim is not to create a full object to json mapping in elasticsearch, use
jackson for that.

On Wed, Nov 30, 2011 at 2:10 AM, Ivan Brusic ivan@brusic.com wrote:

Started using Elasticsearch on a new (to me) project and came across a
small issue while indexing sets.

Set set = ...
builder.field("fieldName", set);

The code will call the overloaded method XContentBuilder#field(String
name, Object value), since there is no method for the more restrictive
type Set. There is an overloaded method for
XContentBuilder#field(String name, List value), so the solution is to
simply create a list out of the set. However, looking at the latter
method, there should be no reason why the type should not be
Collection and not just List.

Ivan

It can be fixed (open an issue), but, it is not designed to be a
replacement to a fully fledged object to json mapper.

On Wed, Nov 30, 2011 at 9:57 PM, Ivan Brusic ivan@brusic.com wrote:

The issue has nothing to do with JSON. Indexing any Java collection is
easy with a change of the method:

https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L498

Replace List with Collection and you should now be able to index items
such as Sets and even Vectors. Currently, a Set uses the Object level
overloaded method:

https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L616

Since the if-elsif statements does not find set, it simply gets
converted with toString, but the List method would work perfectly.

The issue is very minor. The workaround is simple, but it would be
nice to have Collection level support and not just List.

Cheers,

Ivan

On Wed, Nov 30, 2011 at 3:09 AM, Shay Banon kimchy@gmail.com wrote:

The aim is not to create a full object to json mapping in elasticsearch,
use
jackson for that.

On Wed, Nov 30, 2011 at 2:10 AM, Ivan Brusic ivan@brusic.com wrote:

Started using Elasticsearch on a new (to me) project and came across a
small issue while indexing sets.

Set set = ...
builder.field("fieldName", set);

The code will call the overloaded method XContentBuilder#field(String
name, Object value), since there is no method for the more restrictive
type Set. There is an overloaded method for
XContentBuilder#field(String name, List value), so the solution is to
simply create a list out of the set. However, looking at the latter
method, there should be no reason why the type should not be
Collection and not just List.

Ivan