Elasticsearch父母和孩子

时间:2015-09-28 18:46:08

标签: elasticsearch

如果我这样说:

PUT /hostpid
{
  "mappings": {
    "parent": {},
    "child": {
      "_parent": {
        "type": "parent" 
      }
    },"child1": {
      "_parent": {
        "type": "parent" 
      }
    }
  }
}

父母有两个孩子,childchild1

我有一个问题, 有没有办法直接在父母中添加新的child2?

1 个答案:

答案 0 :(得分:0)

Did you try using the put mapping API?

To test it I used your mappings:

PUT /test_index
{
   "mappings": {
      "parent": {},
      "child": {
         "_parent": {
            "type": "parent"
         }
      },
      "child1": {
         "_parent": {
            "type": "parent"
         }
      }
   }
}

Then created another mapping like this:

PUT /test_index/child2/_mapping
{
   "child2": {
      "_parent": {
         "type": "parent"
      }
   }
}

And if I request the full mapping they all show up:

GET /test_index/_mapping
...
{
   "test_index": {
      "mappings": {
         "child2": {
            "_parent": {
               "type": "parent"
            },
            "_routing": {
               "required": true
            },
            "properties": {}
         },
         "parent": {
            "properties": {}
         },
         "child1": {
            "_parent": {
               "type": "parent"
            },
            "_routing": {
               "required": true
            },
            "properties": {}
         },
         "child": {
            "_parent": {
               "type": "parent"
            },
            "_routing": {
               "required": true
            },
            "properties": {}
         }
      }
   }
}

Here's the code I used for testing:

http://sense.qbox.io/gist/11846b82cbd0f818c4d1c187ebf905d41835b3b0