Multiple types bool query - Different results based on type sequence?


(Hiten Java) #1

Hi all,

Basically, I have an index with two document types 'foo' and 'bar'.
I have a query such that find all 'bar' with 'testColumn1' as 123 and 'foo' with 'testColumn1' in nested object 'nestedObj' as 123.
(nestedObj is basically 'bar' type object within 'foo' in the denormalized schema.)

The problem is that the output is different based on sequence of document types in the 'GET' request.

GET /bar,foo/_search

produces output with both 'foo' and 'bar' type results, but if the sequence is changed to:

GET /foo,bar/_search

then it output only contains 'foo' type results. There are no results of type 'bar' in this case.

My query:
{
  "size" : 1000,
  "query" : {
    "bool" : {
      "minimum_number_should_match": 1, 
      "should" : [  {
        "filtered" : {
          "filter" : {
            "and" : {
              "filters" : [ {
                "term" : {
                  "nestedObj.testColumn1" : "123"
                }
              }, {
                "type" : {
                  "value" : "foo"
                }
              } ]
            }
          }
        }
      },
      {
        "filtered" : {
          "filter" : {
            "and" : {
              "filters" : [ {
                "term" : {
                  "testColumn1" : "123"
                }
              }, {
                "type" : {
                  "value" : "bar"
                }
              } ]
            }
          }
        }
      }]
    }

Any ideas on why this could be happening?

Thanks!


(Hiten Java) #2

I think I figured out a fix for this.

  1. I made sure that the 'nestedObj' property was not 'bar'. (Earlier, I was using 'bar' instead of 'nestedObj')
  2. I added doctype as the prefix in the query. ('bar.testColumn1' instead of 'testColumn1' and 'foo.nestedObj.testColumn1' instead of 'nestedObj.testColumn1'.)

After above 2 changes, I can see both 'foo' and 'bar' results irrespective of the sequence of doctypes in GET request.


(system) #3