Get all unique values of a field across documents

so i have a field named subjects, it is an array. so I want to get all the values of subjects field in a particular index. should be about 300-400. Can someone suggest how to achieve this.

I am doing this:
GET /index/_search { "size": "0", "aggs":{ "by_subjects":{ "terms": { "field": "subjects.en.keyword" } } } }

but this is returning me only 10 items in a list.
also its giving me this in result if it helps:
"aggregations" : { "by_subjects" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 381,

Use the size parameter to ask for more. Given you have hundreds, not tens of thousands of values, these can all be returned from a single request (otherwise you'd need to use something like the composite aggregation to page through results).

hello,
making the size parameter to 400 (keeping rest same) gives me all the documents I have stored in the index.
my goal is to get all the values of the particular field.
Thanks

Sorry, I wasn't clear. I meant the size setting inside the terms aggregation.

I did try that before and just now as well. its still seems to give me same results, giving me all the documents in the index. Is there anything I am missing. this is my query .

`GET /index/_search 

{

"aggs":{
"by_subjects":{
"terms":{
"field": "subjects.en.keyword",
"size": "5"
}
}
}
}`

Console_-_Kibana

Thanks a lot. This solved the issue.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.