# What is the basic logic behind the DSL query pattern?

**URL:** https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254
**Category:** Elasticsearch
**Created:** [August 25, 2011, 11:17pm UTC](https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254 "2011-08-25T23:17:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![chetansharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chetansharma/32/3119_2.png) [@chetansharma](https://discuss.elastic.co/u/chetansharma)
#### Post date: [August 25, 2011, 11:17pm UTC](https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254/1 "2011-08-25T23:17:42Z")

</div>

I am working on a project which is going to use the _elasticsearch_ very  
intensively in future, but i have trouble in implementing the _DSL_ queries  
as I am new to both _ElasticSearch_ and Lucene.

I am using _PHP_

here is example of my code:

$options['_query_'] = array(  
'_query_' =\> array(  
'filtered' =\> array(  
'_query_' =\> array(  
'_query\_string_' =\> array(  
'default\_field' =\> 'name',  
'_query_' =\> $this-\>search\_term . '\*',  
),  
),  
'filter' =\> array(  
'and' =\> array(  
array(  
'term' =\> array(  
'access\_id' =\> 2,  
),  
),  
),

```
                'not' => array( 
                    array( 
                        'term' => array( 
                            'follower' => 32, 
                        ), 
                    ), 

                    array( 
                        'term' => array( 
                            'fan' => 36, 
                        ), 
                    ), 
                ), 
            ), 
        ), 
    ), 
); 

```

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

but this is not working..

Please help thanks.

---

<div class="post-metadata">

### Author: ![chetansharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chetansharma/32/3119_2.png) [@chetansharma](https://discuss.elastic.co/u/chetansharma)
#### Post date: [August 26, 2011, 1:12am UTC](https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254/2 "2011-08-26T01:12:08Z")

</div>

'filter' =\> array(  
'and' =\> array(  
array(  
'term' =\> array(  
'access\_id' =\> 2,  
),  
),  
array(  
'not' =\> array(  
'term' =\> array(  
'follower\_of\_inverse' =\> 32,  
),  
),  
),  
),  
),

I have changed the query as follow and it works a little,  
but how do i add the second filter in it.

Waiting for response..

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [August 26, 2011, 10:12am UTC](https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254/3 "2011-08-26T10:12:01Z")

</div>

Hi Chetan

> I have changed the query as follow and it works a little,  
> but how do i add the second filter in it.
> 
> Waiting for response..

I have answered your question on stackoverflow:

> <https://stackoverflow.com/questions/7194823/how-to-use-elasticsearch-query-params-dsl-query-for-multiple-types>

clint

---

<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 6, 2017, 3:55am UTC](https://discuss.elastic.co/t/what-is-the-basic-logic-behind-the-dsl-query-pattern/5254/4 "2017-07-06T03:55:58Z")

</div>


