# Boolean should query wrong result

**URL:** <https://discuss.elastic.co/t/boolean-should-query-wrong-result/346381>\
**Category:** Elasticsearch\
**Created:** [November 3, 2023, 3:15pm UTC](https://discuss.elastic.co/t/boolean-should-query-wrong-result/346381 "2023-11-03T15:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Cern](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_cern/32/124791_2.png) [@Lukas\_Cern](https://discuss.elastic.co/u/Lukas_Cern)\
**Post date:** [November 3, 2023, 3:15pm UTC](https://discuss.elastic.co/t/boolean-should-query-wrong-result/346381/1 "2023-11-03T15:15:16Z")

</div>

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

```auto
{
	"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

```auto
{
	"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

```auto
{
	"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.

---

<div class="post-metadata">

**Author:** ![Lukas\_Cern](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_cern/32/124791_2.png) [@Lukas\_Cern](https://discuss.elastic.co/u/Lukas_Cern)\
**Post date:** [November 6, 2023, 9:14am UTC](https://discuss.elastic.co/t/boolean-should-query-wrong-result/346381/2 "2023-11-06T09:14:47Z")

</div>

OK, this issue is on ES 8.7, i have just tried 8.10.4 and there this issue does not exist.  
SOLVED

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 4, 2023, 9:15am UTC](https://discuss.elastic.co/t/boolean-should-query-wrong-result/346381/3 "2023-12-04T09:15:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
