Skip to content

Instantly share code, notes, and snippets.

/documents.yaml Secret

Created October 2, 2014 15:10
Show Gist options
  • Save anonymous/cd050e97c23a36d1d8da to your computer and use it in GitHub Desktop.
Save anonymous/cd050e97c23a36d1d8da to your computer and use it in GitHub Desktop.
_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
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
#!/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"
}
}
}
}
}
}
}
}
'
# Auto generated by Found's Play-tool at 2014-10-02T17:10:29+02:00
version: 0
title: Hierarchical facets with Elasticsearch
description: ""
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