-
-
Save jeremyb/c6fc7c11b8a4b5967008 to your computer and use it in GitHub Desktop.
Hierarchical facets with Elasticsearch
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
_type: product | |
category_level0: Books | |
category_level1: Computers & Technology | |
category_level2: Network Programming | |
name: Pro AngularJS | |
--- | |
_type: product | |
category_level0: Books | |
category_level1: Computers & Technology | |
category_level2: Online Searching | |
name: ElasticSearch Server Second Edition | |
--- | |
_type: product | |
category_level0: Books | |
category_level1: Arts & Photography | |
category_level2: Photography & Video | |
name: Humans of New York | |
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
product: | |
properties: | |
category_level0: | |
type: string | |
index: not_analyzed | |
category_level1: | |
type: string | |
index: not_analyzed | |
category_level2: | |
type: string | |
index: not_analyzed | |
name: | |
type: string | |
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
#!/bin/bash | |
export ELASTICSEARCH_ENDPOINT="http://localhost:9200" | |
# Create indexes | |
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{ | |
"mappings": { | |
"product": { | |
"properties": { | |
"category_level0": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"category_level1": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"category_level2": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"name": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}' | |
# Index documents | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' | |
{"index":{"_index":"play","_type":"product"}} | |
{"category_level0":"Books","category_level1":"Computers & Technology","category_level2":"Network Programming","name":"Pro AngularJS"} | |
{"index":{"_index":"play","_type":"product"}} | |
{"category_level0":"Books","category_level1":"Computers & Technology","category_level2":"Online Searching","name":"ElasticSearch Server Second Edition"} | |
{"index":{"_index":"play","_type":"product"}} | |
{"category_level0":"Books","category_level1":"Arts & Photography","category_level2":"Photography & Video","name":"Humans of New York"} | |
' | |
# Do searches | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"size": 0, | |
"aggregations": { | |
"category": { | |
"terms": { | |
"field": "category_level0" | |
}, | |
"aggs": { | |
"level1": { | |
"terms": { | |
"field": "category_level1" | |
}, | |
"aggs": { | |
"level2": { | |
"terms": { | |
"field": "category_level2" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
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
# Auto generated by Found's Play-tool at 2014-11-13T09:48:45+01:00 | |
version: 0 | |
title: Hierarchical facets with Elasticsearch | |
description: "" |
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
aggregations: | |
category: | |
buckets: | |
- | |
key: "Books" | |
doc_count: 3 | |
level1: | |
buckets: | |
- | |
key: "Computers & Technology" | |
doc_count: 2 | |
level2: | |
buckets: | |
- | |
key: "Network Programming" | |
doc_count: 1 | |
- | |
key: "Online Searching" | |
doc_count: 1 | |
- | |
key: "Arts & Photography" | |
doc_count: 1 | |
level2: | |
buckets: | |
- | |
key: "Photography & Video" | |
doc_count: 1 |
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
size: 0 | |
aggregations: | |
category: | |
terms: | |
field: category_level0 | |
aggs: | |
level1: | |
terms: | |
field: category_level1 | |
aggs: | |
level2: | |
terms: | |
field: category_level2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment