title: Usage of NestedFilter and changes in mapping
body: <p>I'm trying to create a filter on the basis of some product attributes which I've indexed. Earlier, they were indexed as follows -:</p>
  
  <pre><code>"attributes": {
      "name1": "value1",
      "name2": "value2",
      ....
  }
  </code></pre>
  
  <p>The filter that I used earlier was generated according to URL query parameters as follows -:</p>
  
  <p><code>"/search?q=product&amp;color=black&amp;color=blue&amp;size=xl"</code></p>
  
  <p>would lead to -</p>
  
  <pre><code>&gt;&gt;&gt; and_filter = ANDFilter(
          [
              ORFilter(
                  [
                      TermFilter('color', 'blue'),
                      TermFilter('color', 'black')
                  ]
              ),
              ORFilter(
                  [
                      TermFilter('size', 'xl')
                  ]
              )
          ]
      )
  &gt;&gt;&gt; main_filter = BoolFilter().add_must(and_filter)
  </code></pre>
  
  <p>Due to some changes in the backend, the mapping had to be changed to a nested one.</p>
  
  <p>New Mapping -:</p>
  
  <pre><code>"attributes":
  {
      "type": "nested",
      "properties": {
          "name": {"type": "string"},
          "display_name": {"type": "string"},
          "type": {"type": "string"},
          "value": {"type": "string"}
      }
  }
  </code></pre>
  
  <p>I thought of the new filter as so -:</p>
  
  <pre><code>&gt;&gt;&gt; and_filter = ANDFilter(
          [
              ORFilter(
                  [
                      ANDFilter(
                          [
                              TermFilter("attributes.name", "color"),
                              TermFilter("attributes.value", "blue"),
                          ]
                      ),
                      ANDFilter(
                          [
                              TermFilter("attributes.name", "color"),
                              TermFilter("attributes.value", "black"),
                          ]
                      )
                  ]
              ),
              ORFilter(
                  [
                      ANDFilter(
                          [
                              TermFilter("attributes.name", "size"),
                              TermFilter("attributes.value", "xl"),
                          ]
                      )
                  ]
              )
          ]
      )
  &gt;&gt;&gt; nested_filter = NestedFilter("attributes", BoolFilter().add_must(and_filter))
  </code></pre>
  
  <p>However, this doesn't seem to be the right way to do it. When I try to generate facets over products with this filter applied, all the counts come out to be zero everytime.</p>
  
  <p>Additionally, trying to search for products does not yield the expected results when the filter is applied.</p>
  
  <p>I would appreciate some pointers as to how to design the filter correctly.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Old Filter -:</p>
  
  <pre><code>{
    "bool": {
      "must": [
        {
          "and": [
            {
              "or": [
                {
                  "term": {
                    "color": "blue"
                  }
                },
                {
                  "term": {
                    "color": "black"
                  }
                }
              ]
            },
            {
              "or": [
                {
                  "term": {
                    "size": "xl"
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  }
  </code></pre>
  
  <p>New Filter -:</p>
  
  <pre><code>{
    "nested": {
      "filter": {
        "bool": {
          "must": [
            {
              "and": [
                {
                  "or": [
                    {
                      "and": [
                        {
                          "term": {
                            "attributes.name": "color"
                          }
                        },
                        {
                          "term": {
                            "attributes.value": "blue"
                          }
                        }
                      ]
                    },
                    {
                      "and": [
                        {
                          "term": {
                            "attributes.name": "color"
                          }
                        },
                        {
                          "term": {
                            "attributes.value": "black"
                          }
                        }
                      ]
                    }
                  ]
                },
                {
                  "or": [
                    {
                      "and": [
                        {
                          "term": {
                            "attributes.name": "size"
                          }
                        },
                        {
                          "term": {
                            "attributes.value": "xl"
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      },
      "path": "attributes"
    }
  }
  </code></pre>