- два образца документов
ПОСТ /aggstest/тест/1
{
"categories": [
{
"type": "book",
"words": [
{"word":"storm","count":277},
{"word":"pooh","count":229}
]
},
{
"type": "magazine",
"words": [
{"word":"vibe","count":100},
{"word":"sunny","count":50}
]
}
]
}
ПОСТ /aggstest/тест/2
{
"categories": [
{
"type": "book",
"words": [
{"word":"rain","count":160},
{"word":"jurassic park","count":150}
]
},
{
"type": "megazine",
"words": [
{"word":"tech","count":200},
{"word":"homes","count":30}
]
}
]
}
- аггс-запрос
ПОЛУЧИТЬ /aggstest/test/_search
{
"size": 0,
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"categories.type": "book"
}
},
{
"term": {
"categories.words.word": "storm"
}
}
]
}
}
}
},
"aggs": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"categories.type": "book"
}
}
]
}
},
"aggs": {
"book_category": {
"terms": {
"field": "categories.words.word",
"size": 10
}
}
}
}
},
"post_filter": {
"term": {
"categories.type": "book"
}
}
}
результат
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0, "hits": [] }, "aggregations": { "filtered": { "doc_count": 1, "book_category": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "pooh", "doc_count": 1 }, { "key": "storm", "doc_count": 1 }, { "key": "sunny", "doc_count": 1 }, { "key": "vibe", "doc_count": 1 } ] } } } }
========================
Ожидаемый набор результатов aggs не должен включать «солнечный» и «вибрационный», потому что это тип «журнала».
Я использовал запрос фильтра и post_filter, но я не мог получить только результат типа «книга».
"aggs" : { "agg_name" : { "terms" : " { "field" : "categories.words.words" } } }
- person Mave   schedule 08.05.2015