# Nested Bool Query With Two Must's

**URL:** <https://discuss.elastic.co/t/nested-bool-query-with-two-musts/121226>\
**Category:** Elasticsearch\
**Created:** [February 23, 2018, 2:18pm UTC](https://discuss.elastic.co/t/nested-bool-query-with-two-musts/121226 "2018-02-23T14:18:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rs82uk](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rs82uk](https://discuss.elastic.co/u/rs82uk)\
**Post date:** [February 23, 2018, 2:18pm UTC](https://discuss.elastic.co/t/nested-bool-query-with-two-musts/121226/1 "2018-02-23T14:18:32Z")

</div>

I am trying to filter my results dependent on filters selected by the user, these would be for example Size Brand Etc in SQL world it would be something along the lines of WHERE (Brand = 'Brand1' OR Brand= 'Brand2') AND (Size = '10')

Here is my mapping

```
{
"myindex": {
    "mappings": {
        "product": {
            "properties": {
                "description": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "html": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "name": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "notes": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "price": {
                    "type": "double"
                },
                "productBrandId": {
                    "type": "integer"
                },
                "productCategory": {
                    "properties": {
                        "code": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "fullPath": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "name": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "parentProductCategoryId": {
                            "type": "integer"
                        },
                        "productCategoryId": {
                            "type": "integer"
                        }
                    }
                },
                "productCategoryId": {
                    "type": "integer"
                },
                "productCode": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "productId": {
                    "type": "integer"
                },
                "productImage": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "productSpecification": {
                    "type": "nested",
                    "properties": {
                        "description": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "name": {
                            "type": "keyword"
                        },
                        "productId": {
                            "type": "long"
                        },
                        "productSpecificationId": {
                            "type": "long"
                        },
                        "specificationId": {
                            "type": "long"
                        },
                        "value": {
                            "type": "keyword"
                        }
                    }
                },
                "taxRateId": {
                    "type": "integer"
                },
                "url": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

```

I currently have the following query but I get no hits returned if I do one or the other I get results but not with both

```
{
"nested": {
	"path": "productSpecification",
	"query": {
		"bool": {
			"must": [{
					"bool": {
						"should": [{
								"term": {
									"productSpecification.name.keyword": "Brand"
								}
							},
							{
								"terms": {
									"productSpecification.value": [
										"Brand 1",
										"Brand 2"
									]
								}
							}
						]
					}
				},
				{
					"bool": {
						"should": [{
								"term": {
									"productSpecification.name.keyword": "Guarantee"
								}
							},
							{
								"terms": {
									"productSpecification.value": [
										"3 years",
										"10 years"
									]
								}
							}
						]
					}
				}
			]
		}
	}
}

```

}

---

<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:** [March 23, 2018, 2:19pm UTC](https://discuss.elastic.co/t/nested-bool-query-with-two-musts/121226/2 "2018-03-23T14:19:54Z")

</div>

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