Unable to index child documents in parent-child relationship

I've created an index with two types:

PUT /pc_test_index

{
  "mappings": {
    "childtype": {
      "_parent": {
        "type": "parenttype"
      },
      "properties": {
        "childprop": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    },
    "parenttype": {
      "properties": {
        "parentprop": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}

This went swimmingly. I can even index parent documents:

POST /pc_test_index/_bulk

{ "index": { "_id": "p01", "_type": "parenttype" } }
{ "parentprop": "parentprop01" }

What I cannot do, however, is index child documents:

POST /pc_test_index/_bulk

{ "index": { "_id": "c01", "_type": "childdtype", "parent": "p01" } }
{ "childprop": "childprop01" }

This results in an error:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Can't specify parent if no parent field has been configured"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Can't specify parent if no parent field has been configured"
  },
  "status": 400
}

This would, of course, make sense to me, except that I'm fairly certain that I configured the _parent in the mapping for childtype. I have seen vague references to some type of field property in the _parent structure, but the documentation does not mention it (that I can find). Am I missing something obvious here?

Thanks for your time.

You have a typo in your request: 'chliddtype' should be 'childtype'.

Indeed. How embarrassing. Works like a charm when I type correctly. Thanks!

1 Like