# Ignore must term (6.0)

**URL:** <https://discuss.elastic.co/t/ignore-must-term-6-0/109864>\
**Category:** Elasticsearch\
**Created:** [December 1, 2017, 2:16am UTC](https://discuss.elastic.co/t/ignore-must-term-6-0/109864 "2017-12-01T02:16:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyB](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@AndyB](https://discuss.elastic.co/u/AndyB)\
**Post date:** [December 1, 2017, 2:16am UTC](https://discuss.elastic.co/t/ignore-must-term-6-0/109864/1 "2017-12-01T02:16:46Z")

</div>

I have the following DSL:

```
"filter" => array(
	"bool" => array(
		"must" => [
			array(
				"term" => array(
					"node" => $currentNodeId
				)
			),
			array(
				"term" => array(
					"type" => 'thread'
				)
			)
		],

```

What I would like to is if the $currentNodeId has a value, follow the must term, otherwise if it has no value, the must term would be ignored, is this possible?

---

<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, 7:56am UTC](https://discuss.elastic.co/t/ignore-must-term-6-0/109864/2 "2017-12-01T07:56:55Z")

</div>

that is part of your application logic, you just construct the array of the `must` query separately based on a condition and then insert at this place.

---

<div class="post-metadata">

**Author:** ![AndyB](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@AndyB](https://discuss.elastic.co/u/AndyB)\
**Post date:** [December 1, 2017, 3:03pm UTC](https://discuss.elastic.co/t/ignore-must-term-6-0/109864/5 "2017-12-01T15:03:10Z")

</div>

The application logic is very simple, the $currentNodeId variable will either contain one number or be empty.

How do I avoid having two queries? Isn't there any way to make the "must" condition be ignored based on some value for $currentNodeId.

---

<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, 3:03pm UTC](https://discuss.elastic.co/t/ignore-must-term-6-0/109864/6 "2017-12-29T15:03:15Z")

</div>

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