# Suggestion completion across multiple types in an index

**URL:** <https://discuss.elastic.co/t/suggestion-completion-across-multiple-types-in-an-index/15602>\
**Category:** Elasticsearch\
**Created:** [February 4, 2014, 10:11pm UTC](https://discuss.elastic.co/t/suggestion-completion-across-multiple-types-in-an-index/15602 "2014-02-04T22:11:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avinash\_Mohan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avinash_mohan/32/1826_2.png) [@Avinash\_Mohan](https://discuss.elastic.co/u/Avinash_Mohan)\
**Post date:** [February 4, 2014, 10:11pm UTC](https://discuss.elastic.co/t/suggestion-completion-across-multiple-types-in-an-index/15602/1 "2014-02-04T22:11:08Z")

</div>

Hi,

Is it possible to do a suggestion completion on a type. im able to do it on  
an index .

POST /data/\_suggest  
{  
"data" : {  
"text" : "tr",  
"completion" : {  
"field" : "sattributes",  
"size":50  
}  
}  
}

when i do on a type

POST /data/suggestion/\_suggest  
{  
"data" : {  
"text" : "tr",  
"completion" : {  
"field" : "sattributes",  
"size":50  
}  
}  
}

"suggestion" is the type

i don't get any results. I need to do suggestion on two different types  
articles and books. Do i need to create separate indexes to make them work  
or is there a way in elasticsearch to accomplish this. In case if i have to  
search on my index "data" is there way to get 50 results for type "article"  
and 50 results for type "book".

Any help is highly appreciated.

- Avinash

--  
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/9b68f9f2-e566-414c-908c-4403ce0a2bcb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b68f9f2-e566-414c-908c-4403ce0a2bcb%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 6, 2014, 10:19am UTC](https://discuss.elastic.co/t/suggestion-completion-across-multiple-types-in-an-index/15602/2 "2014-02-06T10:19:33Z")

</div>

Hey,

right now the completion suggester only works per index, but not per type.  
There is some work going on to add a context around a suggester, which  
would allow for cases like that, see

> <https://github.com/elastic/elasticsearch/pull/4044>
>
> This commit extends the \`CompletionSuggester\` by context
> informations. In exampl…e such a context informations can
> be a simple string representing a category reducing the
> suggestions in order to this category.
> 
> Three base implementations of these context informations
> have been setup in this commit.
> \- a Category Context
> \- a Geo Context
> \- a Field Context
> 
> All the mapping for these context informations are
> specified within a context field in the completion
> field that should use this kind of information.
> \## Mapping Example
> 
> The following example shows the mapping for a GeoContext.
> 
> \`\`\`
> {
> "testType":{
> "properties":{
> "testField":{
> "type":"completion",
> "index\_analyzer":"simple",
> "search\_analyzer":"simple",
> "payloads":true,
> "preserve\_separators":false,
> "preserve\_position\_increments":true,
> "context":{
> "geo":{
> "separator":"|",
> "precision":8,
> "neighbors":true
> }
> }
> }
> }
> }
> }
> \`\`\`
> \## Indexing
> 
> During indexing a document the subfield \`context\` of the
> completion field contains the data to be used in order
> to provide suggestions.
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":"u33dc1v0xupz"
> }
> }
> \`\`\`
> \## Suggestion Example
> 
> The Suggestion request is extended by a context value. The
> suggest request for a geolocation looks like
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context":{
> "geo":"u33dc0cpke4q"
> }
> }
> }
> }
> \`\`\`
> 
> The context objects contains a field with the same name as
> defined in the mapping. According to the type of the context
> this field contains the data associated with the suggestion
> request. In this example the geohash of a location.
> \## Category Context
> 
> The simplest way to use this feature is a category context. It
> supports a arbitrary name of a category to use with the completion
> suggest API.
> 
> To set the context support to the category type this option must be
> set to \`true\`:
> 
> \`\`\`
> "testField":{
> "type":"completion",
> "context":{
> "category": true
> }
> }
> \`\`\`
> 
> The name of the context category then needs to be set within the
> suggestion context during indexing:
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":"delivery"
> }
> }
> \`\`\`
> 
> and can be used by setting the category value:
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context":{
> "category":"delivery"
> }
> }
> }
> }
> \`\`\`
> \## Field Context
> 
> The Field Context works like the category context but the value of this
> will context will not explicitly be set. It refers to another field in
> the document. In example a \`category\` field.
> 
> \`\`\`
> {
> "category":{
> "type": "string"
> },
> "testField":{
> "type":"completion",
> "context":{
> "field": "category"
> }
> }
> }
> \`\`\`
> 
> for indexing the field context must be set to true:
> 
> \`\`\`
> {
> "category":"delivery",
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context":true
> }
> }
> \`\`\`
> 
> and suggestions use the \`context.field\` value
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context": {
> "field": "delivery"
> }
> }
> }
> }
> \`\`\`
> \## Geo Context
> 
> The last context feature is the GeoContext. It take a location into account.
> For example if one searches for delivery services it might be use full to find
> results around the location the query was sent. This context internally works
> on geohashes only but the REST API allows any form defined for \`geo\_points\`
> 
> In the mapping this kind of context is configured by two parameters:
> \- precision
> \- neighbors
> 
> The \`precision\` option is used to configure the range of result. If the
> \`neighbors\` option is enabled not only the given geohash cell will be used
> but also all it's neighbors. 
> 
> \`\`\`
> "context":{
> "geo":{
> "separator":"|",
> "precision":8,
> "neighbors":true
> }
> }
> \`\`\`
> 
> The context during indexing is set to the location of the input:
> 
> \`\`\`
> {
> "testField":{
> "input":\[\["pizza - berlin","pizza","food"\]\],
> "context": "u33dc1v0xupz"
> }
> }
> \`\`\`
> 
> To get a ist of suggestions around a specific area the \`context.geo\` field
> must contain the position of this area:
> 
> \`\`\`
> {
> "suggest":{
> "text":"pizza",
> "completion":{
> "field":"testField",
> "size":10,
> "context": {
> "geo": "u33dc0cpke4q"
> }
> }
> }
> }
> \`\`\`
> 
> Closes #3959

hope this helps.

--Alex

On Tue, Feb 4, 2014 at 11:11 PM, Avinash Mohan [avilanchee@gmail.com](mailto:avilanchee@gmail.com) wrote:

> Hi,
> 
> Is it possible to do a suggestion completion on a type. im able to do it  
> on an index .
> 
> POST /data/\_suggest  
> {  
> "data" : {  
> "text" : "tr",  
> "completion" : {  
> "field" : "sattributes",  
> "size":50  
> }  
> }  
> }
> 
> when i do on a type
> 
> POST /data/suggestion/\_suggest  
> {  
> "data" : {  
> "text" : "tr",  
> "completion" : {  
> "field" : "sattributes",  
> "size":50  
> }  
> }  
> }
> 
> "suggestion" is the type
> 
> i don't get any results. I need to do suggestion on two different types  
> articles and books. Do i need to create separate indexes to make them work  
> or is there a way in elasticsearch to accomplish this. In case if i have to  
> search on my index "data" is there way to get 50 results for type "article"  
> and 50 results for type "book".
> 
> Any help is highly appreciated.
> 
> - Avinash
> 
> --  
> 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/9b68f9f2-e566-414c-908c-4403ce0a2bcb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b68f9f2-e566-414c-908c-4403ce0a2bcb%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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-rvbBoB7srYBbP9ktp0We2tSu36%2BA%2BmwtCDv\_9z4fyEA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-rvbBoB7srYBbP9ktp0We2tSu36%2BA%2BmwtCDv_9z4fyEA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:52am UTC](https://discuss.elastic.co/t/suggestion-completion-across-multiple-types-in-an-index/15602/3 "2017-07-06T01:52:04Z")

</div>


