Function score with nested docs stops working after adding attribute with not unique name

Hi guys,

I am trying to calculate the _score of the document as a sum of IDs of my
nested docs.

Here is the mapping:

PUT /test/property/_mapping
{
   "property": {
      "properties": {
         "destination_id": {
            "type": "long"
         },
         "rates": {
            "type": "nested",
            "properties": {
               "id": {
                  "type": "long"
               },
               "end_date": {
                  "type": "date",
                  "format": "dateOptionalTime"
               },
               "start_date": {
                  "type": "date",
                  "format": "dateOptionalTime"
               }
            }
         }
      }
   }
} 

and here is my query:

GET /test/property/_search
{
   "query": {
      "filtered": {
         "query": {
            "nested": {
               "path": "rates",
               "score_mode": "sum",
               "query": {
                  "function_score": {
                     "functions": [
                        {
                           "script_score": {
                              "script": "doc['id'].value"
                           }
                        }
                     ]
                  }
               }
            }
         }
      }
   }
}

It works fine and score is calculated properly when I don't have field id
in my main (top level) document.
Something unexpected happens though as soon as I add document constructed
that way:

POST /test/property/3
{
   "destination_id": 1,
   "id": 12,
   "rates": [
      {
         "id": 9,
         "end_date": "2014-10-15"
      },
      {
         "id": 10,
         "end_date": "2014-10-20"
      }
   ]
}

after that all my _scores are reduced to 0.
Seems like the top attribute kind of 'overshadows' the nested ones...
anyway shouldn't happen as I explicitly use nested path?
I wonder why is that happening and how can I make sure that one incorrectly
indexed document will not have such an impact on the search query?

Thank you,
Gosia

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ef1c870b-080c-41ec-99c7-5854d6c5a54d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.