# Not able to perform auto-completion/suggestion and spell check in elasticsearch

**URL:** <https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227>\
**Category:** Elasticsearch\
**Created:** [May 2, 2017, 9:03am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227 "2017-05-02T09:03:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [May 2, 2017, 9:03am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/1 "2017-05-02T09:03:13Z")

</div>

Hi Everyone,  
I am putting my mapping file,documentation and whatever the query I have performed.Inside this i want to perform auto-completion/suggestion and spell check.if anyone knows about that then help me.  
Mapping File:  
PUT /test\_word16  
{  
"mappings": {  
"doc": {  
"properties": {  
"name": { "type": "string" },  
"depth": {"type":"long"},  
"children": {  
"type": "nested",  
"properties": {  
"name": { "type": "string" },  
"depth": { "type": "long" },  
"children": {  
"type": "nested",  
"properties": {  
"code": { "type": "string" },  
"name": { "type": "string" },  
"depth": { "type": "long" },  
"children": {  
"type": "nested",  
"properties": {  
"code": { "type": "string" },  
"name": { "type": "string" },  
"depth": { "type": "long" }  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

Documentation:  
POST /test\_word16/doc/1  
{  
"name": "Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism (D50-D89)",  
"depth": 1,  
"children": [{  
"name": "Nutritional anemias (D50-D53)",  
"depth": 2,  
"children": [{  
"code": "D50",  
"name": "Iron deficiency anemia",  
"depth": 3,  
"children": [{  
"code": "D50.0",  
"name": "Iron deficiency anemia secondary to blood loss (chronic)",  
"depth": 4  
}, {  
"code": "D50.1",  
"name": "Sideropenic dysphagia",  
"depth": 4  
}, {  
"code": "D50.8",  
"name": "Other iron deficiency anemias",  
"depth": 4  
}, {  
"code": "D50.9",  
"name": "Iron deficiency anemia, unspecified",  
"depth": 4  
}]  
}]  
}]  
}

QUERY:  
GET /test\_word16/doc/\_search  
{  
"\_source": false,  
"query": {  
"nested": {  
"path": "children.children.children",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"[children.children.children.name](http://children.children.children.name)": "Iron"  
}  
}  
]  
}  
},  
"inner\_hits": {  
"\_source": {  
"excludes":["name"]  
}  
}  
}  
}  
}  
Query is working fine but i am not able to perform auto-completion/suggestion and spell check

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 2, 2017, 9:26am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/2 "2017-05-02T09:26:02Z")

</div>

Auto completion can be achieved with the suggester type:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html)

For instance you can define a completion field for all fields that need auto-completion:

```
"name": { 
   	"type": "string",
    "fields": {
	    "suggest": {
		   "type": "completion"
        }
     }
}

```

For spellcheck you can use the phrase suggester:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html)

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [May 2, 2017, 10:39am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/3 "2017-05-02T10:39:39Z")

</div>

can you show me the mapping with my data because in this way only single level data will be able to find. but in my case nested data is there then how can we find.please help me to solve this problem  
please give me the proper explanation with mapping and query  
Thankyou

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [May 2, 2017, 12:51pm UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/4 "2017-05-02T12:51:36Z")

</div>

I am waiting for your reply

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 2, 2017, 1:19pm UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/5 "2017-05-02T13:19:09Z")

</div>

This forum is manned by volunteers, so please be patient.

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 2, 2017, 7:35pm UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/6 "2017-05-02T19:35:43Z")

</div>

@abhishek5678 you can just add a `copy_to` to your nested fields to make them appear at the root level:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html)  
This way you can define a simple completion field that contain all the values from your nested fields. Regarding the mapping and query I think that the documentation should be enough for you to test and experiment. That's how you can learn things rather than counting on me to solve your problem from A to Z ;).

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [May 3, 2017, 4:29am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/7 "2017-05-03T04:29:22Z")

</div>

@jimczi In this copy\_to we have find only particular word but i want auto suggestion let suppose my name is Abhishek and if i search only abh then it is automatically suggest me the name abhishek.  
and also i want spell check suppose i put wrong spelling of abhishek like ahbishek then also me suggestion will be provided.  
please help me I am not able to putting these two things in my example whatever i am sending to you.  
Thankyou

---

<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:** [May 31, 2017, 4:34am UTC](https://discuss.elastic.co/t/not-able-to-perform-auto-completion-suggestion-and-spell-check-in-elasticsearch/84227/8 "2017-05-31T04:34:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
