# What diffirent about nested and bool composite query

**URL:** <https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063>\
**Category:** Elasticsearch\
**Created:** [April 15, 2023, 10:43am UTC](https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063 "2023-04-15T10:43:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sslhj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sslhj/32/119856_2.png) [@sslhj](https://discuss.elastic.co/u/sslhj)\
**Post date:** [April 15, 2023, 10:43am UTC](https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063/1 "2023-04-15T10:43:33Z")

</div>

I have devloped a component that translate expression to esdel, now i have an exp like that  
"((extras.key== ‘k1’ and extras.value==100 ) or (extras.key== “k2” and extras.value==”v2”))", in that, ”extras“ is a nested field  
we have tow strategies to do that:

1. the whole is bool query,  
bool(or)  
-- nested bool(and)  
-- nested bool(and)
2. the whole is nested query  
nested
  - bool (or)  
-- bool (and)  
-- bool (and)

```auto
{
  "query": {
    "bool": {
      "should": [
        {
			"nested": {
			  "path": "extras",
			  "query": {
				"bool": {
				  "must": [
					{
					  "term": {
						"extras.key": "k1"
					  }
					},
					{
					  "term": {
						"extras.value": 100
					  }
					}
				  ]
				}
			  }
			}
		},
		{
			"nested": {
			  "path": "extras",
			  "query": {
				"bool": {
				  "must": [
					{
					  "term": {
						"extras.key": "k2"
					  }
					},
					{
					  "term": {
						"extras.value": "v2"
					  }
					}
				  ]
				}
			  }
			}
		}
      ]
    }
  }
}

```

```auto
{
  "query": {
          "nested": {
            "path": "extras",
            "query": {
              "bool": {
                "should": [
                  {
                    "bool": {
                      "must": [
                        {
                          "term": {
                            "extras.key": "k1"
                          }
                        },
                        {
                          "term": {
                            "extras.value": 100
                          }
                        }
                      ]
                    }
                  },
                  {
                    "bool": {
                      "must": [
                        {
                          "term": {
                            "extras.key": "k2"
                          }
                        },
                        {
                          "term": {
                            "extras.value": "v2"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
  }
}

```

i have run them in head , the same returned  
what is the diffirent about the tow in performance or they are the same one?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 15, 2023, 11:08am UTC](https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063/2 "2023-04-15T11:08:34Z")

</div>

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

---

<div class="post-metadata">

**Author:** ![sslhj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sslhj/32/119856_2.png) [@sslhj](https://discuss.elastic.co/u/sslhj)\
**Post date:** [April 24, 2023, 7:55am UTC](https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063/3 "2023-04-24T07:55:36Z")

</div>

I have some idea and solved，and post the solution，but it is wrote by chinese，

[https://www.toutiao.com/article/7223768235760812583/](https://www.toutiao.com/article/7223768235760812583/)

---

<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:** [May 22, 2023, 7:56am UTC](https://discuss.elastic.co/t/what-diffirent-about-nested-and-bool-composite-query/330063/4 "2023-05-22T07:56:07Z")

</div>

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