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


(Abhishek Gupta) #1

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": "Iron"
}
}
]
}
},
"inner_hits": {
"_source": {
"excludes":["name"]
}
}
}
}
}
Query is working fine but i am not able to perform auto-completion/suggestion and spell check


(Jimferenczi) #2

Auto completion can be achieved with the suggester type:
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


(Abhishek Gupta) #3

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


(Abhishek Gupta) #4

I am waiting for your reply


(Christian Dahlqvist) #5

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


(Jimferenczi) #6

@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
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 ;).


(Abhishek Gupta) #7

@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


(system) #8

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