# Automatically build \`input\` for \`completion\` fields?

**URL:** <https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763>\
**Category:** Elasticsearch\
**Created:** [April 2, 2014, 8:26am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763 "2014-04-02T08:26:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sviatoslav\_Abakumov](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Sviatoslav\_Abakumov](https://discuss.elastic.co/u/Sviatoslav_Abakumov)\
**Post date:** [April 2, 2014, 8:26am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763/1 "2014-04-02T08:26:38Z")

</div>

Hello,

I have an index `facebook` with type `post`. I need to provide users with  
autocompletions using terms that appear in `post.message`. Also the list of  
completions should be sorted by score.

The mapping is as follows:  
{  
"post": {  
"properties": {  
"created\_time": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"link": {  
"type": "string"  
},  
"message": {  
"type": "string"  
},  
"object\_id": {  
"type": "string"  
},  
"picture": {  
"type": "string"  
},  
"shares\_count": {  
"type": "long"  
},  
"type": {  
"type": "string"  
},  
"update\_time": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"user": {  
"type": "long"  
}  
}  
}  
}

An example document:  
{  
"picture": "...",  
"update\_time": "2014-03-19T23:16:59",  
"message": "The  
day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
pie has been served!! Check to see if you're our first winner!",  
"object\_id": "",  
"shares\_count": 0,  
"link": "...",  
"user": ...,  
"created\_time": "2014-03-17T21:02:32",  
"type": "link"  
}

To achieve the goal I've added one more field to the mapping:  
"message\_suggest": {  
"type": "completion"  
}

Every time I write a document, I query ES to tokenize the string `message`:  
POST \_analyze?\_tokenizer=standard  
The day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
pie has been served!! Check to see if you're our first winner!

Then I get the list of tokens from the response and add it to  
`post.message_suggest.input`.

When I do the following request, I get what I wanted:  
POST facebook/\_suggest  
{  
"messages": {  
"text": "pi",  
"completion": {  
"field": "message\_suggest"  
}  
}  
}

I sense that this approach is not right or at least not optimal. I am new  
to Elasticsearch and I would appreciate any input.

Best,  
Sviatoslav.

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 7, 2014, 7:20am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763/2 "2014-04-07T07:20:36Z")

</div>

Hey,

there is no automation for this. The main reason why your solution might  
work in your specific use-case is, that you do not have billions of  
documents. Otherwise there would be a lot of documents, which contain for  
example piece (pi suggestions) or winner (wi), and you would get a lot of  
results. However the goal of a good suggestions is not to get a lot of  
results but few very good ones, which are likely to be chosen by the user  
for further queries. Just adding arbitrary suggestions without  
scoring/weighting them does not make help the user a lot from my experience.

Hope it makes sense..

--Alex

On Wed, Apr 2, 2014 at 10:26 AM, Sviatoslav Abakumov \<  
[abakumov.sviatoslav@progforce.com](mailto:abakumov.sviatoslav@progforce.com)\> wrote:

