Consider an index containing thousands of flowers and their descriptions in my ES. For example, a redacted json document would look like this:
{
"name": "rose",
"description": "some long description about roses",
"categories": [
"flowers",
"red",
"thorn",
"perfume"
]
}
For some other needs, I have the following mapping to convert all the categories
into a text field like this:
{
"mappings": {
"properties": {
"categories": {
"type": "keyword",
"copy_to": "m_cats"
},
"m_cats": { "type": "text" }
}
}
}
The issue that I am facing is that when I run a multimatchquery, i can get a hit if i search for red flowers
, but if i search for red flower
, i cannot get a match because the s
in flowers
is missing.
I have tried to solve this by using various fuzziness values including 0
and AUTO
, but I can never get the rose document to show up for red flower
, only shows up for red flowers
. I am aware that the fuzziness applies to either keyword
or text
fields, and my index for flowers
is showing m_cats
as text correctly.
My code is using the olivere elasticsearch for golang, and is structured in the following way currently:
fields := []string{"m_cats", "description"}
q := elastic.NewMultiMatchQuery(query, fields...).Fuzziness("AUTO:1,6").MinimumShouldMatch("1")
result, err := helpers.Client.Search().Index(index).Size(limit).Query(q).Do(helpers.Ctx)
The JSON query roughly breaks down to
{
"query": {
"multi_match": {
"query": "red flower",
"fields": ["m_cats", "description"],
"fuzziness": "AUTO:1,6",
"minimum_should_match": 1
}
}
}
What else can I do/try so that I can get the rose document
as a hit when I search for red flower
? Notice the missing s
.
Please note, I am not having issues with keyword searches, but because I want to provide additional results whenever possible, I am using minimum_should_match
and avoiding using operator
.