# Context suggestor in elastic search applied on the nested fields

**URL:** <https://discuss.elastic.co/t/context-suggestor-in-elastic-search-applied-on-the-nested-fields/44946>\
**Category:** Elasticsearch\
**Created:** [March 21, 2016, 5:31am UTC](https://discuss.elastic.co/t/context-suggestor-in-elastic-search-applied-on-the-nested-fields/44946 "2016-03-21T05:31:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemraj-sharma](https://avatars.discourse-cdn.com/v4/letter/h/e9a140/32.png) [@hemraj-sharma](https://discuss.elastic.co/u/hemraj-sharma)\
**Post date:** [March 21, 2016, 5:31am UTC](https://discuss.elastic.co/t/context-suggestor-in-elastic-search-applied-on-the-nested-fields/44946/1 "2016-03-21T05:31:09Z")

</div>

I came across a problem to implement the context suggester of elastic search for the auto-complete search. In my case i have the index document as: explained bellow--\>\>

I need to get the document which should have status active, and the object matched in the "nestedField" corresponding to the values of:"nestField1" and "nestField2" in the object:

```
  {
    "nestField1":"nestValue5",
    "nestField2":"nestValue6",
    ...
    }

```

I need to apply the context suggester for this scenario. I tried context mapping discussed down the page:

but this didn,t work for me. To implement this I mainly refer the links as: [https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html)

The only link I got on the stack overfolw Which seems I guess similar, didnt give much idea about this though. Elasticsearch completion suggester context for nested fields

You may refer the link as: [https://github.com/elastic/elasticsearch/issues/6444](https://github.com/elastic/elasticsearch/issues/6444)

as per suggestion I make some changes in the context mapping as:

```
      "suggest_field": {
    "type": "completion",
    "analyzer": "simple",
    "payloads": false,
    "preserve_separators": true,
    "preserve_position_increments": true,
    "max_input_length": 50,
    "context": {
      "netsedField_nestField1_ctx": {
        "type": "category",
        "path": "netsedField.nestField1",
        "default": [
          "unknown"
        ]
      },
      "netsedField_nestField2_ctx": {
        "type": "category",
        "path": "netsedField.nestField2",
        "default": [
          "Enable"
        ]
      },
      "status_ctx": {
        "type": "category",
        "path": "status",
        "default": [
          "Active"
        ]
      }
    }
  }

```

and my documents are as follows:

"hits": [  
{  
"\_index": "my\_index1",  
"\_type": "subscriber",  
"\_id": "2",  
"\_score": 1,  
"\_source": {  
"device": {  
"brand": "Brand one",  
"model": "bRAND One"  
},  
"personal": {  
"login": "login",  
"firstName": "first name",  
"lastName": "last name",  
"address": "address",  
"zipCode": "zip code",  
"city": "city",  
"country": "COUNTRY",  
"language": "LanGuage"  
},  
"suggest\_field": {  
"input": [  
"Brand",  
"bRAND",  
"One"  
],  
"output": "Brand One,1-3 disable,2-enable",  
"weight": 10  
},  
"netsedField": [  
{  
"nestField1": 1,  
"nestField2": "Disable"  
},  
{  
"nestField1": 2,  
"nestField2": "Enable"  
},  
{  
"nestField1": 3,  
"nestField2": "Disable"  
}  
],  
"status": "Active"  
}  
},  
{  
"\_index": "my\_index1",  
"\_type": "subscriber",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"device": {  
"brand": "Brand one",  
"model": "bRAND One"  
},  
"personal": {  
"login": "login",  
"firstName": "first name",  
"lastName": "last name",  
"address": "address",  
"zipCode": "zip code",  
"city": "city",  
"country": "COUNTRY",  
"language": "LanGuage"  
},  
"suggest\_field": {  
"input": [  
"Brand",  
"bRAND",  
"One"  
],  
"output": "Brand 1 ,1-2 enable,3 disable",  
"weight": 10  
},  
"netsedField": [  
{  
"nestField1": 1,  
"nestField2": "Enable"  
},  
{  
"nestField1": 2,  
"nestField2": "Enable"  
},  
{  
"nestField1": 3,  
"nestField2": "Disable"  
}  
],  
"status": "Active"  
}  
}  
]

and I am hitting the suggest request as: POST host:port/index/\_suggest

{  
"my\_index1" : {  
"text" : "b",  
"completion" : {  
"field" : "suggest\_field",  
"context":{  
"status\_ctx":"Active",  
"netsedField\_nestField2\_ctx":"Enable",  
"netsedField\_nestField1\_ctx":"1"  
}  
}  
}  
}

and the response I am getting are as

{  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"my\_index1": [  
{  
"text": "b",  
"offset": 0,  
"length": 1,  
"options": [  
{  
"text": "Brand 1 ,1-2 enable,3 disable",  
"score": 10  
},  
{  
"text": "Brand One,1-3 disable,2-enable",  
"score": 10  
}  
]  
}  
]  
}

but in response i Dont need :

{  
"text": "Brand One,1-3 disable,2-enable",  
"score": 10  
}

as part of options, as in the \_suggest query i am giving the context values :

```
  "netsedField_nestField2_ctx":"Enable",
  "netsedField_nestField1_ctx":"1"

```

Please tell me where am I making the mistake.

---

<div class="post-metadata">

**Author:** ![Nilabhsagar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilabhsagar/32/10647_2.png) [@Nilabhsagar](https://discuss.elastic.co/u/Nilabhsagar)\
**Post date:** [April 18, 2017, 8:11am UTC](https://discuss.elastic.co/t/context-suggestor-in-elastic-search-applied-on-the-nested-fields/44946/2 "2017-04-18T08:11:15Z")

</div>

Hi,

Here is the link for a feature which solves your problem. Please go through and provide your feedback.

> <https://github.com/elastic/elasticsearch/issues/23476>

---

<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 5, 2017, 10:01pm UTC](https://discuss.elastic.co/t/context-suggestor-in-elastic-search-applied-on-the-nested-fields/44946/3 "2017-07-05T22:01:06Z")

</div>


