Displaying top 1000 results only in elastic search


(Subbu v) #1

i have a simple search query, where i am searching all the documents that falls in a data range. i have more than 50K results, with in which i want to display only top 1000 results based on date. this way my query can also be faster, as the user will also be interested to see only the 1000 results max at a time.

how can i archive this? please help.


(Joshua Rich) #2

Can you show us the query you currently have?


(Subbu v) #3

i am using the below query, and thought that it would return 1000 records (as i mentioned size:1000 in agg), but it returns all.

{
"query" : {
"bool" : {
"must" : {
"range" : {
"filetimestamp" : {
"from" : "2016-01-01T00:00:00.000-0800",
"to" : "2016-08-31T17:11:37.393-0700",
"include_lower" : true,
"include_upper" : true
}
}
}
}
},
"fields" : "filename",
"sort" : [ {
"filetimestamp" : {
"order" : "desc"
}
} ],
"aggregations" : {
"filenames" : {
"terms" : {
"field" : "filename",
"size" : 1000
}
}
}
}


(Isabel Drost-Fromm) #4

I believe you misread what size refers to here. According to

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

The size parameter can be set to define how many term buckets should be returned out of the overall terms list.

I think what might help you is using the following:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html

Hope this helps,
Isabel


(new to Es) #5
{ 
  "size":1000,
  "query" : {  
      "bool" : {     
          "must" : { 
                      ...

(Subbu v) #6

Hi,
thanks for the response. but i dont think this is helping. though i give 1000 in size, it is returning all the results in console.
thanks


(system) #7