# Bug in context suggester?

**URL:** <https://discuss.elastic.co/t/bug-in-context-suggester/17965>\
**Category:** Elasticsearch\
**Created:** [June 6, 2014, 6:41pm UTC](https://discuss.elastic.co/t/bug-in-context-suggester/17965 "2014-06-06T18:41:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gchang10](https://avatars.discourse-cdn.com/v4/letter/g/7feea3/32.png) [@Gchang10](https://discuss.elastic.co/u/Gchang10)\
**Post date:** [June 6, 2014, 6:41pm UTC](https://discuss.elastic.co/t/bug-in-context-suggester/17965/1 "2014-06-06T18:41:53Z")

</div>

I am observing an issue with field reference in context suggester. Consider  
the following use case:

PUT /services/service/\_mapping  
{  
"service": {  
"properties": {  
"name": {  
"type" : "string"  
},  
"network\_id": {  
"type" : "long"  
},  
"suggest\_field": {  
"type": "completion",  
"context": {  
"network": {  
"type": "category",  
"path": "network\_id"  
}  
}  
}  
}  
}  
}

PUT /services/service/1  
{  
"name": "knapsack",  
"network\_id": 1,  
"suggest\_field": {  
"input": ["knacksack", "backpack", "daypack"]  
}  
}

POST services/\_suggest?pretty'  
{  
"suggest" : {  
"text" : "k",  
"completion" : {  
"field" : "suggest\_field",  
"size": 10,  
"context": {  
"network": 1  
}  
}  
}  
}

The suggest query does not return any option. However, if I change the  
field type of network\_id to 'string' (and not\_analyzed), the suggest query  
works. Explicitly indexing the network\_id as the context in the  
suggest\_field works as well:

PUT /services/service/1  
{  
"name": "knapsack",  
"network\_id": 1,  
"suggest\_field": {  
"input": ["knacksack", "backpack", "daypack"],  
"context": {"network\_id": 1}  
}  
}

Seems like a bug?

--  
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/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%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:** [June 16, 2014, 1:02pm UTC](https://discuss.elastic.co/t/bug-in-context-suggester/17965/2 "2014-06-16T13:02:27Z")

</div>

Hey,

the problem is, that the mapping of the context variable 'network\_id' is  
not a string. Thinking if we either should support this or reject it  
directly and only support string fields in the suggester.

Added github issue

> <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

--Alex

On Fri, Jun 6, 2014 at 8:41 PM, Gilbert Chang [gilbertchang10@gmail.com](mailto:gilbertchang10@gmail.com)  
wrote:

> I am observing an issue with field reference in context suggester.  
> Consider the following use case:
> 
> PUT /services/service/\_mapping  
> {  
> "service": {  
> "properties": {  
> "name": {  
> "type" : "string"  
> },  
> "network\_id": {  
> "type" : "long"  
> },  
> "suggest\_field": {  
> "type": "completion",  
> "context": {  
> "network": {  
> "type": "category",  
> "path": "network\_id"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> PUT /services/service/1  
> {  
> "name": "knapsack",  
> "network\_id": 1,  
> "suggest\_field": {  
> "input": ["knacksack", "backpack", "daypack"]  
> }  
> }
> 
> POST services/\_suggest?pretty'  
> {  
> "suggest" : {  
> "text" : "k",  
> "completion" : {  
> "field" : "suggest\_field",  
> "size": 10,  
> "context": {  
> "network": 1  
> }  
> }  
> }  
> }
> 
> The suggest query does not return any option. However, if I change the  
> field type of network\_id to 'string' (and not\_analyzed), the suggest query  
> works. Explicitly indexing the network\_id as the context in the  
> suggest\_field works as well:
> 
> PUT /services/service/1  
> {  
> "name": "knapsack",  
> "network\_id": 1,  
> "suggest\_field": {  
> "input": ["knacksack", "backpack", "daypack"],  
> "context": {"network\_id": 1}  
> }  
> }
> 
> Seems like a bug?
> 
> --  
> 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/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/214f059d-e2e6-4a28-aaaf-7dc6c1e1bcad%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/CAGCwEM-oAgFRo8sRkNCD2X4jo6ZUdevPHmyHS1nzd7JTeK0mgA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-oAgFRo8sRkNCD2X4jo6ZUdevPHmyHS1nzd7JTeK0mgA%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:22am UTC](https://discuss.elastic.co/t/bug-in-context-suggester/17965/3 "2017-07-06T01:22:06Z")

</div>


