# Filtering data in elasticsearch 1.7 php

**URL:** <https://discuss.elastic.co/t/filtering-data-in-elasticsearch-1-7-php/44802>\
**Category:** Elasticsearch\
**Created:** [March 18, 2016, 7:55am UTC](https://discuss.elastic.co/t/filtering-data-in-elasticsearch-1-7-php/44802 "2016-03-18T07:55:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibrahimovfuad](https://avatars.discourse-cdn.com/v4/letter/i/e47c2d/32.png) [@ibrahimovfuad](https://discuss.elastic.co/u/ibrahimovfuad)\
**Post date:** [March 18, 2016, 7:55am UTC](https://discuss.elastic.co/t/filtering-data-in-elasticsearch-1-7-php/44802/1 "2016-03-18T07:55:14Z")

</div>

HI all!  
I am trying to filter my products and i have some problems with query..  
here is my mapping in attached file  
[mapping.json](https://onedrive.live.com/redir?resid=E53393FC07E6FCC9!332141&authkey=!AOOOBibr71Ye43M&ithint=file%2cjson)  
Here is my query.

```
          `$query = [
                    'query'=>[
                        'filtered'=>[
                                 'query'=>[
                                            ['term'=>['language'=>$lang]], //current language
                                       ],
                             'filter'=>[
                                  ['terms'=>['manufacturer_id'=>$manufacturerId]],//array of manufacturers
                                  ['terms'=>['attribute_id'=>$attributeId]],//array of attributes
                                  ['term'=>['category_id'=>$categoryId]],//id of current category which comes from $_GET
                                  [
                                      'range'=>[
                                           'price'=>[
                                              'gte'=>$gte,
                                             'lte'=>$lte
                                          ]
                                  ]

                          ],
                   ]
               ]
          ];`

```

All parameters i am getting from $\_GET  
And some of parameters like manufacturer\_id, attribute\_id, price can be empty in $\_GET  
But category\_id, language is required and it cant be empty.  
And when i want to filter by manufaturer\_id i am sending and array but i dont want to filter by attribute\_id and it is empty.  
My query doesn't return correct data because it needs an attribute\_id .but it is empty array.  
So how write a query which will ignore statement if the value from $\_GET is empty.

The second problem (if you saw my mapping you will understand what i mean)  
I have

```
          ` "properties" : { //root properties object
                   //another props here 
                   "productOnly" : {
                      "properties" : {
                        ......
                        "price" : {
                          "type" : "float"
                        }
                      }
                    }
             }`

```

so how can i refer to price in range filter?  
i tried somethind like this `productOnly.price` but it didnt works

Third problem.  
I have a productToCategory array of objects  
here is mapping

```
          ` "properties" : {//root properties object
                   //another props here 
                     "productOnly" : {},
                    "productToCategory" : {
                      "properties" : {
                        "category_id" : {
                          "type" : "integer"
                        },
                        "id" : {
                          "type" : "integer"
                        },
                        "product_id" : {
                          "type" : "integer"
                        }
                      }
                    }
             }`

```

And i tried to refer like this

`['term'=>['productToCategory.category_id'=>$categoryId]],`

but it didnt works  
Please help)

---

<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:07pm UTC](https://discuss.elastic.co/t/filtering-data-in-elasticsearch-1-7-php/44802/2 "2017-07-05T23:07:17Z")

</div>

Closed on July 5, 2017, 11:07pm UTC


