Return distinct tags

Hi guys,
I have document of following format:
_id :"1",
tags:["guava","apple","mango", "banana", "gulmohar"]

tags: ["orange","guava", "mango shakes", "apple pie", "grammar"]


tags: ["guava","apple","grapes", "water",
"grammar","gulmohar","water-melon", "green"]

Now, I wanted to show tags suggestion to user:
For example: Whenever user types, 'g':
"guava", "gulmohar", "grammar", "grapes" and "green" should be returned as
a result.
ie. the query should returns distinct tags with prefix g*.

Here is my mapping:
"tags": {
"type": "string",
"include_in_all": false,
"term_vector": "with_positions_offsets"
I tried everywhere, browse whole documentations, but I didn't find any
clue, much to my dismay.
I tried aggregation, but aggregation returns the distinct count for whole
words, not for word starting with 'g'.
"query": {
"filtered": {
"query": {
"bool": {
"should": [
"query_string": {
"allow_leading_wildcard": false,
"fields": [
"query": "Pizza*",
"filter": {
//some condition on other field...


"aggs": {
"distinct_tags": {
"terms": {
"field": "tags",
"size": 10

result of above: guava(3), apple(2), mango(1)

Can someone please suggest me the correct way to fetch all the distinct
tags with prefix input_prefix*?


You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit