Query_string with "+" operator

Hi there,

I have an issue related to query_string using the "+" operator. Suppose that my index contains the documents below:

  doc_1
  {
     field1: "foo bar",
     field2: "zoo"
  }

  doc_2
  {
     field1: "foo",
     field2: "bar"
  }

Now, consider the following query_string:

{
    query_string:{
        query: foo bar
        fields: [field1^5, field2],
        default_operator: 'AND'
    }
}

Executing it, only the first document is returned, as foo and bar only occurs in one field (I'm not using quotation marks!)

If I change my query term to foo + bar

{
    query_string:{
        query: foo + bar
        fields: [field1^5, field2],
        default_operator: 'AND'
    }
}

both documents are returned, as the second document contains foo in one field and bar in another field.

My point is: Why should I force the "+" operator do have the second result, as I'm not using quotations in the first query? It seems that the "+" operator is much more than just force the terms to be presented in the document, it, somehow, tells the query_string to find the occurrence of them across the fields (I don't intend to use multi_match cross_field DSL!)
I'm asking that, because it's something that is not clear in the reference:
https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html
which says that, the "+" operator is similar to the default_operator = 'AND'.

Am I wrong?? What have I missed in my first query_string to have the terms searched across the fields and not the obligation to have all of them presented in one field??

Thanks,

Guilherme

This issue was discussed here: Confusing documentation on Query String Query on the split by whitespace behaviour · Issue #29148 · elastic/elasticsearch · GitHub!

I'm using elasticsearch 6.5, that's why it's happening!

Before 6.x the query is translated into (title:new OR text:new) AND (title:york OR title:york)... .

The later versions, the behaviour is

by default the query_string will first apply the analysis on the field title and build the query title:(new OR york OR city) and then it will combine this query with the text field: title:(new OR york OR city) OR text:(new OR york OR city) . If you change the default_operator to AND the query would be: title:(new AND york AND city) OR text:(new AND york AND city) . This means that a document will match if it contains new AND york AND city in one of the targeted fields.

It's something I need to change in my query term. But I suggest Elastic to let this clearer in the query_string reference.

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