title: problems on elasticsearch with parent child documents
body: <p>We work with two types of documents on elastic search (ES): items and slots, where items are parents of slot documents.
  We define the index with the following command:</p>
  
  <pre><code>curl -XPOST 'localhost:9200/items' -d @itemsdef.json
  </code></pre>
  
  <p>where <code>itemsdef.json</code> has the following definition</p>
  
  <pre><code>{
  "mappings" : {
      "item" : {
          "properties" : {
              "id" : {"type" : "long" },
              "name" : {
                  "type" : "string",
                  "_analyzer" : "textIndexAnalyzer"   
              },
              "location" : {"type" : "geo_point" },
          }
      }
  },
  "settings" : {
      "analysis" : {
          "analyzer" : {
  
                  "activityIndexAnalyzer" : {
                      "alias" : ["activityQueryAnalyzer"],
                      "type" : "custom",
                      "tokenizer" : "whitespace",
                      "filter" : ["trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
                  },
                  "textIndexAnalyzer" : {
                      "type" : "custom",
                      "tokenizer" : "whitespace",
                      "filter" : ["word_delimiter_impl", "trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
                  },
                  "textQueryAnalyzer" : {
                      "type" : "custom",
                      "tokenizer" : "whitespace",
                      "filter" : ["trim", "lowercase", "asciifolding", "spanish_stop"]
                  }       
          },
          "filter" : {        
                  "spanish_stop" : {
                      "type" : "stop",
                      "ignore_case" : true,
                      "enable_position_increments" : true,
                      "stopwords_path" : "analysis/spanish-stopwords.txt"
                  },
                  "spanish_synonym" : {
                      "type" : "synonym",
                      "synonyms_path" : "analysis/spanish-synonyms.txt"
                  },
                  "word_delimiter_impl" : {
                      "type" : "word_delimiter",
                      "generate_word_parts" : true,
                      "generate_number_parts" : true,
                      "catenate_words" : true,
                      "catenate_numbers" : true,
                      "split_on_case_change" : false                  
                  }               
          }
      }
  }
  }
  </code></pre>
  
  <p>Then we add the child document definition using the following command:</p>
  
  <pre><code>curl -XPOST 'localhost:9200/items/slot/_mapping' -d @slotsdef.json
  </code></pre>
  
  <p>Where <code>slotsdef.json</code> has the following definition:</p>
  
  <pre><code>{
  "slot" : {
      "_parent" : {"type" : "item"},
      "_routing" : {
          "required" : true,
          "path" : "parent_id"
      },
      "properties": {
          "id" : { "type" : "long" },
          "parent_id" : { "type" : "long" },
          "activity" : {
              "type" : "string",
              "_analyzer" : "activityIndexAnalyzer"
          },
          "day" : { "type" : "integer" },
          "start" : { "type" : "integer" },
          "end" :  { "type" : "integer" }
      }
  }   
  }
  </code></pre>
  
  <p>Finally we perform a bulk index with the following command:</p>
  
  <pre><code>curl -XPOST 'localhost:9200/items/_bulk' --data-binary @testbulk.json
  </code></pre>
  
  <p>Where testbulk.json holds the following data:</p>
  
  <pre><code>{"index":{"_type": "item", "_id":35}}
  {"location":[40.4,-3.6],"id":35,"name":"A Name"}
  {"index":{"_type":"slot","_id":126,"_parent":35}}
  {"id":126,"start":1330,"day":1,"end":1730,"activity":"An Activity","parent_id":35}
  </code></pre>
  
  <p>We see through ES Head plugin that definitions seem to be ok. We test the analyzers to check that they have been loaded and they work. Both documents appear listed in ES Head browser view. But if we try to retrieve the child item using the API, ES responds that it does not exist:</p>
  
  <pre><code>$ curl -XGET 'localhost:9200/items/slot/126'
  {"_index":"items","_type":"slot","_id":"126","exists":false}
  </code></pre>
  
  <p>When we import 50 documents, all parent documents can be retrieved through API, but only SOME of the requests for child elements get a successful response.</p>
  
  <p>My guess is that it may have something to do with how docs are stored across shards and the routing...which certainly is not clear to me how it works. </p>
  
  <p>Any clue on how to be able to retrieve individual child documents? ES Head shows they have been stored but HTTP GETs to localhost:9200/items/slot/XXX respond randomly with "exists":false.</p>