I'd probably just simplify and eliminate all the nested stuff. So for 
example, if your document is like this:

{
  "name": "Shirt1",
  "color": ["Red"]
  "size": ["XL", "S", "M"]
}

It's easy to execute queries like this:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            { "term": { "color": "red" } },
            { "term": { "size": "m" } }
          ]
        }
      }
    }
  }
}

The reason your query doesn't match any is because the nested:options part 
will look into a *single* option item to satisfy both your conditions which 
will never be true. If you change your query to something like this, it 
should work as expected:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "bool": {
                "must": [
                  {
                    "nested": {
                      "path": "options",
                      "filter": {
                        "bool": {
                          "must": [
                            {
                              "term": {
                                "options.name": "size"
                              }
                            },
                            {
                              "nested": {
                                "path": "options.values",
                                "filter": {
                                  "term": {
                                    "options.values.name": "m"
                                  }
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  },
                  {
                    "nested": {
                      "path": "options",
                      "filter": {
                        "bool": {
                          "must": [
                            {
                              "term": {
                                "options.name": "color"
                              }
                            },
                            {
                              "nested": {
                                "path": "options.values",
                                "filter": {
                                  "term": {
                                    "options.values.name": "red"
                                  }
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/8bfb26cd-8879-4c9b-ad2a-62be25a2a91c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to