I'm having some trouble getting the right query for elastic search. When searching on 2 fields it's giving unexpected results.
Let's say given the documents:
[
{ name: 'Infernoble', code: 'MP21' },
{ name: 'Infernoble', code: 'AMDE' },
{ name: 'A Cell Device', code: 'FOTB' }
]
I'm using searchkit's MultiMatchQuery
on those 2 fields which sends the following query to ElasticSearch:
{
"bool": {
"should": [
{
"multi_match": {
"query": "<my query term>",
"fields": [
"name",
"code"
],
"type": "best_fields",
"operator": "and"
}
},
{
"multi_match": {
"query": "<my query term>",
"fields": [
"name",
"code"
],
"type": "cross_fields"
}
},
{
"multi_match": {
"query": "<my query term>",
"fields": [
"name",
"code"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "<my query term>",
"fields": [
"name",
"code"
],
"type": "phrase_prefix"
}
}
]
}
}
Currently, if I search for "Infernoble" I correctly get the first 2 documents.
When I search "Infernoble AMDE" I would like it to bring the second document to the front (given that it has name:'Infernoble'
and code: 'AMDE'
),
Instead "Infernoble AMDE" gives the same results at the top as just "Infernoble".
Additionally, "Infernoble A" brings the 3rd document to the front (since it starts with "A"), ignoring that documents exist with name "Inferno".
The code
property is always just a short acronym that could be added to the end to narrow the search by code.
How can I get this to work?