Last active
June 28, 2017 12:10
-
-
Save yanglikun/8ce5cdb8b51b364f7a6031f60ba3436e to your computer and use it in GitHub Desktop.
es-关联关系-nested
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_nested_index | |
PUT /relation_nested_index | |
PUT /relation_nested_index/_mapping/relation_nested_type | |
{ | |
"relation_nested_type": { | |
"properties": { | |
"members": { | |
"type":"nested", | |
"properties": { | |
"firstName": { | |
"type": "string" | |
}, | |
"lastName": { | |
"type": "string" | |
} | |
} | |
}, | |
"projectName": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
GET /relation_nested_index/_mapping | |
PUT /relation_nested_index/relation_nested_type/1 | |
{ | |
"projectName": "train", | |
"members": [ | |
{ | |
"firstName":"san", | |
"lastName":"zhang" | |
},{ | |
"firstName":"si", | |
"lastName":"li" | |
} | |
] | |
} | |
PUT /relation_nested_index/relation_nested_type/2 | |
{ | |
"projectName": "airplane", | |
"members": [ | |
{ | |
"firstName":"wu", | |
"lastName":"wang" | |
},{ | |
"firstName":"liu", | |
"lastName":"zhao" | |
} | |
] | |
} | |
GET /relation_nested_index/_search | |
#nested query:no cross-object bescause of nested | |
GET /relation_nested_index/_search | |
{ | |
"query": { | |
"nested": { | |
"path": "members", | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"members.lastName": { | |
"value": "zhang" | |
} | |
} | |
}, | |
{ | |
"term": { | |
"members.firstName": { | |
"value": "si" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
#match inner document | |
GET /relation_nested_index/_search | |
{ | |
"query": { | |
"nested": { | |
"path": "members", | |
"query": { | |
"term": { | |
"members.lastName": { | |
"value": "zhang" | |
} | |
} | |
}, | |
"inner_hits":{} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment