Skip to content

Instantly share code, notes, and snippets.

@vchimishuk
Created June 24, 2014 14: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 vchimishuk/2c324e2be71c23b7f4c7 to your computer and use it in GitHub Desktop.
Save vchimishuk/2c324e2be71c23b7f4c7 to your computer and use it in GitHub Desktop.
// Create index.
curl -XPUT 'http://localhost:9200/emotions/'
// Mappings.
curl -XPUT 'http://localhost:9200/emotions/emotion/_mapping' -d '{
"emotion" : {
"properties" : {
"name" : {"type" : "string", "index" : "not_analyzed" },
"count" : {"type" : "integer" },
"companyEmotions" : {
"type" : "nested",
"_parent": {
"type": "emotion"
},
"properties": {
"company" : {"type" : "string", "index" : "not_analyzed" },
"emotion" : { "type" : "integer" }
}
}
}
}
}'
// Create documents:
curl -XPUT 'http://localhost:9200/emotions/emotion/1' -d '{
name: "aaa",
count: 3,
companyEmotions: [{
emotion: 1,
company: "foo"
}, {
emotion: 2,
company: "bar"
}]
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/2' -d '{
name: "bbb",
count: 0,
companyEmotions: [{
emotion: 3,
company: "bar"
}, {
emotion: 1,
company: "foo"
}]
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/3' -d '{
name: "ccc",
count: 2,
companyEmotions: [{
emotion: 1,
company: "foo"
}]
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/4' -d '{
name: "ddd",
count: 1000,
companyEmotions: []
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/5' -d '{
name: "eee",
count: 10,
companyEmotions: [{
emotion: 2,
company: "foo"
}, {
emotion: 1,
company: "bar"
}]
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/6' -d '{
name: "fff",
count: 20,
companyEmotions: [{
emotion: 2,
company: "foo"
}, {
emotion: 1,
company: "bar"
}]
}'
curl -XPUT 'http://localhost:9200/emotions/emotion/7' -d '{
name: "ggg",
count: 3,
companyEmotions: [{
emotion: 1,
company: "bar"
}, {
emotion: 2,
company: "foo"
}]
}'
// Aggregation.
curl -XPOST "http://localhost:9200/emotions/emotion/_search?pretty=true" -d '{
"aggregations": {
"emotionAggr": {
"nested": {
"path": "companyEmotions"
},
"aggregations": {
"emotionAggr2": {
"filter": {
"term": {"companyEmotions.company": "foo"}
},
"aggregations": {
"emotionAggr3": {
"terms": {
"field": "companyEmotions.emotion"
},
"aggregations": {
"emotionAggr4": {
"sum": {"script": "doc[\"count\"].value"}
}
}
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment