When I'm trying to search using Loremipsum
it's returning empty array. I would like to get Lorem ipsum dolor
using Loremipsum
query.
value
Lorem ipsum dolor
query
GET favorite_candy/_search
{
"query": {
"multi_match": {
"query": "Loremipsum"
}
}
}
result
"hits" : [ ]
CodePudding user response:
This happens because there is no correspondence between the search token and the indexed tokens. In other words, the term "Loremipsum" does not find any corresponding token.
In my experience I see this as the possibility of using "did you mean". Once the term is incorrect, you can return suggestions for correct terms to the user.
In this case I did a test with Completion Suggestion. Note that I used the "preserve_separators" property so that you will get suggestions when you type the words together.
Query
PUT idx_test
{
"mappings": {
"properties": {
"suggest": {
"type": "completion",
"preserve_separators": false
}
}
}
}
PUT idx_test/_doc/1
{
"suggest": ["Lorem ipsum dolor"]
}
GET idx_test/_search
{
"suggest": {
"any-suggest": {
"prefix": "loremipsum",
"completion": {
"field": "suggest"
}
}
}
}
Response
"suggest": {
"any-suggest": [
{
"text": "loremipsum",
"offset": 0,
"length": 10,
"options": [
{
"text": "Lorem ipsum dolor",
"_index": "idx_test",
"_id": "1",
"_score": 1,
"_source": {
"suggest": [
"Lorem ipsum dolor"
]
}
}
]
}
]
}