> Hello,
> 
> I have an index `facebook` with type `post`. I need to provide users with  
> autocompletions using terms that appear in `post.message`. Also the list of  
> completions should be sorted by score.
> 
> The mapping is as follows:  
> {  
> "post": {  
> "properties": {  
> "created\_time": {  
> "type": "date",  
> "format": "dateOptionalTime"  
> },  
> "link": {  
> "type": "string"  
> },  
> "message": {  
> "type": "string"  
> },  
> "object\_id": {  
> "type": "string"  
> },  
> "picture": {  
> "type": "string"  
> },  
> "shares\_count": {  
> "type": "long"  
> },  
> "type": {  
> "type": "string"  
> },  
> "update\_time": {  
> "type": "date",  
> "format": "dateOptionalTime"  
> },  
> "user": {  
> "type": "long"  
> }  
> }  
> }  
> }
> 
> An example document:  
> {  
> "picture": "...",  
> "update\_time": "2014-03-19T23:16:59",  
> "message": "The  
> day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
> pie has been served!! Check to see if you're our first winner!",  
> "object\_id": "",  
> "shares\_count": 0,  
> "link": "...",  
> "user": ...,  
> "created\_time": "2014-03-17T21:02:32",  
> "type": "link"  
> }
> 
> To achieve the goal I've added one more field to the mapping:  
> "message\_suggest": {  
> "type": "completion"  
> }
> 
> Every time I write a document, I query ES to tokenize the string `message`:  
> POST \_analyze?\_tokenizer=standard  
> The day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
> pie has been served!! Check to see if you're our first winner!
> 
> Then I get the list of tokens from the response and add it to  
> `post.message_suggest.input`.
> 
> When I do the following request, I get what I wanted:  
> POST facebook/\_suggest  
> {  
> "messages": {  
> "text": "pi",  
> "completion": {  
> "field": "message\_suggest"  
> }  
> }  
> }
> 
> I sense that this approach is not right or at least not optimal. I am new  
> to Elasticsearch and I would appreciate any input.
> 
> Best,  
> Sviatoslav.
> 
> --  
> 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Sviatoslav\_Abakumov](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Sviatoslav\_Abakumov](https://discuss.elastic.co/u/Sviatoslav_Abakumov)\
**Post date:** [April 23, 2014, 6:52am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763/3 "2014-04-23T06:52:29Z")

</div>

What about fields `index_analyzer` and `search_analyzer`? I had hope  
that `index_analyzer` would split string `message_suggest.input` into  
array, but it doesn't seem to do it. What are they for then?

On Mon, Apr 7, 2014 at 11:20 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> there is no automation for this. The main reason why your solution might  
> work in your specific use-case is, that you do not have billions of  
> documents. Otherwise there would be a lot of documents, which contain for  
> example piece (pi suggestions) or winner (wi), and you would get a lot of  
> results. However the goal of a good suggestions is not to get a lot of  
> results but few very good ones, which are likely to be chosen by the user  
> for further queries. Just adding arbitrary suggestions without  
> scoring/weighting them does not make help the user a lot from my experience.
> 
> Hope it makes sense..
> 
> --Alex
> 
> On Wed, Apr 2, 2014 at 10:26 AM, Sviatoslav Abakumov  
> [abakumov.sviatoslav@progforce.com](mailto:abakumov.sviatoslav@progforce.com) wrote:
> 
> > Hello,
> > 
> > I have an index `facebook` with type `post`. I need to provide users with  
> > autocompletions using terms that appear in `post.message`. Also the list of  
> > completions should be sorted by score.
> > 
> > The mapping is as follows:  
> > {  
> > "post": {  
> > "properties": {  
> > "created\_time": {  
> > "type": "date",  
> > "format": "dateOptionalTime"  
> > },  
> > "link": {  
> > "type": "string"  
> > },  
> > "message": {  
> > "type": "string"  
> > },  
> > "object\_id": {  
> > "type": "string"  
> > },  
> > "picture": {  
> > "type": "string"  
> > },  
> > "shares\_count": {  
> > "type": "long"  
> > },  
> > "type": {  
> > "type": "string"  
> > },  
> > "update\_time": {  
> > "type": "date",  
> > "format": "dateOptionalTime"  
> > },  
> > "user": {  
> > "type": "long"  
> > }  
> > }  
> > }  
> > }
> > 
> > An example document:  
> > {  
> > "picture": "...",  
> > "update\_time": "2014-03-19T23:16:59",  
> > "message": "The  
> > day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
> > pie has been served!! Check to see if you're our first winner!",  
> > "object\_id": "",  
> > "shares\_count": 0,  
> > "link": "...",  
> > "user": ...,  
> > "created\_time": "2014-03-17T21:02:32",  
> > "type": "link"  
> > }
> > 
> > To achieve the goal I've added one more field to the mapping:  
> > "message\_suggest": {  
> > "type": "completion"  
> > }
> > 
> > Every time I write a document, I query ES to tokenize the string  
> > `message`:  
> > POST \_analyze?\_tokenizer=standard  
> > The day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
> > pie has been served!! Check to see if you're our first winner!
> > 
> > Then I get the list of tokens from the response and add it to  
> > `post.message_suggest.input`.
> > 
> > When I do the following request, I get what I wanted:  
> > POST facebook/\_suggest  
> > {  
> > "messages": {  
> > "text": "pi",  
> > "completion": {  
> > "field": "message\_suggest"  
> > }  
> > }  
> > }
> > 
> > I sense that this approach is not right or at least not optimal. I am new  
> > to Elasticsearch and I would appreciate any input.
> > 
> > Best,  
> > Sviatoslav.
> > 
> > --  
> > 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> > 
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/MV2369vLp0g/unsubscribe](https://groups.google.com/d/topic/elasticsearch/MV2369vLp0g/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com).
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKmtHP\_m4AAeT0r-7ujeJ5RjSSY%3DEdSw-VUufSVD7zgPS2hHKA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKmtHP_m4AAeT0r-7ujeJ5RjSSY%3DEdSw-VUufSVD7zgPS2hHKA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 26, 2014, 12:11am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763/4 "2014-04-26T00:11:40Z")

</div>

Hey,

it is exactly the same functionality index/search analyzers serve when  
indexing/querying any other fields.. It defines the analysis process chain  
(consisting of tokenizer, token filters and optionally char filters), when  
a field is either indexed or queried, to make sure the terms are in the  
same format. No special handling for the completion suggester here.

--Alex

On Wed, Apr 23, 2014 at 2:52 AM, Sviatoslav Abakumov \<  
[abakumov.sviatoslav@progforce.com](mailto:abakumov.sviatoslav@progforce.com)\> wrote:

