# Multilevel depth query

**URL:** <https://discuss.elastic.co/t/multilevel-depth-query/86283>\
**Category:** Elasticsearch\
**Created:** [May 18, 2017, 2:42pm UTC](https://discuss.elastic.co/t/multilevel-depth-query/86283 "2017-05-18T14:42:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![serban88](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serban88/32/125925_2.png) [@serban88](https://discuss.elastic.co/u/serban88)\
**Post date:** [May 18, 2017, 2:42pm UTC](https://discuss.elastic.co/t/multilevel-depth-query/86283/1 "2017-05-18T14:42:40Z")

</div>

Hello, I started using Elasticsearch for my e-commerce site but I am struggling with a query:

I am trying to do the following SQL query:

> ```
> SELECT * FROM products WHERE 
> ((params.value = 'book' AND params.param = 'category'') OR (params.value = 'universal' AND params.param = 'category')) 
> AND 
> ((params.value = 'textile' AND params.param = 'material') OR (params.value = 'sillicon' AND params.param = 'material'))
> 
> ```

currently I have this:

```
"filter": [
        {
          "term": {
            "publicsite": 1
          }
        },
        {
          "nested": { 
            "path": "params",
            "query": {
              "bool": {
                "must": [
                  {
                    "bool": {
                      "should": [
                        {
                          "bool": {
                            "must": [
                              {
                                "term": {
                                  "params.value": "agenda"
                                }
                              },
                              {
                                "term": {
                                  "params.param": "subcategorie"
                                }
                              }
                            ]
                          }
                        },
                        {
                          "bool": {
                            "must": [
                              {
                                "term": {
                                  "params.value": "universala"
                                }
                              },
                              {
                                "term": {
                                  "params.param": "subcategorie"
                                }
                              }
                            ]
                          }
                        }
                      ]
                    }
                  },
                  {
                    "bool": {
                      "should": [
                        {
                          "bool": {
                            "must": [
                              {
                                "term": {
                                  "params.value": "textil"
                                }
                              },
                              {
                                "term": {
                                  "params.param": "material"
                                }
                              }
                            ]
                          }
                        },
                        {
                          "bool": {
                            "must": [
                              {
                                "term": {
                                  "params.value": "silicon"
                                }
                              },
                              {
                                "term": {
                                  "params.param": "material"
                                }
                              }
                            ]
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        }

```

]

The strange thing to me is that if I change to fist "must" into "should" it works but I'm not sure if its 100% corect.

---

<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:** [June 15, 2017, 2:43pm UTC](https://discuss.elastic.co/t/multilevel-depth-query/86283/2 "2017-06-15T14:43:00Z")

</div>

Closed on June 15, 2017, 2:43pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
