0

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?

5
  • You're indexing the document into the server index, but the response somehow shows that the document is in the living index. Weird, not sure how that's possible. Commented Oct 13, 2015 at 8:00
  • It's just a typing mistake. I've just edited it. server means the url to ES server, that's not the index. The index is index, and the collection is test Commented Oct 13, 2015 at 8:53
  • Ok, makes sense. What still doesn't make sense, though, is your source with to fields which are not even double-quoted strings. Which tool/plugin are you using to send your queries? Commented Oct 13, 2015 at 8:59
  • I'm using curl tool. Commented Oct 13, 2015 at 9:22
  • Interesting case. Using Sense, I get a Bad string (next to the first to field) warning when retrieving the search results... Commented Oct 13, 2015 at 9:32

1 Answer 1

1

In a JSON document you cannot have two fields with the same name, but ES will silently "fix" your document and only index a single to field. Moreover, since a JSON document is basically a map, which is inherently unordered, you have no guarantee as to which one of the three to fields get indexed.

So if you index that document, it will work, but you'll only see a single to field in it, which is probably not what you want:

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

GET 'server/test/1'
{
    to: "to3"            <--- could also be to1 or to2
}

However, if you make to an array of values then all the values will be indexed

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

GET 'server/test/1'
{
    to: ["to1", "to2", "to3"]
}
Sign up to request clarification or add additional context in comments.

1 Comment

I've added some searches on my post. It seems ES indexes every repeated field value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.