Index parent-child with _id

Hi all! I use parent-child model in my index "npk" and here are some questions basically on the ways i can search. I studied has-child and has-parent queries but i don't get any results for the docs i inserted to this index.

My index creation:

PUT /npk
{ 
    "settings" : {
        "index" : {
            "number_of_shards" : 3, 
            "number_of_replicas" : 2 
        }
    },
  "dynamic": true,
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field" : {
                "type" : "join",
                "relations": {
                    "header": "body"
                }}}}}}

I indexed 2 parents with _ids 1 and 4:

PUT /npk/doc/1
{
        "header_column_1": "value1",
        "header_column_2": "value2",
        "my_join_field": "header"
}

I indexed 2 children for each parent with ids 2, 3 and 5, 6:

PUT /npk/doc/2?routing=1&refresh
{ 
  "body_column_1": 220,
  "body_column_2": 220,
  "my_join_field": {
    "name": "body",
    "parent": "1"
  }
}  

My question is: Both parent and child have to be in the field '_id' ? Do i implement it in the right way here? I have read somewhere that '_id' field has a limit of 512 bytes, so we cannot increase it too much. I have made a script that puts parents-children and in the '_id' i have an auto-increment routine to increase it as a number. Is it right to be a number? Because by default it takes alphanumeric values.

The weird here is that when i run the below query for both parents (_ids 1 and 4) to get their children i receive correct results:

GET /npk/_search
{
  "query": {
      "parent_id": {
          "type": "body",
          "id": "4"
      }
  }

}

response:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.87546873,
    "hits": [
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "5",
        "_score": 0.87546873,
        "_routing": "1",
        "_source": {
          "body_column_1": 200,
          "body_column_2": 200,
          "my_join_field": {
            "name": "body",
            "parent": "4"
          }
        }
      },
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "6",
        "_score": 0.87546873,
        "_routing": "1",
        "_source": {
          "body_column_1": 220,
          "body_column_2": 220,
          "my_join_field": {
            "name": "body",
            "parent": "4"
          }
        }
      }
    ]
  }
}

... BUT, when i run the has_child query

GET /npk/_search
{
    "query": {
        "has_child" : {
            "type" : "body",
            "query" : {
                "match_all" : {}
            },
            "max_children": 10,
            "min_children": 1,
            "score_mode" : "min"
        }
    }
}

i get results only for the parent with _id = 1. The other with _id=4 is missing!

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "header_column_1": "value1",
          "header_column_2": "value1",
          "my_join_field": "header"
        }
      }
    ]
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.