Actually, i am not creating a query here, i want to index the values like
this. Is there any way to do this?
Right, I misunderstood your question.
The example you have is invalid JSON, when you have a hash two keys
can't have the same keyname.
This is correct.
So no, you can't do it like that, and you have to explicitly create an
array yourself.
This isn't. Elasticsearch parses JSON in a stream and accepts repeated
keys (ie invalid JSON) as multi-value fields. So your example doc would
actually work - it would give you a multi-value field which you can
search on.
However, I wouldn't recommend it, especially if you're going to use the
JSON document that is returned from ES Any valid JSON parser would throw
away one of your values. Abusing the streaming parser in this way is
bound to cause hard-to-spot bugs later on.
On Fri, 2012-06-22 at 14:34 +0200, Ævar Arnfjörð Bjarmason wrote:
So no, you can't do it like that, and you have to explicitly create an
array yourself.
This isn't. Elasticsearch parses JSON in a stream and accepts repeated
keys (ie invalid JSON) as multi-value fields. So your example doc would
actually work - it would give you a multi-value field which you can
search on.
However, I wouldn't recommend it, especially if you're going to use the
JSON document that is returned from ES Any valid JSON parser would throw
away one of your values. Abusing the streaming parser in this way is
bound to cause hard-to-spot bugs later on.
I didn't know that, I wonder whether this is intentional or a quirk of
the current JSON parser that might go away.
I tried it out with my code, used bulkRequestBuilder to do so, the problem
is that it ignores the first value, i.e in the example it will only index
black not blue, a sort of overwrite i guess.
On Fri, Jun 22, 2012 at 7:39 PM, Ævar Arnfjörð Bjarmason avarab@gmail.comwrote:
On Fri, 2012-06-22 at 14:34 +0200, Ævar Arnfjörð Bjarmason wrote:
So no, you can't do it like that, and you have to explicitly create an
array yourself.
This isn't. Elasticsearch parses JSON in a stream and accepts repeated
keys (ie invalid JSON) as multi-value fields. So your example doc would
actually work - it would give you a multi-value field which you can
search on.
However, I wouldn't recommend it, especially if you're going to use the
JSON document that is returned from ES Any valid JSON parser would throw
away one of your values. Abusing the streaming parser in this way is
bound to cause hard-to-spot bugs later on.
I didn't know that, I wonder whether this is intentional or a quirk of
the current JSON parser that might go away.
--
Saurabh Kumar
M.Sc (Mathematics) B.E (Computer Science)
Birla Institute of Technology and Science-Pilani
I am having the same problem while indexing multi value fields.
BulkRequestBuilder is overwriting the first value.
Do you have any solution for this ? Please help me in this regard.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.