Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
1.3.20
Describe the issue:
We have a search query that has a combination of must and should matches. There are multiple similar queries with different input fields:
GET some-index/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"fuzzy": {
"Name 1.white_hyphen_lower": {
"value": "forename1",
"transpositions": false,
"rewrite": "constant_score"
}
}
},
{
"fuzzy": {
"Name 2.white_hyphen_lower": {
"value": "surname1",
"transpositions": false,
"rewrite": "constant_score"
}
}
},
{
"bool": {
"should": [
{
"match": {
"DOB": {
"query": "02/02/2002",
"_name": "DOB"
}
}
},
{
"match": {
"birthyear": {
"query": "2002",
"_name": "birthyear"
}
}
}
]
}
}
]
}
},
{
"bool": {
"must": [
{
"fuzzy": {
"Name 1.white_hyphen_lower": {
"value": "othername1",
"transpositions": false,
"rewrite": "constant_score"
}
}
},
{
"fuzzy": {
"Name 2.white_hyphen_lower": {
"value": "othername2",
"transpositions": false,
"rewrite": "constant_score"
}
}
},
{
"bool": {
"should": [
{
"match": {
"DOB": {
"query": "02/02/2002",
"_name": "DOB2"
}
}
},
{
"match": {
"birthyear": {
"query": "2002",
"_name": "birthyear2"
}
}
}
]
}
}
]
}
}
],
"minimum_should_match": "1"
}
},
"size": "3"
}
The idea is that a document must match on both Name 1 and Name 2, and either DOB or birthyear.
We need to identify if we matched on DOB or birthyear, which we do via _name.
Based on an index with this data:
{
"_index" : "some-index",
"_type" : "_doc",
"_id" : "id2",
"_score" : 1.0,
"_source" : {
"Name 1" : "flibble2",
"Name 2" : "slibble2",
"DOB" : "02/02/2002",
"birthyear" : "2002"
}
},
{
"_index" : "some-index",
"_type" : "_doc",
"_id" : "id1",
"_score" : 1.0,
"_source" : {
"Name 1" : "forename1",
"Name 2" : "surname1",
"DOB" : "01/01/2002",
"birthyear" : "2002"
}
}
We would expect that we get a match on the document “id1”, which we do.
But what we also find is that in the matched_queries output, both birthyear and also birthyear2 are returned.
We cannot figure out how it is matching on the named query birthyear2 when the Name 1 and Name 2 fields are not being matched on.
Is this some strange behaviour of the _name functionality?
Below is the output of the query on the given data (truncated):
...
"hits" : [
{
"_index" : "some-index",
"_type" : "_doc",
"_id" : "id1",
"_score" : 3.0,
"_source" : {
"Name 1" : "forename1",
"Name 6" : "surname1",
"DOB" : "01/01/2002",
"birthyear" : "2002"
},
"matched_queries" : [
"birthyear",
"birthyear2"
]
}
]
...
Thanks in advance.