Skip to content

Instantly share code, notes, and snippets.

@dazraf
Last active August 29, 2015 13:58
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 dazraf/10126360 to your computer and use it in GitHub Desktop.
Save dazraf/10126360 to your computer and use it in GitHub Desktop.
curl -XDELETE "http://localhost:9200/contests"
curl -XPUT "http://localhost:9200/contests" -d'
{
"mappings": {
"contest": {
"properties": {
"contestant": {
"type": "nested",
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"data": {
"type": "nested",
"properties": {
"timing": {
"type": "integer"
},
"expectedTiming": {
"type": "integer"
}
}
}
}
}
}
}
}
}'
curl -XPUT "http://localhost:9200/contests/contest/1" -d'
{
"contestant": [
{
"id": "alice",
"data": [
{
"timing": 1,
"expectedTiming": 2
},
{
"timing": 2,
"expectedTiming": 2
}
]
},
{
"id": "jane",
"data": [
{
"timing": 3,
"expectedTiming": 2
},
{
"timing": 4,
"expectedTiming": 2
}
]
}
]
}'
curl -XPUT "http://localhost:9200/contests/contest/2" -d'
{
"contestant": [
{
"id": "alice",
"data": [
{
"timing": 1,
"expectedTiming": 2
},
{
"timing": 2,
"expectedTiming": 2
}
]
},
{
"id": "jane",
"data": [
{
"timing": 3,
"expectedTiming": 2
},
{
"timing": 4,
"expectedTiming": 2
}
]
}
]
}'
curl -XGET "http://localhost:9200/contests/_search" -d'
{
"aggs": {
"myResults": {
"nested": {
"path": "contestant"
},
"aggs": {
"per_contestant": {
"terms": {
"field": "id"
},
"aggs": {
"contestant_data": {
"nested": {
"path": "contestant.data"
},
"aggs": {
"timing_total": {
"sum": {
"field": "timing"
}
}
}
}
}
}
}
}
},
"explain": true
}'
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_shard": 2,
"_node": "6juKykbISA-hUwWyAy3rLw",
"_index": "contests",
"_type": "contest",
"_id": "1",
"_score": 1,
"_source": {
"contestant": [
{
"id": "alice",
"data": [
{
"timing": 1,
"expectedTiming": 2
},
{
"timing": 2,
"expectedTiming": 2
}
]
},
{
"id": "jane",
"data": [
{
"timing": 3,
"expectedTiming": 2
},
{
"timing": 4,
"expectedTiming": 2
}
]
}
]
},
"_explanation": {
"value": 1,
"description": "ConstantScore(cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@953b6c6c)), product of:",
"details": [
{
"value": 1,
"description": "boost"
},
{
"value": 1,
"description": "queryNorm"
}
]
}
},
{
"_shard": 3,
"_node": "6juKykbISA-hUwWyAy3rLw",
"_index": "contests",
"_type": "contest",
"_id": "2",
"_score": 1,
"_source": {
"contestant": [
{
"id": "alice",
"data": [
{
"timing": 1,
"expectedTiming": 2
},
{
"timing": 2,
"expectedTiming": 2
}
]
},
{
"id": "jane",
"data": [
{
"timing": 3,
"expectedTiming": 2
},
{
"timing": 4,
"expectedTiming": 2
}
]
}
]
},
"_explanation": {
"value": 1,
"description": "ConstantScore(cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@953b6c6c)), product of:",
"details": [
{
"value": 1,
"description": "boost"
},
{
"value": 1,
"description": "queryNorm"
}
]
}
}
]
},
"aggregations": {
"myResults": {
"doc_count": 4,
"per_contestant": {
"buckets": [
{
"key": "alice",
"doc_count": 2,
"contestant_data": {
"doc_count": 4,
"timing_total": {
"value": 6
}
}
},
{
"key": "jane",
"doc_count": 2,
"contestant_data": {
"doc_count": 4,
"timing_total": {
"value": 14
}
}
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment