# Context suggest display results for all the categories (mimic the completion suggester behavior)

**URL:** https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064
**Category:** Elasticsearch
**Created:** [August 4, 2014, 8:50am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064 "2014-08-04T08:50:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)
#### Post date: [August 4, 2014, 8:50am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/1 "2014-08-04T08:50:23Z")

</div>

Hi, Is there a way to tell the context suggester to display results for all  
the categories ?  
I know that for the category suggester query I must provide context/s  
Sort of:

{  
"suggest" : {  
"text" : "m",  
"completion" : {  
"field" : "suggest\_field",  
"size": 10,  
"context": {  
"color": "\*"  
}  
}  
}  
}

This should work like simple completion suggester no matter what "color"  
each document has.  
So I should be able to find suggestions, and filter them (by "color") only  
when needed.

--  
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/e6a44204-207e-42bc-8bf0-bc60e0869496%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e6a44204-207e-42bc-8bf0-bc60e0869496%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: [August 4, 2014, 9:21am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/2 "2014-08-04T09:21:18Z")

</div>

Hey,

you could simply index an 'all' color field value for every document, and  
then use that for your suggestions?

--Alex

On Mon, Aug 4, 2014 at 10:50 AM, Tihomir Lichev [shoteff@gmail.com](mailto:shoteff@gmail.com) wrote:

> Hi, Is there a way to tell the context suggester to display results for  
> all the categories ?  
> I know that for the category suggester query I must provide context/s  
> Sort of:
> 
> {  
> "suggest" : {  
> "text" : "m",  
> "completion" : {  
> "field" : "suggest\_field",  
> "size": 10,  
> "context": {  
> "color": "\*"  
> }  
> }  
> }  
> }
> 
> This should work like simple completion suggester no matter what "color"  
> each document has.  
> So I should be able to find suggestions, and filter them (by "color") only  
> when needed.
> 
> --  
> 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/e6a44204-207e-42bc-8bf0-bc60e0869496%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e6a44204-207e-42bc-8bf0-bc60e0869496%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/e6a44204-207e-42bc-8bf0-bc60e0869496%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e6a44204-207e-42bc-8bf0-bc60e0869496%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/CAGCwEM8\_q\_k\_CBgmq7C0ir2A1KfZMA%2BiNYGYrieV\_aL4\_JgW-w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8_q_k_CBgmq7C0ir2A1KfZMA%2BiNYGYrieV_aL4_JgW-w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)
#### Post date: [August 5, 2014, 8:13am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/3 "2014-08-05T08:13:46Z")

</div>

Thank you Alex,  
I also came up with that idea, but I think it is not that useful when you  
have context, mapped to a field, which usually contains a single value,  
especially numeric fields (despite that  
[https://github.com/elasticsearch/elasticsearch/issues/6512](https://github.com/elasticsearch/elasticsearch/issues/6512) is not fixed yet)

--  
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/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%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: [August 5, 2014, 8:41am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/4 "2014-08-05T08:41:17Z")

</div>

Hey,

maybe the new transform feature could help here to create a default value  
(just an idea, havent tested it). See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Tue, Aug 5, 2014 at 10:13 AM, Tihomir Lichev [shoteff@gmail.com](mailto:shoteff@gmail.com) wrote:

> Thank you Alex,  
> I also came up with that idea, but I think it is not that useful when you  
> have context, mapped to a field, which usually contains a single value,  
> especially numeric fields (despite that  
> [Context Suggester: Context does not work with non strings in mapping · Issue #6512 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/6512) is not fixed  
> yet)
> 
> --  
> 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/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%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/CAGCwEM9b7Nw-PhVV8WoVq2prx0-egCR94er2SMm%2B3xRM0PLVYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9b7Nw-PhVV8WoVq2prx0-egCR94er2SMm%2B3xRM0PLVYw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)
#### Post date: [August 7, 2014, 9:27am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/5 "2014-08-07T09:27:50Z")

</div>

Thanks Alex,  
I made it 🙂  
I'm using transformation script to add "\*" to any of the context fields.  
But I definitely think that issues:

> <https://github.com/elastic/elasticsearch/issues/6444>
>
> running the example given in the documentation is throwing an error:
> 
> {
> "\_sha…rds": {
> "total": 5,
> "successful": 4,
> "failed": 1,
> "failures": \[
> {
> "index": "services",
> "shard": 2,
> "reason": "BroadcastShardOperationFailedException\[\[services\]\[2\] \]; nested: ElasticsearchException\[failed to execute suggest\]; nested: NullPointerException; "
> }
> \]
> }
> }
> 
> here's the code example given:
> 
> PUT /services
> 
> PUT /services/service/\_mapping
> {
> "service": {
> "properties": {
> "name": {
> "type" : "string"
> },
> "tag": {
> "type" : "string"
> },
> "suggest\_field": {
> "type": "completion",
> "context": {
> "color": { 
> "type": "category",
> "path": "color\_field",
> "default": \["red", "green", "blue"\]
> },
> "location": { 
> "type": "geo",
> "precision": "5m",
> "neighbors": true,
> "default": "u33"
> }
> }
> }
> }
> }
> }
> 
> PUT services/service/1
> {
> "name": "knapsack",
> "suggest\_field": {
> "input": \["knacksack", "backpack", "daypack"\],
> "context": {
> "color": \["red", "yellow"\]
> }
> }
> }
> 
> POST services/\_suggest?pretty'
> {
> "suggest" : {
> "text" : "m",
> "completion" : {
> "field" : "suggest\_field",
> "size": 10,
> "context": {
> "color": "red"
> }
> }
> }
> }

> <https://github.com/elastic/elasticsearch/issues/6512>
>
> Hey,
> 
> the context suggester only works with strings in the mapping if you specif…y a field, see this example
> 
> \`\`\`
> DELETE /services
> PUT /services
> PUT /services/service/\_mapping
> {
> "service": {
> "properties": {
> "network\_id": {
> "type" : "long"
> },
> "suggest\_field": {
> "type": "completion",
> "context": {
> "network": { 
> "type": "category",
> "path": "network\_id"
> }
> }
> },
> "suggest\_field2": {
> "type": "completion",
> "context": {
> "network": { 
> "type": "category"
> }
> }
> }
> }
> }
> }
> 
> PUT /services/service/1
> {
> "name": "knapsack",
> "network\_id": "1",
> "suggest\_field": {
> "input": \["knacksack", "backpack", "daypack"\]
> },
> "suggest\_field2": {
> "input": \["knacksack", "backpack", "daypack"\],
> "context" : {
> "network" : "1"
> }
> }
> }
> 
> POST services/\_suggest?pretty'
> {
> "suggest" : {
> "text" : "k",
> "completion" : {
> "field" : "suggest\_field",
> "size": 10,
> "context": {
> "network": "1"
> }
> }
> },
> "suggest2" : {
> "text" : "k",
> "completion" : {
> "field" : "suggest\_field2",
> "size": 10,
> "context": {
> "network": "1"
> }
> }
> }
> }
> \`\`\`
> 
> Solution 1: Call \`toString()\` for everything
> Solution 2: Reject contexts for anything else than strings

have to be fixed  
Probably also provide some way to select any value also for non-string  
fields (if issue 6512 end up as toString conversion)

05 август 2014, вторник, 11:41:33 UTC+3, Alexander Reelsen написа:

> Hey,
> 
> maybe the new transform feature could help here to create a default value  
> (just an idea, havent tested it). See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-transform.html#mapping-transform)
> 
> --Alex
> 
> On Tue, Aug 5, 2014 at 10:13 AM, Tihomir Lichev \<[sho...@gmail.com](mailto:sho...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Thank you Alex,  
> > I also came up with that idea, but I think it is not that useful when you  
> > have context, mapped to a field, which usually contains a single value,  
> > especially numeric fields (despite that  
> > [Context Suggester: Context does not work with non strings in mapping · Issue #6512 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/6512) is not fixed  
> > yet)
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/6ca0e8df-b21a-4f3a-afa5-0b57c91c03c1%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/5ae47c01-0bc6-465b-a58d-70a4fc2de0fa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ae47c01-0bc6-465b-a58d-70a4fc2de0fa%40googlegroups.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:10am UTC](https://discuss.elastic.co/t/context-suggest-display-results-for-all-the-categories-mimic-the-completion-suggester-behavior/19064/6 "2017-07-06T01:10:14Z")

</div>


