Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap a query with constant score change the size of result from 1 to 0 , es 6.8.8 #54802

Closed
vkocubinsky opened this issue Apr 6, 2020 · 1 comment

Comments

@vkocubinsky
Copy link

Elasticsearch version (bin/elasticsearch --version):
Version: 6.8.8, Build: default/tar/2f4c224/2020-03-18T23:22:18.622755Z, JVM: 1.8.0_192
Plugins installed: []

JVM version (java -version):
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
OS version (uname -a if on a Unix-like system):
Darwin MacBook.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
Description of the problem including expected versus actual behavior:
I have an index, index contains 1 document, I have elasticsearch query , query match the document and search api return the result. When I wrap the query with "constant_score" clause I got zero result. I reproduced issue on 6.8.0, 6.8.8, but on 7.6.2 everything is works as expected

My question is is any plan to fix it for 6.x version?

Steps to reproduce:

  1. Create index
curl -XPUT localhost:9200/twitter -H 'Content-type: application/json' -d '
{
    "mappings" : {
        "_doc": { 
            "properties" : {
                "message" : { "type" : "text" }
            }
        }
    }
}
'
  1. Put a document
curl -XPUT localhost:9200/twitter/_doc/1?pretty -H 'Content-Type: application/json' -d '
{
    "message": "hello world"
}'
  1. Execute query
curl -H "Content-type: application/json" -XPOST localhost:9200/twitter/_search -d '
{
   "query" : {
      "bool" : {
         "must" : [
            {
               "bool" : {
                  "must" : [
                     {
                        "bool" : {
                           "must" : {
                              "query_string" : {
                                 "query" : "+message:hello +message:world"
                              }
                           },
                           "should" : {
                              "query_string" : {
                                 "query" : "message:foo"
                              }
                           }
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}
'

Query return the result

{"took":78,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":0.5753642,"hits":[{"_index":"twitter","_type":"_doc","_id":"1","_score":0.5753642,"_source":
{
    "message": "hello world"
}}]}}
  1. Execute wrapped with "constant_score" query
curl -H "Content-type: application/json" -XPOST localhost:9200/twitter/_search -d '
{
   "query" : {
      "constant_score" : {
         "filter" : {
            "bool" : {
               "must" : [
                  {
                     "bool" : {
                        "must" : [
                           {
                              "bool" : {
                                 "must" : 
                                    {
                                       "query_string" : {
                                          "query" : "+message:hello +_words:world"
                                       }
                                    }
                                 ,
                                 "should" : 
                                    {
                                       "query_string" : {
                                          "query" : "message:foo"
                                       }
                                    }
                                 
                              }
                           }
                        ]
                     }
                  }
               ]
            }
         }
      }
   }
}
'

The difference is only "constant_score ... filter". The result is

{"took":7,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

Expected result is 1 document, the same as not wrapped with "constant_score" query.

This is only reproduced on es 6.8 especially 6.8.0 and 6.8.8, but on 7.6.2 wrapped with "constant_score" query.

Do you plan to fix for 6.8.8 ?

@jimczi
Copy link
Contributor

jimczi commented Apr 6, 2020

Do you plan to fix for 6.8.8

This is the documented behavior in 6.8.8 (see the important section called "Bool query in filter context"). Although, we agree that this behavior can be confusing, which is why we've decided to deprecate it in 6.x and to make the breaking change in 7.x: #35354
You should have a deprecation warning associated with the response in 6.8, that's how we warn users that a breaking change will occur in the next major version.
For these reasons, I hope you don't mind if I close the issue since you consider the new behavior as the right thing to do.

@jimczi jimczi closed this as completed Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants