title: How to use ElasticSearch Query params (DSL query) for multiple types?
body: <p>I have been working with the ElasticSearch from last few months, but still find it complicated when I have to pass an complicated query.</p>
  
  <p>I want to run the query which will have to search the multiple "types" and each type has to be searched with its own "filters", but need to have combined "searched results"</p>
  
  <p>For example:</p>
  
  <p>I need to search the "user type" document which are my friends and on the same time i have to search the "object type" document which I like, according to the keyword provided.</p>
  
  <p>OR </p>
  
  <p>The query that has both the "AND" and "NOT" clause</p>
  
  <p>Example query:</p>
  
  <pre><code>$options['query'] = array(
          'query' =&gt; array(
              'filtered' =&gt; array(
                  'query' =&gt; array(
                      'query_string' =&gt; array(
                          'default_field' =&gt; 'name',
                          'query' =&gt; $this-&gt;search_term . '*',
                      ),
                  ),
                  'filter' =&gt; array(
                      'and' =&gt; array(
                          array(
                              'term' =&gt; array(
                                  'access_id' =&gt; 2,
                              ),
                          ),
                      ),
  
                      'not' =&gt; array(
                          array(
                              'term' =&gt; array(
                                  'follower' =&gt; 32,
                              ),
                          ),
  
                          array(
                              'term' =&gt; array(
                                  'fan' =&gt; 36,
                              ),
                          ),
                      ),
                  ),
              ),
          ),
      );
  </code></pre>
  
  <p>as this query is meant to search the user with access_id = 2, but must not have the follower of id 32 and fan of id 36</p>
  
  <p>but this is not working..</p>
  
  <p><strong>Edit: Modified query</strong></p>
  
  <pre><code>{
    "query": {
      "filtered": {
        "filter": {
          "and": [
            {
              "not": {
                "filter": {
                  "and": [
                    {
                      "query": {
                        "query_string": {
                          "default_field": "fan",
                          "query": "*510*"
                        }
                      }
                    },
                    {
                      "query": {
                        "query_string": {
                          "default_field": "follower",
                          "query": "*510*"
                        }
                      }
                    }
                  ]
                }
              }
            },
            {
              "term": {
                "access_id": 2
              }
            }
          ]
        },
        "query": {
          "field": {
            "name": "xyz*"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p><em>now after running this query, i am getting two results, one with follower: "34,518" &amp; fan: "510" and second with fan:"34", but isn't it supposed to be only the second one in the result.</em></p>
  
  <p>Any ideas?</p>