问题
I am using elastic search for autocompletion and also to correct spelling mistakes.I have this mapping for my field(for auto-completion).
**Mapping:**
"name": {
"type": "text",
"analyzer": "autocomplete"
}
Now i want to implement phrase suggester on this field.When i use this it is giving wrong result.Thats because of existing mapping i think.
**POST XYZ/_search**
{
"suggest": {
"text": "ipone 16",
"simple_phrase": {
"phrase": {
"field": "name",
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}
**Results:**
"options": [
{
"text": "i ip ipo iphon iphone 1 16",
"highlighted": "i ip ipo <em>iphon iphone</em> 1 16",
"score": 1.6111489e-8
},
{
"text": "i ip ipo iphon iphon 1 16",
"highlighted": "i ip ipo <em>iphon iphon</em> 1 16",
"score": 1.4219211e-8
},
{
"text": "i ip ipo ipho iphone 1 16",
"highlighted": "i ip ipo <em>ipho iphone</em> 1 16",
"score": 1.3510152e-8
},
{
"text": "i ip ipo ipho iphon 1 16",
"highlighted": "i ip ipo <em>ipho iphon</em> 1 16",
"score": 1.1923397e-8
},
{
"text": "i ip ipo iron iphone 1 16",
"highlighted": "i ip ipo <em>iron iphone</em> 1 16",
"score": 6.443544e-9
}
]
**From the document i should use this for phrase suggester.**
"mappings": {
"test": {
"properties": {
"title": {
"type": "text",
"fields": {
"trigram": {
"type": "text",
"analyzer": "trigram"
},
"reverse": {
"type": "text",
"analyzer": "reverse"
}
}
}
}
**How can i use two different mapping on same filed?**
回答1:
As your results are not tokenized properly the problem could be from your aurocomplete analyzer. please provide your
_settings
to see the defination for your analyzers.Do Your query on name.trigram.
- After solving this problem it's good to prune your result using
collate
回答2:
You can write a query like this. Please provide output for this query.
It's also good to have your trigram analyzer
settings (tokenizer, char mappers and token filters)
{
"suggest": {
"text": "noble prize",
"simple_phrase": {
"phrase": {
"field": "name_suggest.trigram",
"size": 1,
"gram_size": 3,
"direct_generator": [
{
"field": "name_suggest.trigram",
"suggest_mode": "always"
}
],
"collate": {
"query": {
"inline": {
"match": {
"title": "{{suggestion}}"
}
}
},
"prune": true
},
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}
来源:https://stackoverflow.com/questions/43973192/mappings-on-filed-elastic-search