# Elastic AppSearch operators in query string yield unexpected results

**URL:** <https://discuss.elastic.co/t/elastic-appsearch-operators-in-query-string-yield-unexpected-results/325572>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 15, 2023, 9:23am UTC](https://discuss.elastic.co/t/elastic-appsearch-operators-in-query-string-yield-unexpected-results/325572 "2023-02-15T09:23:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nguyen\_Anh\_Vu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nguyen_anh_vu/32/117277_2.png) [@Nguyen\_Anh\_Vu](https://discuss.elastic.co/u/Nguyen_Anh_Vu)\
**Post date:** [February 15, 2023, 9:23am UTC](https://discuss.elastic.co/t/elastic-appsearch-operators-in-query-string-yield-unexpected-results/325572/1 "2023-02-15T09:23:45Z")

</div>

I run these queries and here are the number of results I got

```auto
// Query 1
machine AND building
{
  "query": "machine AND building"
}
// Total 109 items

// Query 2
machine AND car
// Total 27 items

// Query 3. Total 6 items
machine AND building OR car

// Query 4. Total 6 items
building AND machine OR car

// Query 5. Total 6 items
car AND machine OR building

// Query 6. Total 6 items
car OR machine AND building

```

What we think is that query 3,4,5, 6 should return more matches than query 1,2 but it seems not working like that. We suspect that "term\_1 AND term\_2 OR term\_3" , "term\_1 OR term\_2 AND term\_3" have become "term\_1 AND term\_2 AND term\_3"

The search\_explain endpoint (/api/as/v1/engines/ENGINE/search\_explain ) showed this

```auto
"query": {
            "bool": {
                "must": {
                    "bool": {
                        "must": [
                            {
                                "bool": {
                                    "should": [
                                        {
                                            "query_string": {
                                                "query": "machine AND building OR car",
                                                "fields": [
                                                       // omitted
                                                ]
                                               "minimum_should_match": "1<-1 3<49%",
                                                "phrase_slop": 0
// omitted

```

How can " AND OR" and " OR AND " become " AND AND " in this case or did we misunderstand something ? How should we change the query to get the expected results ?  
Thank you

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [February 15, 2023, 2:49pm UTC](https://discuss.elastic.co/t/elastic-appsearch-operators-in-query-string-yield-unexpected-results/325572/2 "2023-02-15T14:49:37Z")

</div>

Hi @Nguyen_Anh_Vu ,

This is a known issue where the `minimum_should_match` coming from your relevance slider is conflicting with the number of terms present in the query. To work around this, you can

1. use the Search Explain API (as you've already done) to get the underlying Elasticsearch Query,
2. remove the `minimum_should_match` if you're attempting to use lucene query syntax
3. execute the resulting query through App Search's [Elasticsearch Search API](https://www.elastic.co/guide/en/app-search/current/elasticsearch-search-api-reference.html)

We hope to have this issue resolved in a future version, but I don't have a timeline for you, at this moment.

---

<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:** [March 15, 2023, 2:49pm UTC](https://discuss.elastic.co/t/elastic-appsearch-operators-in-query-string-yield-unexpected-results/325572/3 "2023-03-15T14:49:50Z")

</div>

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