Created
June 24, 2014 14:58
-
-
Save vchimishuk/2c324e2be71c23b7f4c7 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
// 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