Multiple fields with different values in a same document

I'd like to know a bit more about the next situation. I'm trying to index a document like this:

PUT 'server/index/test/1'
{
    to: "to1",
    to: "to2",
    to: "to3"
}

Seemingly, elasticsearch swallows this document. Ok , no problem. Nevertheless, I would like to know which are the differences between an array of values.

How the searches are made?

EDITED:

I've tried this searches:

GET 'server/index/test/_search?q=to:to1&pretty'
GET 'server/index/test/_search?q=to:to2&pretty'
GET 'server/index/test/_search?q=to:to3&pretty'

and ES shows me the document after each execution:

{
   "took" : 44,
   "timed_out" : false,
   "_shards" : {
       "total" : 5,
       "successful" : 5,
       "failed" : 0
   },
   "hits" : {
   "total" : 1,
   "max_score" : 1.0,
       "hits" : [ {
           "_index" : "index",
           "_type" : "test",
           "_id" : "1",
           "_score" : 1.0,
           "_source":
           {
               to: "to1",
               to: "to2",
               to: "to3"
           }
       } ]
    }
}

Seemingly, ES indexes every repeated field value also... Is it really like this? Or I'm performing or doing something wrong?

I think first of all this is incorrect json.

You should write something like:

{
  "to" : [ "to1", "to2", "to3"]
}

I've been able to save this document in ES.

From a end user perspective, what do you expect?

If to can be 3 values, what does it mean? Why do you think the result you get is incorrect?

In short: what are you trying to do ?

I've exposed this issue in order to ensure what I'm trying to get is not going to run in problems tomorrow.
I'm trying to do exactly what I've exposed.

As you can guess, It's consequence of providing a first disign:

  • Every field of my entities save a value.

After 2 or 3 iterations, we figured out it's possible:

  • User needs to store several values for each "field".

The porblem is that we began storing out objects in ES using a single field: value1, field: value2 pattern for each field.
So, as you can figure out, I'm trying to be sure that I can keep this approach, or I need to do a refactoring in order to store every field as an arrray pattern: field: [value1, value2].

The json is definitely invalid. I wouldn't rely on future versions of elasticsearch accepting it.

1 Like