Completion's size and total results


(Daniele Orler) #1

Elastic Search allows to set a size in completion suggest.
Is there a way to get the total number of options the query would return before applying the size limit?

Example:

request:

{
   text: "John",
   completion: {
       size: 3,
       field: "suggestion"
   }
}

actual result:

{
  "text": "John",
  "offset": 0,
  "length": 4,
  "options": [
	{
	  "text": "John Doe",
	  "score": 1,
	  "payload": { "id" : 1 }
	},
	{
	  "text": "John Doe Jr.",
	  "score": 1,
	  "payload": { "id" : 2 }
	},
	{
	  "text": "John Doe III",
	  "score": 1,
	  "payload": { "id" : 3 }
	},
  ]
}

result I'd like:

{
  "text": "John",
  "offset": 0,
  "length": 4,
  "total": 32,  //means that "John" would produce 32 results but since size=3 only 3 are listed
  "options": [
	{
	  "text": "John Doe",
	  "score": 1,
	  "payload": { "id" : 1 }
	},
	{
	  "text": "John Doe Jr.",
	  "score": 1,
	  "payload": { "id" : 2 }
	},
	{
	  "text": "John Doe III",
	  "score": 1,
	  "payload": { "id" : 3 }
	},
  ]
}

(system) #2