Please find the steps I followed and the query.
PUT myindex
{
"mappings":{
"properties": {
"foo" : {"type": "keyword"}
}
}
}
PUT myindex/_doc/1
{
"foo" : "x"
}
PUT myindex/_doc/2
{
"foo" : "x"
}
PUT myindex/_doc/3
{
"foo" : "x"
}
GET myindex/_search
{
"size": 0,
"aggs": {
"foo_agg": {
"terms": {
"field": "foo",
"min_doc_count": 0
}
}
}
}
POST myindex/_update/1
{
"script" : "ctx._source.foo = 'y'"
}
POST myindex/_update/2
{
"script" : "ctx._source.foo = 'y'"
}
POST myindex/_update/3
{
"script" : "ctx._source.foo = 'x'"
}
GET myindex/_search
{
"size": 0,
"aggs": {
"foo_agg": {
"terms": {
"field": "foo",
"min_doc_count": 0
}
}
}
}
POST myindex/_update/3
{
"script" : "ctx._source.foo = 'y'"
}
GET myindex/_search
{
"size": 0,
"aggs": {
"foo_agg": {
"terms": {
"field": "foo",
"min_doc_count": 0
}
}
}
}
Please find the below out put in the same order of search agg query...
output 1:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"foo_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "x",
"doc_count": 3
}
]
}
}
Output 2:
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"foo_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "y",
"doc_count": 2
},
{
"key": "x",
"doc_count": 1
}
]
}
}
}
Output 3:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"foo_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "y",
"doc_count": 3
},
{
**"key": "x",**
**"doc_count": 0**
}
]
}
}
}