> What about fields `index_analyzer` and `search_analyzer`? I had hope  
> that `index_analyzer` would split string `message_suggest.input` into  
> array, but it doesn't seem to do it. What are they for then?
> 
> On Mon, Apr 7, 2014 at 11:20 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de)  
> wrote:
> 
> > Hey,
> > 
> > there is no automation for this. The main reason why your solution might  
> > work in your specific use-case is, that you do not have billions of  
> > documents. Otherwise there would be a lot of documents, which contain for  
> > example piece (pi suggestions) or winner (wi), and you would get a lot of  
> > results. However the goal of a good suggestions is not to get a lot of  
> > results but few very good ones, which are likely to be chosen by the user  
> > for further queries. Just adding arbitrary suggestions without  
> > scoring/weighting them does not make help the user a lot from my  
> > experience.
> > 
> > Hope it makes sense..
> > 
> > --Alex
> > 
> > On Wed, Apr 2, 2014 at 10:26 AM, Sviatoslav Abakumov  
> > [abakumov.sviatoslav@progforce.com](mailto:abakumov.sviatoslav@progforce.com) wrote:
> > 
> > > Hello,
> > > 
> > > I have an index `facebook` with type `post`. I need to provide users  
> > > with  
> > > autocompletions using terms that appear in `post.message`. Also the  
> > > list of  
> > > completions should be sorted by score.
> > > 
> > > The mapping is as follows:  
> > > {  
> > > "post": {  
> > > "properties": {  
> > > "created\_time": {  
> > > "type": "date",  
> > > "format": "dateOptionalTime"  
> > > },  
> > > "link": {  
> > > "type": "string"  
> > > },  
> > > "message": {  
> > > "type": "string"  
> > > },  
> > > "object\_id": {  
> > > "type": "string"  
> > > },  
> > > "picture": {  
> > > "type": "string"  
> > > },  
> > > "shares\_count": {  
> > > "type": "long"  
> > > },  
> > > "type": {  
> > > "type": "string"  
> > > },  
> > > "update\_time": {  
> > > "type": "date",  
> > > "format": "dateOptionalTime"  
> > > },  
> > > "user": {  
> > > "type": "long"  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > An example document:  
> > > {  
> > > "picture": "...",  
> > > "update\_time": "2014-03-19T23:16:59",  
> > > "message": "The  
> > > day has finally arrived - the first piece of the 1,000,000 Swag Bucks  
> > > pie has been served!! Check to see if you're our first winner!",  
> > > "object\_id": "",  
> > > "shares\_count": 0,  
> > > "link": "...",  
> > > "user": ...,  
> > > "created\_time": "2014-03-17T21:02:32",  
> > > "type": "link"  
> > > }
> > > 
> > > To achieve the goal I've added one more field to the mapping:  
> > > "message\_suggest": {  
> > > "type": "completion"  
> > > }
> > > 
> > > Every time I write a document, I query ES to tokenize the string  
> > > `message`:  
> > > POST \_analyze?\_tokenizer=standard  
> > > The day has finally arrived - the first piece of the 1,000,000 Swag  
> > > Bucks  
> > > pie has been served!! Check to see if you're our first winner!
> > > 
> > > Then I get the list of tokens from the response and add it to  
> > > `post.message_suggest.input`.
> > > 
> > > When I do the following request, I get what I wanted:  
> > > POST facebook/\_suggest  
> > > {  
> > > "messages": {  
> > > "text": "pi",  
> > > "completion": {  
> > > "field": "message\_suggest"  
> > > }  
> > > }  
> > > }
> > > 
> > > I sense that this approach is not right or at least not optimal. I am  
> > > new  
> > > to Elasticsearch and I would appreciate any input.
> > > 
> > > Best,  
> > > Sviatoslav.
> > > 
> > > --  
> > > 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> > > 
> > > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com)  
> .
> 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/MV2369vLp0g/unsubscribe](https://groups.google.com/d/topic/elasticsearch/MV2369vLp0g/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9muU19N2jprvPMuGd8ZVzaDTLTC4koFmwqPHuNziyT7A%40mail.gmail.com)  
> .
> 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAKmtHP\_m4AAeT0r-7ujeJ5RjSSY%3DEdSw-VUufSVD7zgPS2hHKA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKmtHP_m4AAeT0r-7ujeJ5RjSSY%3DEdSw-VUufSVD7zgPS2hHKA%40mail.gmail.com)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_zPSfY5zTaa9iFLwuhv45a4TedwA1bqt8aga3XsRNNRQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_zPSfY5zTaa9iFLwuhv45a4TedwA1bqt8aga3XsRNNRQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:33am UTC](https://discuss.elastic.co/t/automatically-build-input-for-completion-fields/16763/5 "2017-07-06T01:33:24Z")

</div>


