Last active
June 29, 2017 06:16
-
-
Save yanglikun/fd9aa4402ddebfb5d00c4e458c0ee211 to your computer and use it in GitHub Desktop.
es-关联关系-parentchild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE relation_parentchild_index | |
PUT /relation_parentchild_index | |
#child must create before parent | |
PUT /relation_parentchild_index/_mapping/relation_child_type | |
{ | |
"relation_child_type": { | |
"_parent": { | |
"type": "relation_parent_type" | |
}, | |
"properties": { | |
"firstName":{ | |
"type":"string" | |
}, | |
"lastName":{ | |
"type":"string" | |
} | |
} | |
} | |
} | |
PUT /relation_parentchild_index/_mapping/relation_parent_type | |
{ | |
"relation_parent_type": { | |
"properties": { | |
"projectName": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
GET /relation_parentchild_index/_mapping | |
#index parent | |
PUT /relation_parentchild_index/relation_parent_type/1 | |
{ | |
"projectName":"train" | |
} | |
PUT /relation_parentchild_index/relation_parent_type/2 | |
{ | |
"projectName":"airplane" | |
} | |
#index child | |
PUT /relation_parentchild_index/relation_child_type/1?parent=1 | |
{ | |
"firstName":"san", | |
"lastName":"zhang" | |
} | |
PUT /relation_parentchild_index/relation_child_type/2?parent=1 | |
{ | |
"firstName":"si", | |
"lastName":"li" | |
} | |
PUT /relation_parentchild_index/relation_child_type/1?parent=2 | |
{ | |
"firstName":"wu", | |
"lastName":"wang" | |
} | |
PUT /relation_parentchild_index/relation_child_type/2?parent=2 | |
{ | |
"firstName":"liu", | |
"lastName":"zhao" | |
} | |
#search parent | |
GET /relation_parentchild_index/relation_parent_type/_search | |
#search child | |
GET /relation_parentchild_index/relation_child_type/_search | |
#search child with id | |
GET /relation_parentchild_index/relation_child_type/1?parent=2 | |
#update child | |
POST /relation_parentchild_index/relation_child_type/1/_update?parent=2 | |
{ | |
"doc":{ | |
"firstName":"wu-update" | |
} | |
} | |
#delete child with id must parent | |
DELETE /relation_parentchild_index/relation_child_type/1?parent=2 | |
#has_child query/filter | |
GET /relation_parentchild_index/relation_parent_type/_search | |
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"has_child": { | |
"type": "relation_child_type", | |
"filter": { | |
"term": { | |
"lastName": "zhang" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
#has_parent query/filter | |
GET /relation_parentchild_index/relation_child_type/_search | |
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"has_parent": { | |
"parent_type": "relation_parent_type", | |
"filter": { | |
"term": { | |
"projectName": "train" | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment