Hello !
I'm facing an issue with elasticsearch 8. I have an index that contains companies and I use a copy_to parameters to group searchable fields of these companies. However, some fields can be null, and some can contains strings with spaces. As a result, one company doesn't have the same search field length than another one and it influences search results. For example:
PUT /my-index
{
mappings: {
properties: {
"companyName": {
"type": "text",
"store": true,
"copy_to": "search_field_1"
},
"reference": {
"type": "text",
"store": true,
"copy_to": "search_field_1"
}
"comment": {
"type": "text",
"store": true,
"copy_to": "search_field_1"
},
"otherField": {
"type": "text",
"store": true,
"copy_to": "search_field_2"
}
}
}
}
POST my-index/_doc/
{
"companyName": "test",
"reference": "001245",
"comment": "a large comment",
"otherField": "00000"
}
POST my-index/_doc/
{
"companyName": "test company",
"reference": "123",
"comment": null,
"otherField": null
}
GET /_search
{
"query": {
"multi_match" : {
"query": "test",
"type": "cross_fields",
"operator": "and",
"fields": [ "search_field_1^1", "search_field_2^2" ]
}
}
}
If I search "test", I am expecting the first company as the first result because of its company name. Instead of that, it's the second one, because its search field length is shorter.
Did I miss something here? Should I change my mapping to archive that behavior?