Detection of object arrays

Hi all,

did not found anything about this topic
it seems to me, that arrays of objects are not detected automatically:

(java insert)
startObject()
.startObject("someThing")
.field("id", 42)
.field("fieldName", "fieldValue")
.endObject()
.startObject("someThing")
.field("id", 43)
.field("fieldName", "other fieldValue")
.endObject()
.endObject()

results in something like:

{
"someThing":{
"id":42,
"fieldName":"fieldValue"
},
"someThing":{
"id":43,
"fieldName":"other fieldValue"
}
}

i am expecting something like

{
"someThing":[
{
"id":42,
"fieldName":"fieldValue"
},
{
"id":43,
"fieldName":"other fieldValue"
}
]
}

for me it is not possible to insert something in this way (we do not have
the all the "someThing"s at one time):
startArray("someThing")
.startObject()
.field("id", 42)
.field("fieldName", "fieldValue")
.endObject()
.startObject()
.field("id", 43)
.field("fieldName", "other fieldValue")
.endObject()
.endArray()

searching works also for e.g. "other fieldValue" but when I parse the
source of the searchHit (java again), i get not a list for "someThing",
only a normal Map is found.

Is there some error in my considerations/coding or is this a bug?

Best regards,
Daniel

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

In the Elasticsearch object model, which maps to Lucene fields, the two
alternatives are equivalent. Although not correct JSON because two
object names occur, ES accepts double JSON keys while parsing.

Jörg

Am 16.08.2013 12:06, schrieb daniel koller:

Hi all,

did not found anything about this topic
it seems to me, that arrays of objects are not detected automatically:

(java insert)
|
startObject()
.startObject("someThing")
.field("id",42)
.field("fieldName","fieldValue")
.endObject()
.startObject("someThing")
.field("id",43)
.field("fieldName","other fieldValue")
.endObject()
.endObject()
|

results in something like:

|
{
"someThing":{
"id":42,
"fieldName":"fieldValue"
},
"someThing":{
"id":43,
"fieldName":"other fieldValue"
}
}
|

i am expecting something like

|
{
"someThing":[
{
"id":42,
"fieldName":"fieldValue"
},
{
"id":43,
"fieldName":"other fieldValue"
}
]
}
|

for me it is not possible to insert something in this way (we do not
have the all the "someThing"s at one time):
|
startArray("someThing")
.startObject()
.field("id",42)
.field("fieldName","fieldValue")
.endObject()
.startObject()
.field("id",43)
.field("fieldName","other fieldValue")
.endObject()
.endArray()
|

searching works also for e.g. "other fieldValue" but when I parse the
source of the searchHit (java again), i get not a list for
"someThing", only a normal Map is found.

Is there some error in my considerations/coding or is this a bug?

Best regards,
Daniel

You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Jörg,

since the first object can not be retrieved from a searchHit, it might be
better to build an array when adding the second object instead of adding a
second object with the same name.
or collection all object from with the same name and adding them to the
source Map of the search hit (since the first object is present in the
searchResponse but not in the searchHit source).

Maybe I am just too stupid to find it, but is there a way to add multiple
object to an array after adding the single object to a XContentBuilder?
For only one single object, this can be done with
xContentBuilder.rawField(String name, ByteReference byteReference).

I thought of something like:

builder.startArray("someThing");
for(ByteReference ref: references){
builder.raw(ref); //not existing
}
builder.endArray()

where the references Iterable contains the bytes which where build and
collected before.

Best regards,
Daniel

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I agree, this is one thing I also miss in the XContentBuilder API.

Maybe XContentBuilder can be improved, so for example, it could also
understand the nuances of JSONML mixed object/value arrays.

Jörg

Am 16.08.2013 13:34, schrieb daniel koller:

Maybe I am just too stupid to find it, but is there a way to add
multiple object to an array after adding the single object to a
XContentBuilder?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Jörg,

i worked it out by just passing the "parent"-xContentBuilder arround and
calling a "startArray"-Function before and an "endArray"-Function after
adding the array-objects.

Thank you very much,
best regards from switzerland,
Daniel

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.