# Complex Elastic Search Query

**URL:** <https://discuss.elastic.co/t/complex-elastic-search-query/238587>\
**Category:** Elasticsearch\
**Created:** [June 25, 2020, 2:35am UTC](https://discuss.elastic.co/t/complex-elastic-search-query/238587 "2020-06-25T02:35:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![surajdalvi](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@surajdalvi](https://discuss.elastic.co/u/surajdalvi)\
**Post date:** [June 25, 2020, 2:35am UTC](https://discuss.elastic.co/t/complex-elastic-search-query/238587/1 "2020-06-25T02:35:46Z")

</div>

I have the following documents in the elastic search index.

```
[{
		"_index": "ten2",
		"_type": "documents",
		"_id": "c323c2244a4a4c22_en-us",
		"_source": {
			"publish_details": [{
					"environment": "603fe91adbdcff66",
					"time": "2020-06-24T13:36:55.514Z",
					"locale": "hi-in",
					"user": "aadab2f531206e9d",
					"version": 1
				},
				{
					"environment": "603fe91adbdcff66",
					"time": "2020-06-24T13:36:55.514Z",
					"locale": "en-us",
					"user": "aadab2f531206e9d",
					"version": 1
				}
			],
			"created_at": "2020-06-24T13:36:43.037Z",
			"_in_progress": false,
			"title": "Entry 1",
			"locale": "en-us",
			"url": "/entry-1",
			"tags": [],
			"uid": "c323c2244a4a4c22",
			"updated_at": "2020-06-24T13:36:43.037Z",
			"fields": []
		}
	},
	{
		"_index": "ten2",
		"_type": "documents",
		"_id": "c323c2244a4a4c22_mr-in",
		"_source": {
			"publish_details": [{
				"environment": "603fe91adbdcff66",
				"time": "2020-06-24T13:37:26.205Z",
				"locale": "mr-in",
				"user": "aadab2f531206e9d",
				"version": 1
			}],
			"created_at": "2020-06-24T13:36:43.037Z",
			"_in_progress": false,
			"title": "Entry 1 marathi",
			"locale": "mr-in",
			"url": "/entry-1",
			"tags": [],
			"uid": "c323c2244a4a4c22",
			"updated_at": "2020-06-24T13:37:20.092Z",
			"fields": []
		}
	}
]

```

And I want Result blank from this. As here we can see that uid of both the documents is the same. I am using the following query to get result :

```
{
	"query": {
		"bool": {
			"must": [{
				"bool": {
					"must_not": [{
						"bool": {
							"must": [{
								"nested": {
									"path": "publish_details",
									"query": {
										"term": {
											"publish_details.environment": "603fe91adbdcff66"
										}
									}
								}
							}, {
								"nested": {
									"path": "publish_details",
									"query": {
										"term": {
											"publish_details.locale": "en-us"
										}
									}
								}
							}, {
								"nested": {
									"path": "publish_details",
									"query": {
										"term": {
											"publish_details.locale": "hi-in"
										}
									}
								}
							}, {
								"nested": {
									"path": "publish_details",
									"query": {
										"term": {
											"publish_details.locale": "mr-in"
										}
									}
								}
							}]
						}
					}]
				}
			}]
		}
	}
}

```

But the above query gives me all 2 documents, but I want results as bank the reason here is here uid is common and that uid contains all three local in publishing details. So is way to get a valid result, Is any aggregation query that helps me here. it is just a sample I have so many documents to filter out. Kindle Helps me here.

---

<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:** [July 23, 2020, 2:35am UTC](https://discuss.elastic.co/t/complex-elastic-search-query/238587/2 "2020-07-23T02:35:47Z")

</div>

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