Skip to content

Instantly share code, notes, and snippets.

@yanglikun
Last active June 28, 2017 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanglikun/8ce5cdb8b51b364f7a6031f60ba3436e to your computer and use it in GitHub Desktop.
Save yanglikun/8ce5cdb8b51b364f7a6031f60ba3436e to your computer and use it in GitHub Desktop.
es-关联关系-nested
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