title: Parent Child Relation In Elastic Search 7.5
body: <p>I am new to "<strong>Elastic Search</strong>" and currently trying to understand how does ES maintain "<strong>Parent-Child</strong>" relationship. I started with the following article:</p>
  
  <p><a href="https://www.elastic.co/blog/managing-relations-inside-elasticsearch" rel="noreferrer">https://www.elastic.co/blog/managing-relations-inside-elasticsearch</a></p>
  
  <p>But the article is based on old version of ES and I am currently using ES 7.5 which states that:</p>
  
  <p><strong>The _parent field has been removed in favour of the join field.</strong> </p>
  
  <p>Now I am currently following this article:</p>
  
  <p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.5/parent-join.html" rel="noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/7.5/parent-join.html</a></p>
  
  <p>However, I am not able to get the desired result.</p>
  
  <p>I have a scenario in which i have two indices "Person" and "Home". Each "Person" can have multiple "Home" which is basically a one-to-many relation. Problem is when I query to fetch all homes whose parent is "XYZ" person the answer is null.</p>
  
  <p>Below are my indexes structure and search query:</p>
  
  <h1>Person Index:</h1>
  
  <p>Request URL: <a href="http://hostname/person" rel="noreferrer">http://hostname/person</a></p>
  
  <pre><code>{
      "mappings": {
          "properties": {
              "name": {
                  "type": "text"
              },
              "person_home": {
                  "type": "join",
                  "relations": {
                      "person": "home"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <h1>Home Index:</h1>
  
  <p>Request URL: <a href="http://hostname/home" rel="noreferrer">http://hostname/home</a> </p>
  
  <pre><code>{
      "mappings": {
          "properties": {
              "state": {
                  "type": "text"
              },
              "person_home": {
                  "type": "join",
                  "relations": {
                      "person": "home"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <h1>Adding data in person Index</h1>
  
  <p>Request URL: <a href="http://hostname/person/_doc/1" rel="noreferrer">http://hostname/person/_doc/1</a>  </p>
  
  <pre><code>{
      "name": "shujaat",
      "person_home": {
          "name": "person"
      }
  }
  </code></pre>
  
  <h1>Adding data in home index</h1>
  
  <p>Request URL: <a href="http://hostname/home/_doc/2?routing=1&amp;refresh" rel="noreferrer">http://hostname/home/_doc/2?routing=1&amp;refresh</a></p>
  
  <pre><code>{
      "state": "ontario",
      "person_home": {
          "name": "home",
          "parent": "1"
      }
  }
  </code></pre>
  
  <h1>Query to fetch data: (To fetch all the records who parent is person id "1")</h1>
  
  <p>Request URL: <a href="http://hostname/person/_search" rel="noreferrer">http://hostname/person/_search</a></p>
  
  <pre><code>   {
      "query": {
          "has_parent": {
              "parent_type": "person",
              "query": {
                  "match": {
                      "name": "shujaat"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>{
      "query": {
          "has_parent": {
              "parent_type": "person",
              "query": {
                  "match": {
                      "_id": "1"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <h1>Response:</h1>
  
  <pre><code>{
      "took": 1,
      "timed_out": false,
      "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
      },
      "hits": {
          "total": {
              "value": 0,
              "relation": "eq"
          },
          "max_score": null,
          "hits": []
      }
  }
  </code></pre>
  
  <p>I am unable to understand what I am missing here or what is wrong with the above mentioned query as it not returning any data.</p>