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

**URL:** <https://discuss.elastic.co/t/multiple-types-bool-query-different-results-based-on-type-sequence/34880>\
**Category:** Elasticsearch\
**Created:** [November 18, 2015, 5:04am UTC](https://discuss.elastic.co/t/multiple-types-bool-query-different-results-based-on-type-sequence/34880 "2015-11-18T05:04:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitenj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hitenj/32/5991_2.png) [@hitenj](https://discuss.elastic.co/u/hitenj)\
**Post date:** [November 18, 2015, 5:04am UTC](https://discuss.elastic.co/t/multiple-types-bool-query-different-results-based-on-type-sequence/34880/1 "2015-11-18T05:04:47Z")

</div>

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.

```auto
GET /bar,foo/_search
```

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

```auto
GET /foo,bar/_search
```

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

```auto
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!

---

<div class="post-metadata">

**Author:** ![hitenj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hitenj/32/5991_2.png) [@hitenj](https://discuss.elastic.co/u/hitenj)\
**Post date:** [November 18, 2015, 5:35am UTC](https://discuss.elastic.co/t/multiple-types-bool-query-different-results-based-on-type-sequence/34880/2 "2015-11-18T05:35:08Z")

</div>

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.

---

<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:** [July 5, 2017, 11:37pm UTC](https://discuss.elastic.co/t/multiple-types-bool-query-different-results-based-on-type-sequence/34880/3 "2017-07-05T23:37:47Z")

</div>


