# Help to Combine Queries

**URL:** <https://discuss.elastic.co/t/help-to-combine-queries/109807>\
**Category:** Elasticsearch\
**Created:** [November 30, 2017, 5:35pm UTC](https://discuss.elastic.co/t/help-to-combine-queries/109807 "2017-11-30T17:35:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bevikra](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@bevikra](https://discuss.elastic.co/u/bevikra)\
**Post date:** [November 30, 2017, 5:35pm UTC](https://discuss.elastic.co/t/help-to-combine-queries/109807/1 "2017-11-30T17:35:02Z")

</div>

Hello,

Here is my Schema,

```
{
	"cmslocal": {
		"mappings": {
			"video": {
				"properties": {
					"assetProps": {
						"properties": {
							"assetType": {
								"type": "string"
							},
							"configPath": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string",
										"index": "not_analyzed"
									}
								},
								"analyzer": "standard"
							},
							"contentSha1": {
								"type": "string"
							},
							"originalPath": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string",
										"index": "not_analyzed"
									}
								},
								"analyzer": "standard"
							},
							"path": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string",
										"index": "not_analyzed"
									}
								},
								"analyzer": "standard"
							},
							"thumbnailPath": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string",
										"index": "not_analyzed"
									}
								},
								"analyzer": "standard"
							}
						}
					},
					"channel": {
						"type": "string"
					},
					"configProps": {
						"properties": {
							"events": {
								"type": "nested",
								"include_in_root": true,
								"properties": {
									"Desc": {
										"type": "string"
									},
									"Tags": {
										"type": "string"
									},
									"UUID": {
										"type": "string"
									}
								}
							},
							"roiUUID": {
								"type": "string"
							}
						}
					},
					"contentSha1": {
						"type": "string"
					},
					"eventDesc": {
						"type": "string"
					},
					"ext": {
						"type": "string"
					},
					"format": {
						"type": "string"
					},
					"fovProps": {
						"properties": {
							"description": {
								"type": "string"
							},
							"width": {
								"type": "float"
							}
						}
					},
					"locationProps": {
						"type": "nested",
						"properties": {
							"address": {
								"type": "string"
							},
							"city": {
								"type": "string"
							},
							"country": {
								"type": "string"
							},
							"county": {
								"type": "string"
							},
							"location": {
								"type": "geo_point"
							},
							"postcode": {
								"type": "string"
							},
							"state": {
								"type": "string"
							}
						}
					},
					"nodeid": {
						"type": "string"
					},
					"poleHeight": {
						"type": "float"
					},
					"query": {
						"properties": {
							"bool": {
								"properties": {
									"filter": {
										"properties": {
											"term": {
												"properties": {
													"nodeid": {
														"type": "string"
													}
												}
											}
										}
									}
								}
							}
						}
					},
					"retentionPolicy": {
						"type": "string"
					},
					"siteScopeID": {
						"type": "string"
					},
					"tagProps": {
						"type": "nested",
						"properties": {
							"conditions": {
								"type": "string"
							},
							"environment": {
								"type": "string"
							},
							"events": {
								"type": "string"
							},
							"lighting": {
								"type": "string"
							},
							"objects": {
								"type": "string"
							},
							"other": {
								"type": "string"
							},
							"scenes": {
								"type": "string"
							},
							"useCases": {
								"type": "string"
							},
							"weather": {
								"type": "string"
							}
						}
					},
					"test": {
						"type": "string"
					},
					"title": {
						"type": "string"
					},
					"uploadTime": {
						"type": "date",
						"format": "strict_date_optional_time||epoch_millis"
					},
					"videoProps": {
						"properties": {
							"bitrate": {
								"type": "float"
							},
							"datetime": {
								"type": "date",
								"format": "date_hour_minute_second_millis"
							},
							"daySegments": {
								"type": "string"
							},
							"duration": {
								"type": "long"
							},
							"framerate": {
								"type": "float"
							},
							"height": {
								"type": "integer"
							},
							"overlaysOn": {
								"type": "boolean"
							},
							"width": {
								"type": "integer"
							}
						}
					}
				}
			}
		}
	}
}

```

Please help to build the query so I can search for

1. Only nodeId, Only Channel, Date Range
2. Any of the Tags

I'm able to search for nodeId, Channel Id using

```
{
    "query": {
        "bool": {
            "filter": [
                { "match": { "nodeid": "N02cff15a" } },
                { "match": { "channel": "1" } }
            ]
        }
    }
}

```

and I can able to Search for tagProps using

```
{
    "nested": {
        "path": "tagProps",
        "query": {
            "bool": {
                "must": [
                    { "match": { "tagProps.objects": "car" } },
                    { "match": { "tagProps.objects": "truck" } }
                ]
            }
        }
    }
}

```

Help me combine two queries so I can search for NodeId with Combination of Tags.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 1, 2017, 8:08am UTC](https://discuss.elastic.co/t/help-to-combine-queries/109807/2 "2017-12-01T08:08:08Z")

</div>

you need to use the bool query to combine things like this

```auto
"bool" : {
  "must": { "nested" : ... },
  "filter" : [{ "match": ... }, { "match": ... }]
}

```

hope this makes sense

---

<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:** [December 29, 2017, 8:08am UTC](https://discuss.elastic.co/t/help-to-combine-queries/109807/3 "2017-12-29T08:08:20Z")

</div>

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