-
-
Save anonymous/cd050e97c23a36d1d8da to your computer and use it in GitHub Desktop.
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-10-02T17:10:29+02: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
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