I have ten or so fields in all my documents: One in particular is product_code
which is unique per document and of type string.
I have a match query on _all
that works well, but I would like to perform a "fuzzy match" while preserving the ability to search for exact product_code
Here's what I've attempted:
"query": {
"bool": {
"should": [
{
"match": {
"product_code": {
"query": searchString,
"operator": "AND"
}
}
},
{
"match": {
"_all": {
"query": searchString,
"operator": "AND"
"fuzziness": 2,
"prefix_length": 2
}
}
}
]
}
}
The problem with this approach is that the fuzziness is being applied to searches for product_code
as well because it's included in _all
.
Is there a way to either perform the search on product_code
first and if no results are found, perform the search on _all
, or exclude product_code
from the _all
query?
Any help is greatly appreciated.