title: ElasticSearch _parent query
body: <p>Elastic documentation states that one can use the _parent field in a query (see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html</a>).</p>
  
  <p>However, I have been unable to get it to work. Here's the simple test:</p>
  
  <pre><code>PUT /company
  {
    "mappings": {
      "branch": {},
      "employee": {
        "_parent": {
          "type": "branch" 
        }
      }
    }
  }
  
  POST /company/branch/_bulk
  { "index": { "_id": "london" }}
  { "name": "London Westminster", "city": "London", "country": "UK" }
  { "index": { "_id": "liverpool" }}
  { "name": "Liverpool Central", "city": "Liverpool", "country": "UK" }
  { "index": { "_id": "paris" }}
  { "name": "Champs Élysées", "city": "Paris", "country": "France" }
  
  PUT /company/employee/1?parent=london 
  {
    "name":  "Alice Smith",
    "dob":   "1970-10-24",
    "hobby": "hiking"
  }
  </code></pre>
  
  <p>Verifying that the employees have a _parent field:</p>
  
  <pre><code>GET /company/employee/_search
  {
    "query": {
      "match_all": {}
    }
  }
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>{
    "took": 1,
    "timed_out": false,
    "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
    },
    "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
        {
          "_index": "company",
          "_type": "employee",
          "_id": "1",
          "_score": 1,
          "_routing": "london",
          "_parent": "london",
          "_source": {
            "name": "Alice Smith",
            "dob": "1970-10-24",
            "hobby": "hiking"
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>But the following:</p>
  
  <pre><code>GET /company/employee/_search
  {
    "query": {
      "term": {
        "_parent":"london"
      }
    }
  }
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>{
    "took": 1,
    "timed_out": false,
    "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
    },
    "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
    }
  }
  </code></pre>
  
  <p>Using "has_parent" works, but why doesn't using _parent work, as stated in the docs.</p>
  
  <p>Here's the query using has_parent that works:</p>
  
  <pre><code>GET /company/employee/_search
  {
    "query": {
      "has_parent": {
        "parent_type":"branch",
        "query":{
          "match_all": {}
        }
      }
    }
  }
  </code></pre>
  
  <p>What am I missing? Using ElasticSearch 5.0.2.</p>