Elastic AppSearch operators in query string yield unexpected results

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

// 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

"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

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

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

1 Like

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