-
-
Save markharwood/86246ef2983b286611f4c4439dee5e99 to your computer and use it in GitHub Desktop.
Accounting for items with multiple Categories and subcategories
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 sandbox | |
PUT sandbox | |
{ | |
"mappings": { | |
"test-cat": { | |
"properties": { | |
"title": { | |
"type": "string" | |
}, | |
"classifications": { | |
"type": "nested", | |
"properties": { | |
"category": { | |
"type": "string" | |
}, | |
"subcategory": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
DELETE /sandbox/test-cat/1 | |
POST /sandbox/test-cat/1 | |
{ | |
"title": "Item 1", | |
"classifications": [ | |
{ | |
"category": "A", | |
"subcategory": [ | |
"A1", | |
"A2" | |
] | |
}, | |
{ | |
"category": "B", | |
"subcategory": [ | |
"B1" | |
] | |
} | |
] | |
} | |
DELETE /sandbox/test-cat/2 | |
POST /sandbox/test-cat/2 | |
{ | |
"title": "Item 2", | |
"classifications": [ | |
{ | |
"category": "A", | |
"subcategory": [ | |
"A1" | |
] | |
} | |
] | |
} | |
POST /sandbox/test-cat/_search?search_type=count | |
{ | |
"aggs": { | |
"classifications": { | |
"nested": { | |
"path": "classifications" | |
}, | |
"aggs": { | |
"categories": { | |
"terms": { | |
"field": "classifications.category" | |
}, | |
"aggs": { | |
"sub_categories": { | |
"terms": { | |
"field": "classifications.subcategory" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment