As discussed in this thread, here is a feature request for terms facet : http://…elasticsearch-users.115913.n3.nabble.com/Terms-facet-getting-all-the-results-tp3051086p3055360.html
I would like to get within the terms facet result the count of all other terms that have not been returned (due to size limit).
Here is a test case :
``` bash
# Dropping index and Creating articles
curl -X DELETE "http://localhost:9200/articles"
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["one", "two", "three", "four", "five", "six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["two", "three", "four", "five", "six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["three", "four", "five", "six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["four", "five", "six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["five", "six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["six", "seven"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"tags" : ["seven"]}'
```
``` bash
# Classic search with terms facet
curl -X POST "http://localhost:9200/articles/_search?pretty=true" -d '
{
"query" : { "match_all" : { } },
"facets" : {
"f_tags" : { "terms" : {"field" : "tags"} }
}
}
'
```
``` javascript
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 7,
"max_score" : 1.0,
"hits" : [ {
"_index" : "articles",
"_type" : "article",
"_id" : "gkgAyLN6QWuxSyBLxxknIw",
"_score" : 1.0, "_source" : {"tags":["two","three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "swVlq23SS9aoC8uHNB_LRA",
"_score" : 1.0, "_source" : {"tags":["one","two","three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "oColEdY-SUmMPWvBWBEneQ",
"_score" : 1.0, "_source" : {"tags":["six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "hk-9osIlRViESqEF7WPj_w",
"_score" : 1.0, "_source" : {"tags":["three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "Ki9KA036TI6n7f6vD2gGWA",
"_score" : 1.0, "_source" : {"tags":["four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "_bFnruq4TdyJQjHH5bTMrg",
"_score" : 1.0, "_source" : {"tags":["five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "k1FzqoBwQ82PYNa1jgE-Tg",
"_score" : 1.0, "_source" : {"tags":["seven"]}
} ]
},
"facets" : {
"f_tags" : {
"_type" : "terms",
"missing" : 0,
"terms" : [ {
"term" : "seven",
"count" : 7
}, {
"term" : "six",
"count" : 6
}, {
"term" : "five",
"count" : 5
}, {
"term" : "four",
"count" : 4
}, {
"term" : "three",
"count" : 3
} ]
}
}
}
```
I would like to add an option to the term facet :
``` bash
# New option "other_terms" for terms facet
curl -X POST "http://localhost:9200/articles/_search?pretty=true" -d '
{
"query" : { "match_all" : { } },
"facets" : {
"f_tags" : { "terms" : {
"field" : "tags",
"other_terms" : true
} }
}
}
'
```
Which should return :
``` javascript
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 7,
"max_score" : 1.0,
"hits" : [ {
"_index" : "articles",
"_type" : "article",
"_id" : "gkgAyLN6QWuxSyBLxxknIw",
"_score" : 1.0, "_source" : {"tags":["two","three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "swVlq23SS9aoC8uHNB_LRA",
"_score" : 1.0, "_source" : {"tags":["one","two","three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "oColEdY-SUmMPWvBWBEneQ",
"_score" : 1.0, "_source" : {"tags":["six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "hk-9osIlRViESqEF7WPj_w",
"_score" : 1.0, "_source" : {"tags":["three","four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "Ki9KA036TI6n7f6vD2gGWA",
"_score" : 1.0, "_source" : {"tags":["four","five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "_bFnruq4TdyJQjHH5bTMrg",
"_score" : 1.0, "_source" : {"tags":["five","six","seven"]}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "k1FzqoBwQ82PYNa1jgE-Tg",
"_score" : 1.0, "_source" : {"tags":["seven"]}
} ]
},
"facets" : {
"f_tags" : {
"_type" : "terms",
"missing" : 0,
"terms" : [ {
"term" : "seven",
"count" : 7
}, {
"term" : "six",
"count" : 6
}, {
"term" : "five",
"count" : 5
}, {
"term" : "four",
"count" : 4
}, {
"term" : "three",
"count" : 3
}, {
"term" : "_other",
"count" : 3
} ]
}
}
}
```
As you can see, a new _other term field is returned with a count of 3 (2 terms "two" + 1 term "one").
Many thanks
Cheers
David.