Get list with all users name?


(Sergey) #1

Hi!!!
I have many documents with field "user-name".
I want to see list with all user names in it.


(Magnus Bäck) #2

This probably answers your question:


(Sergey) #3

@magnusbaeck
Well i create a aggs
"size": 0,
"aggs" : {
"user-ids" : {
"terms" : { "field" : "user-id" }
}
}
But it returns me only 12 id's. How can i increase numbers of id's in my response? (i have it apx. 7000) And i want to see all of them.
The respond looks like this:
"aggregations": {
"user-ids": {
"doc_count_error_upper_bound": 137,
"sum_other_doc_count": 97335,
"buckets": [
{
"key": 572773,
"doc_count": 646
},
{
"key": 665035,
"doc_count": 533
},
{
"key": 672046,
"doc_count": 425
},
{
"key": 672870,
"doc_count": 403
},
{
"key": 192596,
"doc_count": 364
},
{
"key": 588616,
"doc_count": 361
},
{
"key": 401020,
"doc_count": 348
},
{
"key": 664634,
"doc_count": 347
},
{
"key": 673037,
"doc_count": 340
},
{
"key": 669806,
"doc_count": 334
}
]
}
}


(Sergey) #4

Sorry not 12 but 10


(Sergey) #5

I mean I want to see all buckets not only 10.


(Colin Goodheart-Smithe) #6

this should help you: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_size

Note that it is not a good idea to set size to 0 as this can lead to memory issues. If you are expecting approx 7000 values I would set size to 10000.

Note that this size parameter is inside the terms aggregation and is not the same as the size parameter you already have in your request.


(Sergey) #7

@colings86
Well, there is no any solution like _all in size?


(Magnus Bäck) #8

If you want the user-name field of all documents (i.e. no aggregation at all) try this:

POST /name-of-your-index/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "exists": {
          "field": "user-name"
        }
      }
    }
  },
  "fields": ["user-name"],
  "size": 10000
}

(If you don't have an reasonable accurate upper bound on the number of documents to return, have a look at the scan and scroll API.


(Sergey) #9

@magnusbaeck
Sorry I can't find answer.
I have request
POST /name-index/_search
{
"filter": {
"term": {
"event_type": "03_finish_tutorial_battle1"
}
}
}
and i want to see all my 1235 document in response (something like "size": "_all"). Is it possible?


(Magnus Bäck) #10

To get all documents, set size to zero. Or what's the problem?


(system) #11