Depending on order of queries, there is no match (wrong) or there is a match (correct). This wrong behavior is only the case of queryes containing one of synonyms.
This is my index, data and explain queries:
PUT /pokus-index
{
"mappings": {
"properties": {
"fieldx": {
"type": "text",
"analyzer": "my_analyzer"
},
"fieldy": {
"type": "text",
"analyzer": "my_analyzer"
}
}
},
"settings": {
"index": {
"number_of_replicas": 0
},
"analysis": {
"filter": {
"my_synonyms": {
"type": "synonym",
"lenient": true,
"synonyms": ["aplikace, apka"]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"my_synonyms"
]
}
}
}
}
}
POST /pokus-index/_doc
{"fieldx":"xxx", "fieldy": "aplikace yyy"}
POST /pokus-index/_explain/kDehlYsByE4U1BF8_HRu
{
"query": {
"bool": {
"should": [
{
"match": {
"fieldx": {
"query": "aplikace"
}
}
},
{
"match": {
"fieldy": {
"query": "aplikace"
}
}
}
],
"minimum_should_match": 1
}
}
}
..."matched":false,"explanation":{"value":0.0,"description":"no matching term","details":}}
WHY no match? The fieldy contains the word "aplikace".
And now exactly the same query with differen order of match clauses:
POST /pokus-index/_explain/kDehlYsByE4U1BF8_HRu
{
"query": {
"bool": {
"should": [
{
"match": {
"fieldy": {
"query": "aplikace"
}
}
},
{
"match": {
"fieldx": {
"query": "aplikace"
}
}
}
],
"minimum_should_match": 1
}
}
}
..."matched":true,"explanation":{"value":0.8729663,"description":"weight(Synonym(fieldy:apka fieldy:aplikace) in 0) [PerFieldSimilarity], result of...
OK, this is expected.
The wrong behavior only hapens when there is synonym in query. If i change the word "aplikace" for "yyy", the order doesnt matter and there is always match as expected (fieldy contains yyy).
Thank you for explanation.